Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull attempty into v2.0 #43

Merged
merged 6 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import sys

from lib.conf import *
from lib.lang import language_options, default_language_code
from lib.lang import language_mapping, default_language_code

script_mode = NATIVE
share = False

def check_python_version():
current_version = sys.version_info[:2] # (major, minor)
Expand Down Expand Up @@ -99,10 +100,10 @@ def is_port_in_use(port):
return s.connect_ex(('0.0.0.0', port)) == 0

def main():
global script_mode, ebooks_dir
global script_mode, share, ebooks_dir

# Convert the list of languages to a string to display in the help text
language_options_str = ", ".join(language_options)
lang_list_str = ", ".join(list(language_mapping.keys()))

# Argument parser to handle optional parameters with descriptions
parser = argparse.ArgumentParser(
Expand All @@ -111,21 +112,21 @@ def main():
Example usage:
Windows:
headless:
ebook2audiobook.cmd --headless --ebook 'path_to_ebook' --voice 'path_to_voice' --language en --use_custom_model --custom_model 'model.zip' --custom_config config.json --custom_vocab vocab.json
ebook2audiobook.cmd --headless --ebook 'path_to_ebook' --voice 'path_to_voice' --language en --custom_model 'model.zip'
Graphic Interface:
ebook2audiobook.cmd
Linux/Mac:
headless:
./ebook2audiobook.sh --headless --ebook 'path_to_ebook' --voice 'path_to_voice' --language en --use_custom_model --custom_model 'model.zip' --custom_config config.json --custom_vocab vocab.json
./ebook2audiobook.sh --headless --ebook 'path_to_ebook' --voice 'path_to_voice' --language en --custom_model 'model.zip'
Graphic Interface:
./ebook2audiobook.sh
""",
formatter_class=argparse.RawTextHelpFormatter
)
options = [
"--script_mode", "--share", "--headless", "--ebook", "--ebooks_dir",
"--voice", "--language", "--device", "--use_custom_model", "--custom_model",
"--custom_config", "--custom_vocab", "--custom_model_url", "--temperature",
"--voice", "--language", "--device", "--custom_model",
"--custom_model_url", "--temperature",
"--length_penalty", "--repetition_penalty", "--top_k", "--top_p", "--speed",
"--enable_text_splitting", "--version"
]
Expand All @@ -142,37 +143,31 @@ def main():
parser.add_argument(options[5], type=str,
help="Path to the target voice file for TTS. Optional, uses a default voice if not provided.")
parser.add_argument(options[6], type=str, default="en",
help=f"Language for the audiobook conversion. Options: {language_options_str}. Defaults to English (en).")
help=f"Language for the audiobook conversion. Options: {lang_list_str}. Defaults to English (en).")
parser.add_argument(options[7], type=str, default="cpu", choices=["cpu", "gpu"],
help=f"Type of processor unit for the audiobook conversion. If not specified: check first if gpu available, if not cpu is selected.")
parser.add_argument(options[8], action="store_true",
help="Use a custom TTS model. Defaults to False. Must be True to use custom models.")
parser.add_argument(options[9], type=str,
parser.add_argument(options[8], type=str,
help="Path to the custom model file (.pth). Required if using a custom model.")
parser.add_argument(options[10], type=str,
help="Path to the custom config file (config.json). Required if using a custom model.")
parser.add_argument(options[11], type=str,
help="Path to the custom vocab file (vocab.json). Required if using a custom model.")
parser.add_argument(options[12], type=str,
parser.add_argument(options[9], type=str,
help=("URL to download the custom model as a zip file. Optional, but will be used if provided. "
"Examples include David Attenborough's model: "
"'https://huggingface.co/drewThomasson/xtts_David_Attenborough_fine_tune/resolve/main/Finished_model_files.zip?download=true'. "
"More XTTS fine-tunes can be found on my Hugging Face at 'https://huggingface.co/drewThomasson'."))
parser.add_argument(options[13], type=float, default=0.65,
parser.add_argument(options[10], type=float, default=0.65,
help="Temperature for the model. Defaults to 0.65. Higher temperatures lead to more creative outputs.")
parser.add_argument(options[14], type=float, default=1.0,
parser.add_argument(options[11], type=float, default=1.0,
help="A length penalty applied to the autoregressive decoder. Defaults to 1.0. Not applied to custom models.")
parser.add_argument(options[15], type=float, default=2.0,
parser.add_argument(options[12], type=float, default=2.0,
help="A penalty that prevents the autoregressive decoder from repeating itself. Defaults to 2.0.")
parser.add_argument(options[16], type=int, default=50,
parser.add_argument(options[13], type=int, default=50,
help="Top-k sampling. Lower values mean more likely outputs and increased audio generation speed. Defaults to 50.")
parser.add_argument(options[17], type=float, default=0.8,
parser.add_argument(options[14], type=float, default=0.8,
help="Top-p sampling. Lower values mean more likely outputs and increased audio generation speed. Defaults to 0.8.")
parser.add_argument(options[18], type=float, default=1.0,
parser.add_argument(options[15], type=float, default=1.0,
help="Speed factor for the speech generation. Defaults to 1.0.")
parser.add_argument(options[19], action="store_true",
parser.add_argument(options[16], action="store_true",
help="Enable splitting text into sentences. Defaults to False.")
parser.add_argument(options[20], action="version",version=f"ebook2audiobook version {version}",
parser.add_argument(options[17], action="version",version=f"ebook2audiobook version {version}",
help="Show the version of the script and exit")

for arg in sys.argv:
Expand All @@ -188,6 +183,7 @@ def main():
sys.exit(1)

script_mode = args.script_mode if args.script_mode else script_mode
share = args.share if args.share else share

if script_mode == NATIVE:
check_pkg = check_and_install_requirements(requirements_file)
Expand Down Expand Up @@ -236,11 +232,13 @@ def main():
else:
print(f"Error: The directory {ebooks_dir} does not exist.")
sys.exit(1)

elif args.ebook:
progress_status, audiobook_file = convert_ebook(args)
if audiobook_file is None:
print(f"Conversion failed: {progress_status}")
sys.exit(1)

else:
print("Error: In headless mode, you must specify either an ebook file using --ebook or an ebook directory using --ebooks_dir.")
sys.exit(1)
Expand All @@ -249,7 +247,7 @@ def main():
allowed_arguments = {'--share', '--script_mode'}
passed_args_set = {arg for arg in passed_arguments if arg.startswith('--')}
if passed_args_set.issubset(allowed_arguments):
web_interface(args.script_mode, args.share)
web_interface(script_mode, share)
else:
print("Error: In non-headless mode, no option or only '--share' can be passed")
sys.exit(1)
Expand Down
6 changes: 3 additions & 3 deletions ebook2audiobook.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if not exist "%CALIBRE_TEMP_DIR%" (

icacls "%CALIBRE_TEMP_DIR%" /grant Users:(OI)(CI)F /T

for %%A in (%*) do (
for %%A in (%ARGS%) do (
if "%%A"=="%DOCKER_UTILS%" (
set "SCRIPT_MODE=%DOCKER_UTILS%"
break
Expand Down Expand Up @@ -228,7 +228,7 @@ if not "%DOCKER_BUILD_STATUS%"=="0" (
net session >nul 2>&1
if %errorlevel% equ 0 (
echo Restarting in user mode...
start "" /b cmd /c "%~f0" %*
start "" /b cmd /c "%~f0" %ARGS%
exit /b
)
goto dispatch
Expand Down Expand Up @@ -269,7 +269,7 @@ if "%SCRIPT_MODE%"=="%FULL_DOCKER%" (
call conda create --prefix %SCRIPT_DIR%\%PYTHON_ENV% python=%PYTHON_VERSION% -y
call conda activate %SCRIPT_DIR%\%PYTHON_ENV%
call python -m pip install --upgrade pip
call python -m pip install beautifulsoup4 coqui-tts ebooklib docker "gradio>=4.44.0" mecab mecab-python3 "nltk>=3.8.2" pydub translate tqdm unidic
call python -m pip install --upgrade -r requirements.txt
call python -m unidic download
call python -m spacy download en_core_web_sm
call python -m nltk.downloader punkt_tab
Expand Down
2 changes: 1 addition & 1 deletion ebook2audiobook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function conda_check {
source $CONDA_ENV
conda activate $SCRIPT_DIR/$PYTHON_ENV
python -m pip install --upgrade pip
python -m pip install beautifulsoup4 coqui-tts ebooklib docker "gradio>=4.44.0" mecab mecab-python3 "nltk>=3.8.2" pydub translate tqdm unidic
python -m pip install --upgrade -r requirements.txt
python -m unidic download
python -m spacy download en_core_web_sm
python -m nltk.downloader punkt_tab
Expand Down
Binary file removed ebooks/test1.epub
Binary file not shown.
Binary file removed ebooks/test2.azw3
Binary file not shown.
Binary file removed ebooks/test3.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test4.txt

This file was deleted.

Binary file added ebooks/test_ar.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_ar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
هذا هو الاختبار من نتيجة تحويل ملف نصي إلى كتاب صوتي.
Binary file added ebooks/test_cs.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_cs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Toto je test od výsledku převodu textového souboru na audioknihu.
Binary file added ebooks/test_da.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_da.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dette er testen fra resultatet af konvertering af tekstfil til lydbog.
Binary file added ebooks/test_de.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_de.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dies ist der Test des Ergebnisses der Konvertierung einer Textdatei in ein Hörbuch.
Binary file added ebooks/test_el.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_el.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Αυτή είναι η δοκιμή από το αποτέλεσμα της μετατροπής αρχείου κειμένου σε ηχητικό βιβλίο.
Binary file added ebooks/test_en.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_en.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the test from the result of text file to audiobook conversion.
Binary file added ebooks/test_es.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_es.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Esta es la prueba del resultado de la conversión de archivo de texto a audiolibro.
Binary file added ebooks/test_fi.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_fi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tämä on testi tekstitiedoston muuntamisen tuloksesta äänikirjaksi.
Binary file added ebooks/test_fr.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_fr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ceci est le test provenant d'un fichier text en livre audio.
Binary file added ebooks/test_hr.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_hr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ovo je test rezultata pretvorbe tekstualne datoteke u audioknjigu.
Binary file added ebooks/test_it.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_it.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Questo è il test del risultato della conversione del file di testo in audiolibro.
Binary file added ebooks/test_ja.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_ja.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
これは、テキスト ファイルからオーディオブックへの変換結果のテストです。
Binary file added ebooks/test_ko.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_ko.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
이는 텍스트 파일을 오디오북으로 변환한 결과에 대한 테스트입니다.
Binary file added ebooks/test_nb.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_nb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dette er testen fra resultatet av konvertering av tekstfil til lydbok.
Binary file added ebooks/test_nl.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_nl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dit is de test op basis van het resultaat van de conversie van een tekstbestand naar een audioboek.
Binary file added ebooks/test_pl.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_pl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To jest test wyniku konwersji pliku tekstowego na audiobook.
Binary file added ebooks/test_pt.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_pt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Este é o teste do resultado da conversão de ficheiro de texto em audiolivro.
Binary file added ebooks/test_ro.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_ro.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Acesta este testul de la rezultatul conversiei fișierului text la cartea audio.
Binary file added ebooks/test_ru.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_ru.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Это тест результата конвертации текстового файла в аудиокнигу.
Binary file added ebooks/test_sl.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_sl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To je preizkus rezultata pretvorbe besedilne datoteke v zvočno knjigo.
Binary file added ebooks/test_sv.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_sv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Detta är testet från resultatet av konvertering av textfil till ljudbok.
Binary file added ebooks/test_zh.azw3
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test_zh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
这是从文本文件到有声读物的转换结果进行的测试。
Loading