@@ -82,6 +82,64 @@ async def run(self, text: str, settings: TTSModelSettings):
8282 assert audio_chunks == [np .array ([1 ], dtype = np .int16 ).tobytes ()]
8383
8484
85+ @pytest .mark .asyncio
86+ async def test_streamed_audio_result_synthesizes_short_custom_splitter_chunk () -> None :
87+ texts : list [str ] = []
88+
89+ class RecordingTTS (FakeTTS ):
90+ async def run (self , text : str , settings : TTSModelSettings ):
91+ texts .append (text )
92+ yield np .zeros (2 , dtype = np .int16 ).tobytes ()
93+
94+ def split_immediately (text : str ) -> tuple [str , str ]:
95+ return text , ""
96+
97+ result = StreamedAudioResult (
98+ RecordingTTS (),
99+ TTSModelSettings (buffer_size = 1 , text_splitter = split_immediately ),
100+ VoicePipelineConfig (),
101+ )
102+
103+ await result ._add_text ("ok" )
104+ await result ._turn_done ()
105+ await result ._done ()
106+
107+ events , audio_chunks = await extract_events (result )
108+
109+ assert texts == ["ok" ]
110+ assert events == ["turn_started" , "audio" , "turn_ended" , "session_ended" ]
111+ assert audio_chunks == [np .zeros (2 , dtype = np .int16 ).tobytes ()]
112+
113+
114+ @pytest .mark .asyncio
115+ async def test_streamed_audio_result_ignores_empty_custom_splitter_chunk () -> None :
116+ texts : list [str ] = []
117+
118+ class RecordingTTS (FakeTTS ):
119+ async def run (self , text : str , settings : TTSModelSettings ):
120+ texts .append (text )
121+ yield np .zeros (2 , dtype = np .int16 ).tobytes ()
122+
123+ def discard_text (_text : str ) -> tuple [str , str ]:
124+ return "" , ""
125+
126+ result = StreamedAudioResult (
127+ RecordingTTS (),
128+ TTSModelSettings (buffer_size = 1 , text_splitter = discard_text ),
129+ VoicePipelineConfig (),
130+ )
131+
132+ await result ._add_text ("ok" )
133+ await result ._turn_done ()
134+ await result ._done ()
135+
136+ events , audio_chunks = await extract_events (result )
137+
138+ assert texts == []
139+ assert events == ["turn_started" , "turn_ended" , "session_ended" ]
140+ assert audio_chunks == []
141+
142+
85143@pytest .mark .asyncio
86144async def test_voicepipeline_run_single_turn () -> None :
87145 # Single turn. Should produce a single audio output, which is the TTS output for "out_1".
0 commit comments