This commit is contained in:
Claudio Santini 2025-02-19 14:31:03 +01:00
parent 058847c722
commit 4d2380bf7d
3 changed files with 7 additions and 3 deletions

View file

@ -185,7 +185,6 @@ def gen_text(text, voice='af_heart', output_file='text.wav', speed=1, play=False
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 = []
@ -305,7 +304,7 @@ def probe_duration(file_name):
def create_index_file(title, creator, chapter_mp3_files, output_folder):
with open(Path(output_folder) / "chapters.txt", "w") as f:
with open(Path(output_folder) / "chapters.txt", "w", encoding="utf-8") as f:
f.write(f";FFMETADATA1\ntitle={title}\nartist={creator}\n\n")
start = 0
i = 0

View file

@ -28,6 +28,7 @@ class CliTest(unittest.TestCase):
self.assertTrue(Path('./prova/mini.m4b').exists())
self.assertTrue(Path('./prova/mini.m4b').stat().st_size > 256 * 1024)
@unittest.skip('Not implemented yet')
def test_md(self):
content = (
'## Italy\n'
@ -42,6 +43,7 @@ class CliTest(unittest.TestCase):
self.assertTrue(Path(file_name).exists())
self.assertTrue(Path('file_name').stat().st_size > 256 * 1024)
@unittest.skip('Not implemented yet')
def test_txt(self):
content = (
'Italy, officially the Italian Republic, is a country in Southern and Western Europe. '

View file

@ -1,4 +1,5 @@
import os
import subprocess
import unittest
from pathlib import Path
@ -45,8 +46,10 @@ class MainTest(unittest.TestCase):
url = 'https://www.gutenberg.org/ebooks/24225.epub3.images'
self.base('chinese', url, voice='zf_xiaobei')
def test_leigh(self):
def test_leigh_and_play_result(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)
subprocess.run(['ffplay', '-nodisp', '-autoexit', 'leigh.m4b'], check=True)