2025-01-30 16:04:58 +01:00
|
|
|
import os
|
2025-02-19 14:31:03 +01:00
|
|
|
import subprocess
|
2025-01-23 22:31:22 +01:00
|
|
|
import unittest
|
|
|
|
from pathlib import Path
|
|
|
|
|
2025-02-13 22:44:56 +01:00
|
|
|
from ebooklib import epub
|
|
|
|
|
|
|
|
from audiblez.core import main, find_document_chapters_and_extract_texts
|
2025-01-23 22:31:22 +01:00
|
|
|
|
2025-02-19 14:56:09 +01:00
|
|
|
# from phonemizer.backend.espeak.wrapper import EspeakWrapper
|
|
|
|
|
|
|
|
# EspeakWrapper.set_library('/opt/homebrew/Cellar/espeak-ng/1.52.0/lib/libespeak-ng.1.dylib')
|
|
|
|
|
2025-01-23 22:31:22 +01:00
|
|
|
|
|
|
|
class MainTest(unittest.TestCase):
|
2025-02-13 22:44:56 +01:00
|
|
|
def base(self, name, url='', **kwargs):
|
2025-01-31 20:02:21 +01:00
|
|
|
if not Path(f'{name}.epub').exists():
|
|
|
|
os.system(f'wget {url} -O {name}.epub')
|
|
|
|
Path(f'{name}.m4b').unlink(missing_ok=True)
|
|
|
|
os.system(f'rm {name}_chapter_*.wav')
|
2025-02-07 15:48:05 +01:00
|
|
|
merged_args = dict(voice='af_sky', pick_manually=False, speed=1.0, max_chapters=1, max_sentences=2)
|
2025-01-31 14:13:37 +01:00
|
|
|
merged_args.update(kwargs)
|
2025-01-31 20:02:21 +01:00
|
|
|
main(f'{name}.epub', **merged_args)
|
2025-01-31 21:45:37 +01:00
|
|
|
m4b_file = Path(f'{name}.m4b')
|
|
|
|
self.assertTrue(m4b_file.exists())
|
2025-02-07 15:48:05 +01:00
|
|
|
self.assertTrue(m4b_file.stat().st_size > 1024)
|
2025-01-31 20:02:21 +01:00
|
|
|
|
|
|
|
def test_poe(self):
|
|
|
|
url = 'https://www.gutenberg.org/ebooks/1064.epub.images'
|
2025-01-31 21:45:37 +01:00
|
|
|
self.base('poe', url)
|
2025-01-31 20:02:21 +01:00
|
|
|
|
|
|
|
def test_orwell(self):
|
|
|
|
url = 'https://archive.org/download/AnimalFarmByGeorgeOrwell/Animal%20Farm%20by%20George%20Orwell.epub'
|
|
|
|
self.base('orwell', url)
|
|
|
|
|
2025-02-24 10:13:58 +01:00
|
|
|
def test_italian_pirandello_and_filename_with_spaces(self):
|
2025-01-31 21:45:37 +01:00
|
|
|
url = 'https://www.liberliber.eu/mediateca/libri/p/pirandello/cosi_e_se_vi_pare_1925/epub/pirandello_cosi_e_se_vi_pare_1925.epub'
|
2025-02-24 10:13:58 +01:00
|
|
|
self.base('pirandello e spazio', url, voice='im_nicola')
|
|
|
|
self.assertTrue(Path('pirandello e spazio.m4b').exists())
|
2025-01-31 14:39:32 +01:00
|
|
|
|
2025-01-31 20:02:21 +01:00
|
|
|
def test_italian_manzoni(self):
|
|
|
|
url = 'https://www.liberliber.eu/mediateca/libri/m/manzoni/i_promessi_sposi/epub/manzoni_i_promessi_sposi.epub'
|
2025-02-07 15:48:05 +01:00
|
|
|
self.base('manzoni', url, voice='im_nicola')
|
2025-01-31 20:02:21 +01:00
|
|
|
|
|
|
|
def test_french_baudelaire(self):
|
|
|
|
url = 'http://gallica.bnf.fr/ark:/12148/bpt6k70861t.epub'
|
|
|
|
self.base('baudelaire', url, voice='ff_siwis')
|
2025-02-03 12:29:19 +01:00
|
|
|
|
|
|
|
def test_chinese(self):
|
|
|
|
url = 'https://www.gutenberg.org/ebooks/24225.epub3.images'
|
|
|
|
self.base('chinese', url, voice='zf_xiaobei')
|
2025-02-13 22:44:56 +01:00
|
|
|
|
2025-02-19 14:31:03 +01:00
|
|
|
def test_leigh_and_play_result(self):
|
2025-02-13 22:44:56 +01:00
|
|
|
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)
|
2025-02-19 14:31:03 +01:00
|
|
|
subprocess.run(['ffplay', '-nodisp', '-autoexit', 'leigh.m4b'], check=True)
|
|
|
|
|