Skip to content

Commit 058847c

Browse files
committed
fix
1 parent 90ff06a commit 058847c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

audiblez/core.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ def gen_audio_segments(pipeline, text, voice, speed, stats=None, max_sentences=N
174174
return audio_segments
175175

176176

177+
def gen_text(text, voice='af_heart', output_file='text.wav', speed=1, play=False):
178+
lang_code = voice[:1]
179+
pipeline = KPipeline(lang_code=lang_code)
180+
load_spacy()
181+
audio_segments = gen_audio_segments(pipeline, text, voice=voice, speed=speed);
182+
final_audio = np.concatenate(audio_segments)
183+
soundfile.write(output_file, final_audio, sample_rate)
184+
if play:
185+
subprocess.run(['ffplay', '-autoexit', '-nodisp', output_file])
186+
187+
188+
177189
def find_document_chapters_and_extract_texts(book):
178190
"""Returns every chapter that is an ITEM_DOCUMENT and enriches each chapter with extracted_text."""
179191
document_chapters = []
@@ -253,7 +265,7 @@ def create_m4b(chapter_files, filename, cover_image, output_folder):
253265
audio = AudioSegment.from_wav(wav_file)
254266
combined_audio += audio
255267
print('Converting to Mp4...')
256-
combined_audio.export(tmp_file_path, format="mp4", codec="aac", bitrate="128k")
268+
combined_audio.export(tmp_file_path, format="mp4", bitrate="128k")
257269
final_filename = Path(output_folder) / filename.replace('.epub', '.m4b')
258270
print('Creating M4B file...')
259271

audiblez/ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def generate_preview():
495495
tmp_preview_wav_file = NamedTemporaryFile(suffix='.wav', delete=False)
496496
soundfile.write(tmp_preview_wav_file, final_audio, core.sample_rate)
497497
cmd = ['ffplay', '-autoexit', '-nodisp', tmp_preview_wav_file.name]
498-
subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
498+
subprocess.run(cmd)
499499
button.SetLabel("🔊 Preview")
500500
button.Enable()
501501

test/test_main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import unittest
33
from pathlib import Path
44

5-
from audiblez.core import main
5+
from ebooklib import epub
6+
7+
from audiblez.core import main, find_document_chapters_and_extract_texts
68

79

810
class MainTest(unittest.TestCase):
9-
def base(self, name, url, **kwargs):
11+
def base(self, name, url='', **kwargs):
1012
if not Path(f'{name}.epub').exists():
1113
os.system(f'wget {url} -O {name}.epub')
1214
Path(f'{name}.m4b').unlink(missing_ok=True)
@@ -42,3 +44,9 @@ def test_french_baudelaire(self):
4244
def test_chinese(self):
4345
url = 'https://www.gutenberg.org/ebooks/24225.epub3.images'
4446
self.base('chinese', url, voice='zf_xiaobei')
47+
48+
def test_leigh(self):
49+
book = epub.read_epub('leigh.epub')
50+
document_chapters = find_document_chapters_and_extract_texts(book)
51+
chapters = [c for c in document_chapters if c.get_name() == 'Text/Chap07.xhtml']
52+
self.base('leigh', voice='af_heart', selected_chapters=chapters, max_sentences=5)

0 commit comments

Comments
 (0)