mirror of
https://github.com/santinic/audiblez.git
synced 2025-08-05 16:48:55 +00:00
fix
Some checks failed
Installing via pip and running / windows-git-clone-and-run (push) Has been cancelled
Git clone and run / linux-git-clone-and-run (push) Has been cancelled
Git clone and run / windows-git-clone-and-run (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-11 (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-12 (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-10 (push) Has been cancelled
Some checks failed
Installing via pip and running / windows-git-clone-and-run (push) Has been cancelled
Git clone and run / linux-git-clone-and-run (push) Has been cancelled
Git clone and run / windows-git-clone-and-run (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-11 (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-12 (push) Has been cancelled
Installing via pip and running / install-and-run-on-python-3-10 (push) Has been cancelled
This commit is contained in:
parent
90ff06a519
commit
058847c722
3 changed files with 24 additions and 4 deletions
|
@ -174,6 +174,18 @@ def gen_audio_segments(pipeline, text, voice, speed, stats=None, max_sentences=N
|
|||
return audio_segments
|
||||
|
||||
|
||||
def gen_text(text, voice='af_heart', output_file='text.wav', speed=1, play=False):
|
||||
lang_code = voice[:1]
|
||||
pipeline = KPipeline(lang_code=lang_code)
|
||||
load_spacy()
|
||||
audio_segments = gen_audio_segments(pipeline, text, voice=voice, speed=speed);
|
||||
final_audio = np.concatenate(audio_segments)
|
||||
soundfile.write(output_file, final_audio, sample_rate)
|
||||
if play:
|
||||
subprocess.run(['ffplay', '-autoexit', '-nodisp', output_file])
|
||||
|
||||
|
||||
|
||||
def find_document_chapters_and_extract_texts(book):
|
||||
"""Returns every chapter that is an ITEM_DOCUMENT and enriches each chapter with extracted_text."""
|
||||
document_chapters = []
|
||||
|
@ -253,7 +265,7 @@ def create_m4b(chapter_files, filename, cover_image, output_folder):
|
|||
audio = AudioSegment.from_wav(wav_file)
|
||||
combined_audio += audio
|
||||
print('Converting to Mp4...')
|
||||
combined_audio.export(tmp_file_path, format="mp4", codec="aac", bitrate="128k")
|
||||
combined_audio.export(tmp_file_path, format="mp4", bitrate="128k")
|
||||
final_filename = Path(output_folder) / filename.replace('.epub', '.m4b')
|
||||
print('Creating M4B file...')
|
||||
|
||||
|
|
|
@ -495,7 +495,7 @@ class MainWindow(wx.Frame):
|
|||
tmp_preview_wav_file = NamedTemporaryFile(suffix='.wav', delete=False)
|
||||
soundfile.write(tmp_preview_wav_file, final_audio, core.sample_rate)
|
||||
cmd = ['ffplay', '-autoexit', '-nodisp', tmp_preview_wav_file.name]
|
||||
subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
|
||||
subprocess.run(cmd)
|
||||
button.SetLabel("🔊 Preview")
|
||||
button.Enable()
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@ import os
|
|||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from audiblez.core import main
|
||||
from ebooklib import epub
|
||||
|
||||
from audiblez.core import main, find_document_chapters_and_extract_texts
|
||||
|
||||
|
||||
class MainTest(unittest.TestCase):
|
||||
def base(self, name, url, **kwargs):
|
||||
def base(self, name, url='', **kwargs):
|
||||
if not Path(f'{name}.epub').exists():
|
||||
os.system(f'wget {url} -O {name}.epub')
|
||||
Path(f'{name}.m4b').unlink(missing_ok=True)
|
||||
|
@ -42,3 +44,9 @@ class MainTest(unittest.TestCase):
|
|||
def test_chinese(self):
|
||||
url = 'https://www.gutenberg.org/ebooks/24225.epub3.images'
|
||||
self.base('chinese', url, voice='zf_xiaobei')
|
||||
|
||||
def test_leigh(self):
|
||||
book = epub.read_epub('leigh.epub')
|
||||
document_chapters = find_document_chapters_and_extract_texts(book)
|
||||
chapters = [c for c in document_chapters if c.get_name() == 'Text/Chap07.xhtml']
|
||||
self.base('leigh', voice='af_heart', selected_chapters=chapters, max_sentences=5)
|
||||
|
|
Loading…
Add table
Reference in a new issue