mirror of
https://github.com/santinic/audiblez.git
synced 2025-04-13 09:38:57 +00:00
fix espeak
This commit is contained in:
parent
60909e2695
commit
ce05103dd1
4 changed files with 36 additions and 12 deletions
|
@ -3,6 +3,9 @@
|
||||||
# audiblez - A program to convert e-books into audiobooks using
|
# audiblez - A program to convert e-books into audiobooks using
|
||||||
# Kokoro-82M model for high-quality text-to-speech synthesis.
|
# Kokoro-82M model for high-quality text-to-speech synthesis.
|
||||||
# by Claudio Santini 2025 - https://claudio.uk
|
# by Claudio Santini 2025 - https://claudio.uk
|
||||||
|
import os
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
import torch.cuda
|
import torch.cuda
|
||||||
import spacy
|
import spacy
|
||||||
import ebooklib
|
import ebooklib
|
||||||
|
@ -34,6 +37,23 @@ def load_spacy():
|
||||||
spacy.cli.download("xx_ent_wiki_sm")
|
spacy.cli.download("xx_ent_wiki_sm")
|
||||||
|
|
||||||
|
|
||||||
|
def set_espeak_library():
|
||||||
|
"""Find the espeak library path"""
|
||||||
|
if os.environ.get('ESPEAK_LIBRARY'):
|
||||||
|
library = os.environ['ESPEAK_LIBRARY']
|
||||||
|
elif platform.system() == 'Darwin':
|
||||||
|
library = glob('/opt/homebrew/Cellar/espeak-ng/*/lib/*.dylib')[0]
|
||||||
|
elif platform.system() == 'Linux':
|
||||||
|
library = glob('/usr/lib/*/libespeak-ng*')[0]
|
||||||
|
elif platform.system() == 'Windows':
|
||||||
|
library = 'C:\\Program Files*\\eSpeak NG\\libespeak-ng.dll'
|
||||||
|
else:
|
||||||
|
print('Unsupported OS, please set the espeak library path manually')
|
||||||
|
return
|
||||||
|
from phonemizer.backend.espeak.wrapper import EspeakWrapper
|
||||||
|
EspeakWrapper.set_library(library)
|
||||||
|
|
||||||
|
|
||||||
def main(file_path, voice, pick_manually, speed, output_folder='.',
|
def main(file_path, voice, pick_manually, speed, output_folder='.',
|
||||||
max_chapters=None, max_sentences=None, selected_chapters=None, post_event=None):
|
max_chapters=None, max_sentences=None, selected_chapters=None, post_event=None):
|
||||||
if post_event: post_event('CORE_STARTED')
|
if post_event: post_event('CORE_STARTED')
|
||||||
|
@ -100,6 +120,7 @@ def main(file_path, voice, pick_manually, speed, output_folder='.',
|
||||||
# add intro text
|
# add intro text
|
||||||
text = f'{title} – {creator}.\n\n' + text
|
text = f'{title} – {creator}.\n\n' + text
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
set_espeak_library()
|
||||||
pipeline = KPipeline(lang_code=voice[0]) # a for american or b for british etc.
|
pipeline = KPipeline(lang_code=voice[0]) # a for american or b for british etc.
|
||||||
if post_event: post_event('CORE_CHAPTER_STARTED', chapter_index=chapter.chapter_index)
|
if post_event: post_event('CORE_CHAPTER_STARTED', chapter_index=chapter.chapter_index)
|
||||||
audio_segments = gen_audio_segments(
|
audio_segments = gen_audio_segments(
|
||||||
|
|
14
poetry.lock
generated
14
poetry.lock
generated
|
@ -914,20 +914,20 @@ referencing = ">=0.31.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "kokoro"
|
name = "kokoro"
|
||||||
version = "0.7.9"
|
version = "0.7.16"
|
||||||
description = "TTS"
|
description = "TTS"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.7"
|
python-versions = ">=3.7"
|
||||||
groups = ["main"]
|
groups = ["main"]
|
||||||
files = [
|
files = [
|
||||||
{file = "kokoro-0.7.9-py3-none-any.whl", hash = "sha256:de2f4826daaca48da3b9d63d232e47db35047548029d0aae30c40aee3af90b5d"},
|
{file = "kokoro-0.7.16-py3-none-any.whl", hash = "sha256:27d8e8cfd6ec4fdad5caacb5e3fabd7b2576b778226c8cd0f92e1c33ff14f553"},
|
||||||
{file = "kokoro-0.7.9.tar.gz", hash = "sha256:62b32422b8985303d7c0e30a2465945ac896a1070d01e4cd5bd8f95f9bd4c73f"},
|
{file = "kokoro-0.7.16.tar.gz", hash = "sha256:c1cf957cfff76cbb6702f16a3cd15eea2a30c561f2c3b6b42107e39e6456316e"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
huggingface-hub = "*"
|
huggingface-hub = "*"
|
||||||
loguru = "*"
|
loguru = "*"
|
||||||
misaki = {version = ">=0.7.9", extras = ["en"]}
|
misaki = {version = ">=0.7.16", extras = ["en"]}
|
||||||
numpy = "1.26.4"
|
numpy = "1.26.4"
|
||||||
scipy = "*"
|
scipy = "*"
|
||||||
torch = "*"
|
torch = "*"
|
||||||
|
@ -1341,14 +1341,14 @@ files = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "misaki"
|
name = "misaki"
|
||||||
version = "0.7.12"
|
version = "0.7.17"
|
||||||
description = "G2P engine for TTS"
|
description = "G2P engine for TTS"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = "<3.13,>=3.8"
|
python-versions = "<3.13,>=3.8"
|
||||||
groups = ["main"]
|
groups = ["main"]
|
||||||
files = [
|
files = [
|
||||||
{file = "misaki-0.7.12-py3-none-any.whl", hash = "sha256:bb71a0e85ff70557d96303560ac72ccf669a02fb126b3e0b38eed3215bb80b34"},
|
{file = "misaki-0.7.17-py3-none-any.whl", hash = "sha256:5c739a540e715c368f9dbcf3e99f814575853785d5ba0096956acabcf58be0cd"},
|
||||||
{file = "misaki-0.7.12.tar.gz", hash = "sha256:cfe714488012ab6beaad08077ce782559f9f0e019989df8bfa3ebc7674f7c33f"},
|
{file = "misaki-0.7.17.tar.gz", hash = "sha256:301ea5ee3bd6dfcf5539bbd55c928a1855cf1bf6a90a367362072348a0e4a16a"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
from ebooklib import epub
|
from ebooklib import epub
|
||||||
|
|
||||||
from audiblez import find_good_chapters, find_document_chapters_and_extract_texts
|
from audiblez.core import find_document_chapters_and_extract_texts, find_good_chapters
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip('Development only, not for CI')
|
|
||||||
class FindChaptersTest(unittest.TestCase):
|
class FindChaptersTest(unittest.TestCase):
|
||||||
def base(self, file, expected_chapter_names):
|
def base(self, file, expected_chapter_names):
|
||||||
book = epub.read_epub(file)
|
book = epub.read_epub(file)
|
||||||
|
@ -46,7 +45,7 @@ class FindChaptersTest(unittest.TestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_spawn_of_dagon(self):
|
def test_spawn_of_dagon(self):
|
||||||
self.base('../epub/kuttner-spawn-of-dagon.epub', [
|
self.base('../epub/dagon.epub', [
|
||||||
# 'bk01-toc.xhtml', # 276
|
# 'bk01-toc.xhtml', # 276
|
||||||
# 'cover.xhtml', # 76
|
# 'cover.xhtml', # 76
|
||||||
# 'index.xhtml', # 1399
|
# 'index.xhtml', # 1399
|
||||||
|
@ -62,7 +61,7 @@ class FindChaptersTest(unittest.TestCase):
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_lewis_innocents(self):
|
def test_lewis_innocents(self):
|
||||||
self.base('../epub/lewis-innocents.epub', [
|
self.base('../epub/lewis.epub', [
|
||||||
# 'bk01-toc.xhtml', # 1603
|
# 'bk01-toc.xhtml', # 1603
|
||||||
# 'cover.xhtml', # 72
|
# 'cover.xhtml', # 72
|
||||||
# 'index.xhtml', # 1554
|
# 'index.xhtml', # 1554
|
||||||
|
@ -178,5 +177,5 @@ class FindChaptersTest(unittest.TestCase):
|
||||||
'2903486949112998543_345-h-30.htm.xhtml', # 4081
|
'2903486949112998543_345-h-30.htm.xhtml', # 4081
|
||||||
'2903486949112998543_345-h-31.htm.xhtml', # 19692
|
'2903486949112998543_345-h-31.htm.xhtml', # 19692
|
||||||
'toc.xhtml', # 4900
|
'toc.xhtml', # 4900
|
||||||
'wrap0000.xhtml', # 374
|
# 'wrap0000.xhtml', # 374
|
||||||
])
|
])
|
||||||
|
|
|
@ -7,6 +7,10 @@ from ebooklib import epub
|
||||||
|
|
||||||
from audiblez.core import main, find_document_chapters_and_extract_texts
|
from audiblez.core import main, find_document_chapters_and_extract_texts
|
||||||
|
|
||||||
|
# from phonemizer.backend.espeak.wrapper import EspeakWrapper
|
||||||
|
|
||||||
|
# EspeakWrapper.set_library('/opt/homebrew/Cellar/espeak-ng/1.52.0/lib/libespeak-ng.1.dylib')
|
||||||
|
|
||||||
|
|
||||||
class MainTest(unittest.TestCase):
|
class MainTest(unittest.TestCase):
|
||||||
def base(self, name, url='', **kwargs):
|
def base(self, name, url='', **kwargs):
|
||||||
|
|
Loading…
Add table
Reference in a new issue