@@ -36,6 +36,8 @@ def text_stream():
3636
3737 def test_websocket_streaming_with_different_models (self , client , save_audio ):
3838 """Test WebSocket streaming with different models."""
39+ import time
40+
3941 models = get_args (Model )
4042
4143 for model in models :
@@ -49,6 +51,9 @@ def text_stream():
4951 # Write to output directory
5052 save_audio (audio_chunks , f"test_websocket_model_{ model } .mp3" )
5153
54+ # Brief delay to avoid SSL errors when opening next WebSocket connection
55+ time .sleep (0.3 )
56+
5257 def test_websocket_streaming_with_wav_format (self , client , save_audio ):
5358 """Test WebSocket streaming with WAV format."""
5459 config = TTSConfig (format = "wav" , chunk_length = 200 )
@@ -218,6 +223,8 @@ async def test_async_websocket_streaming_with_different_models(
218223 self , async_client , save_audio
219224 ):
220225 """Test async WebSocket streaming with different models."""
226+ import asyncio
227+
221228 models = get_args (Model )
222229
223230 for model in models :
@@ -236,6 +243,9 @@ async def text_stream():
236243 # Write to output directory
237244 save_audio (audio_chunks , f"test_async_websocket_model_{ model } .mp3" )
238245
246+ # Brief delay to avoid SSL errors when opening next WebSocket connection
247+ await asyncio .sleep (0.3 )
248+
239249 @pytest .mark .asyncio
240250 async def test_async_websocket_streaming_with_format (
241251 self , async_client , save_audio
@@ -326,6 +336,8 @@ async def test_async_websocket_streaming_multiple_calls(
326336 self , async_client , save_audio
327337 ):
328338 """Test multiple async WebSocket streaming calls in sequence."""
339+ import asyncio
340+
329341 for i in range (3 ):
330342
331343 async def text_stream ():
@@ -338,6 +350,9 @@ async def text_stream():
338350 assert len (audio_chunks ) > 0 , f"Call { i + 1 } should return audio"
339351 save_audio (audio_chunks , f"test_async_websocket_call_{ i + 1 } .mp3" )
340352
353+ # Brief delay to avoid SSL errors when opening next WebSocket connection
354+ await asyncio .sleep (0.3 )
355+
341356 @pytest .mark .asyncio
342357 async def test_async_websocket_streaming_empty_text (self , async_client , save_audio ):
343358 """Test async WebSocket streaming with empty text stream raises error."""
0 commit comments