"""Run with the installed TTS Python to exercise its actual NumPy PCM format.""" import tempfile,unittest from pathlib import Path from tts_worker import streaming_wave class WorkerPCMTests(unittest.TestCase): def setUp(self): try:import numpy except ImportError:self.skipTest('Run with the installed TTS runtime (NumPy required).') self.np=numpy def test_pcm_is_published_before_complete_wave_and_clips_correctly(self): with tempfile.TemporaryDirectory() as d: np=self.np;root=Path(d) class Model: def generate_custom_voice_streaming(self,**kwargs): assert kwargs['chunk_size']==4 yield np.array([-2.,0.,2.]),24000,{} assert (root/'chunk-000000.pcm').is_file() assert not (root/'result.wav').exists() yield np.array([.5]),24000,{} wave,rate=streaming_wave(Model(),dict(output=d,text='Test',language='German',speaker='Serena')) self.assertEqual(rate,24000);self.assertEqual(len(wave),4) self.assertEqual(np.frombuffer((root/'chunk-000000.pcm').read_bytes(),dtype='