This commit is contained in:
Claudio Santini 2025-02-01 11:23:50 +01:00
parent a21da3287b
commit 1ef26f893b
3 changed files with 31 additions and 18 deletions

View file

@ -28,9 +28,8 @@ You also need `espeak-ng` and `ffmpeg` installed on your machine:
```bash
pip install audiblez
sudo apt install ffmpeg espeak-ng # on Ubuntu/Debian
brew install ffmpeg espeak-ng # on Mac
sudo apt install ffmpeg espeak-ng # on Ubuntu/Debian 🐧
brew install ffmpeg espeak-ng # on Mac 🍏
```
Then, to convert an epub file into an audiobook, just run:
@ -54,16 +53,24 @@ audiblez book.epub -v af_sky -s 1.5
## Supported Voices
Use `-v` option to specify the voice to use. Available voices are listed here, the ones that start with "a" are American, the ones that start with "b" are British:
Use `-v` option to specify the voice to use. Available voices are listed here.
the first letter is the language code and the second is the gender of the speaker e.g. `im_nicola` is an italian male voice.
`af_alloy, af_aoede, af_bella, af_jessica, af_kore, af_nicole, af_nova, af_river, af_sarah, af_sky, am_adam, am_echo, am_eric, am_fenrir, am_liam, am_michael, am_onyx, am_puck, bf_alice, bf_emma, bf_isabella, bf_lily, bm_daniel, bm_fable, bm_george, bm_lewis`
| Language | Voices |
|----------|--------|
| 🇺🇸 | `af_alloy`, `af_aoede`, `af_bella`, `af_heart`, `af_jessica`, `af_kore`, `af_nicole`, `af_nova`, `af_river`, `af_sarah`, `af_sky`, `am_adam`, `am_echo`, `am_eric`, `am_fenrir`, `am_liam`, `am_michael`, `am_onyx`, `am_puck`, `am_santa` |
| 🇬🇧 | `bf_alice`, `bf_emma`, `bf_isabella`, `bf_lily`, `bm_daniel`, `bm_fable`, `bm_george`, `bm_lewis` |
| 🇪🇸 | `ef_dora`, `em_alex`, `em_santa` |
| 🇫🇷 | `ff_siwis` |
| 🇮🇳 | `hf_alpha`, `hf_beta`, `hm_omega`, `hm_psi` |
| 🇮🇹 | `if_sara`, `im_nicola` |
| 🇯🇵 | `jf_alpha`, `jf_gongitsune`, `jf_nezumi`, `jf_tebukuro`, `jm_kumo` |
| 🇧🇷 | `pf_dora`, `pm_alex`, `pm_santa` |
| 🇨🇳 | `zf_xiaobei`, `zf_xiaoni`, `zf_xiaoxiao`, `zf_xiaoyi`, `zm_yunjian`, `zm_yunxi`, `zm_yunxia`, `zm_yunyang` |
You can try them here: [https://huggingface.co/spaces/hexgrad/Kokoro-TTS](https://huggingface.co/spaces/hexgrad/Kokoro-TTS)
## How to run on GPU
Experimental support for Cuda is available b
By default audiblez runs on CPU. If you pass the option `--cuda` it will try to use the Cuda device via Torch.
Check out this example: [Audiblez running on a Google Colab Notebook with Cuda ](https://colab.research.google.com/drive/164PQLowogprWQpRjKk33e-8IORAvqXKI?usp=sharing]).

View file

@ -30,9 +30,9 @@ sample_rate = 24000
def main(file_path, voice, pick_manually, speed, max_chapters=None):
if not spacy.util.is_package("en_core_web_sm"):
print("Downloading Spacy model 'en_core_web_sm'...")
spacy.cli.download("en_core_web_sm")
if not spacy.util.is_package("xx_ent_wiki_sm"):
print("Downloading Spacy model xx_ent_wiki_sm...")
spacy.cli.download("xx_ent_wiki_sm")
filename = Path(file_path).name
book = epub.read_epub(file_path)
meta_title = book.get_metadata('DC', 'title')
@ -50,11 +50,11 @@ def main(file_path, voice, pick_manually, speed, max_chapters=None):
document_chapters = find_document_chapters_and_extract_texts(book)
if pick_manually is True:
chapters = pick_chapters(document_chapters)
selected_chapters = pick_chapters(document_chapters)
else:
chapters = find_good_chapters(document_chapters)
print_selected_chapters(document_chapters, chapters)
texts = [c.extracted_text for c in chapters]
selected_chapters = find_good_chapters(document_chapters)
print_selected_chapters(document_chapters, selected_chapters)
texts = [c.extracted_text for c in selected_chapters]
has_ffmpeg = shutil.which('ffmpeg') is not None
if not has_ffmpeg:
@ -68,9 +68,11 @@ def main(file_path, voice, pick_manually, speed, max_chapters=None):
print(f'Estimated time remaining (assuming {chars_per_sec} chars/sec): {strfdelta((total_chars - processed_chars) / chars_per_sec)}')
chapter_wav_files = []
for i, text in enumerate(texts, start=1):
for i, chapter in enumerate(selected_chapters, start=1):
if max_chapters and i > max_chapters: break
chapter_filename = filename.replace('.epub', f'_chapter_{i}.wav')
text = chapter.extracted_text
xhtml_file_name = chapter.get_name().replace(' ', '_').replace('/', '_').replace('\\', '_')
chapter_filename = filename.replace('.epub', f'_chapter_{i}_{voice}_{xhtml_file_name}.wav')
chapter_wav_files.append(chapter_filename)
if Path(chapter_filename).exists():
print(f'File for chapter {i} already exists. Skipping')

View file

@ -60,4 +60,8 @@ voices = {
}
available_voices_str = ('\n'.join([f' {flags[lang]} {", ".join(voices[lang])}' for lang in voices])
.replace(' af_sky,', '\n af_sky,'))
.replace(' af_sky,', '\n af_sky,'))
# for key, l in voices.items():
# ls = ', '.join([f'`{j}`' for j in l])
# print(f'| {flags[key]} | {ls} |')