1919_DIR = Path (__file__ ).parent
2020_LOCAL_DIR = _DIR .parent / "local"
2121_TIMEOUT = 60
22- _REBASELINE = False
2322
2423
2524@pytest .mark .asyncio
@@ -34,8 +33,6 @@ async def test_piper() -> None:
3433 "en_US-ryan-low" ,
3534 "--data-dir" ,
3635 str (_LOCAL_DIR ),
37- "--sentence-silence" ,
38- "0.5" ,
3936 stdin = PIPE ,
4037 stdout = PIPE ,
4138 )
@@ -61,7 +58,7 @@ async def test_piper() -> None:
6158
6259 # Synthesize text
6360 await async_write_event (
64- Synthesize ("This is a test. This is sentence two. " , voice = SynthesizeVoice ("en_US-ryan-low" )).event (),
61+ Synthesize ("This is a test." , voice = SynthesizeVoice ("en_US-ryan-low" )).event (),
6562 proc .stdin ,
6663 )
6764
@@ -70,6 +67,13 @@ async def test_piper() -> None:
7067 assert AudioStart .is_type (event .type )
7168 audio_start = AudioStart .from_event (event )
7269
70+ with wave .open (str (_DIR / "this_is_a_test.wav" ), "rb" ) as wav_file :
71+ assert audio_start .rate == wav_file .getframerate ()
72+ assert audio_start .width == wav_file .getsampwidth ()
73+ assert audio_start .channels == wav_file .getnchannels ()
74+ expected_audio = wav_file .readframes (wav_file .getnframes ())
75+ expected_array = np .frombuffer (expected_audio , dtype = np .int16 )
76+
7377 actual_audio = bytes ()
7478 while True :
7579 event = await asyncio .wait_for (async_read_event (proc .stdout ), timeout = _TIMEOUT )
@@ -86,21 +90,6 @@ async def test_piper() -> None:
8690
8791 actual_array = np .frombuffer (actual_audio , dtype = np .int16 )
8892
89- if _REBASELINE :
90- with wave .open (str (_DIR / "this_is_a_test.wav" ), "w" ) as wav_file :
91- wav_file .setframerate (audio_start .rate )
92- wav_file .setsampwidth (audio_start .width )
93- wav_file .setnchannels (audio_start .channels )
94- wav_file .writeframes (actual_audio )
95- return
96- else :
97- with wave .open (str (_DIR / "this_is_a_test.wav" ), "rb" ) as wav_file :
98- assert audio_start .rate == wav_file .getframerate ()
99- assert audio_start .width == wav_file .getsampwidth ()
100- assert audio_start .channels == wav_file .getnchannels ()
101- expected_audio = wav_file .readframes (wav_file .getnframes ())
102- expected_array = np .frombuffer (expected_audio , dtype = np .int16 )
103-
10493 # Less than 20% difference in length
10594 assert (
10695 abs (len (actual_array ) - len (expected_array ))
0 commit comments