Skip to content

Commit

Permalink
Revert "Merge pull request #43 from ROBERT-MCDOWELL/main"
Browse files Browse the repository at this point in the history
This reverts commit ad357da, reversing
changes made to d6297a5.
  • Loading branch information
DrewThomasson committed Nov 16, 2024
1 parent ad357da commit a5925bf
Show file tree
Hide file tree
Showing 65 changed files with 174 additions and 189 deletions.
48 changes: 25 additions & 23 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import sys

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

script_mode = NATIVE
share = False

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

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

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

# Argument parser to handle optional parameters with descriptions
parser = argparse.ArgumentParser(
Expand All @@ -112,21 +111,21 @@ def main():
Example usage:
Windows:
headless:
ebook2audiobook.cmd --headless --ebook 'path_to_ebook' --voice 'path_to_voice' --language en --custom_model 'model.zip'
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
Graphic Interface:
ebook2audiobook.cmd
Linux/Mac:
headless:
./ebook2audiobook.sh --headless --ebook 'path_to_ebook' --voice 'path_to_voice' --language en --custom_model 'model.zip'
./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
Graphic Interface:
./ebook2audiobook.sh
""",
formatter_class=argparse.RawTextHelpFormatter
)
options = [
"--script_mode", "--share", "--headless", "--ebook", "--ebooks_dir",
"--voice", "--language", "--device", "--custom_model",
"--custom_model_url", "--temperature",
"--voice", "--language", "--device", "--use_custom_model", "--custom_model",
"--custom_config", "--custom_vocab", "--custom_model_url", "--temperature",
"--length_penalty", "--repetition_penalty", "--top_k", "--top_p", "--speed",
"--enable_text_splitting", "--version"
]
Expand All @@ -143,31 +142,37 @@ 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: {lang_list_str}. Defaults to English (en).")
help=f"Language for the audiobook conversion. Options: {language_options_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], type=str,
help="Path to the custom model file (.pth). Required if using a custom model.")
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,
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,
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[10], type=float, default=0.65,
parser.add_argument(options[13], 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[11], type=float, default=1.0,
parser.add_argument(options[14], 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[12], type=float, default=2.0,
parser.add_argument(options[15], type=float, default=2.0,
help="A penalty that prevents the autoregressive decoder from repeating itself. Defaults to 2.0.")
parser.add_argument(options[13], type=int, default=50,
parser.add_argument(options[16], 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[14], type=float, default=0.8,
parser.add_argument(options[17], 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[15], type=float, default=1.0,
parser.add_argument(options[18], type=float, default=1.0,
help="Speed factor for the speech generation. Defaults to 1.0.")
parser.add_argument(options[16], action="store_true",
parser.add_argument(options[19], action="store_true",
help="Enable splitting text into sentences. Defaults to False.")
parser.add_argument(options[17], action="version",version=f"ebook2audiobook version {version}",
parser.add_argument(options[20], action="version",version=f"ebook2audiobook version {version}",
help="Show the version of the script and exit")

for arg in sys.argv:
Expand All @@ -183,7 +188,6 @@ 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 @@ -232,13 +236,11 @@ 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 @@ -247,7 +249,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(script_mode, share)
web_interface(args.script_mode, args.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 (%ARGS%) do (
for %%A in (%*) 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" %ARGS%
start "" /b cmd /c "%~f0" %*
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 --upgrade -r requirements.txt
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 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 --upgrade -r requirements.txt
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 unidic download
python -m spacy download en_core_web_sm
python -m nltk.downloader punkt_tab
Expand Down
Binary file added ebooks/test1.epub
Binary file not shown.
Binary file added ebooks/test2.azw3
Binary file not shown.
Binary file added ebooks/test3.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions ebooks/test4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is the test four from the result of text file to audiobook conversion.
Binary file removed ebooks/test_ar.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_ar.txt

This file was deleted.

Binary file removed ebooks/test_cs.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_cs.txt

This file was deleted.

Binary file removed ebooks/test_da.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_da.txt

This file was deleted.

Binary file removed ebooks/test_de.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_de.txt

This file was deleted.

Binary file removed ebooks/test_el.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_el.txt

This file was deleted.

Binary file removed ebooks/test_en.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_en.txt

This file was deleted.

Binary file removed ebooks/test_es.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_es.txt

This file was deleted.

Binary file removed ebooks/test_fi.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_fi.txt

This file was deleted.

Binary file removed ebooks/test_fr.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_fr.txt

This file was deleted.

Binary file removed ebooks/test_hr.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_hr.txt

This file was deleted.

Binary file removed ebooks/test_it.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_it.txt

This file was deleted.

Binary file removed ebooks/test_ja.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_ja.txt

This file was deleted.

Binary file removed ebooks/test_ko.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_ko.txt

This file was deleted.

Binary file removed ebooks/test_nb.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_nb.txt

This file was deleted.

Binary file removed ebooks/test_nl.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_nl.txt

This file was deleted.

Binary file removed ebooks/test_pl.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_pl.txt

This file was deleted.

Binary file removed ebooks/test_pt.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_pt.txt

This file was deleted.

Binary file removed ebooks/test_ro.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_ro.txt

This file was deleted.

Binary file removed ebooks/test_ru.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_ru.txt

This file was deleted.

Binary file removed ebooks/test_sl.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_sl.txt

This file was deleted.

Binary file removed ebooks/test_sv.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_sv.txt

This file was deleted.

Binary file removed ebooks/test_zh.azw3
Binary file not shown.
1 change: 0 additions & 1 deletion ebooks/test_zh.txt

This file was deleted.

Loading

0 comments on commit a5925bf

Please sign in to comment.