11"""Integration tests for TTS WebSocket streaming functionality."""
22
3+ from typing import get_args
4+
35import pytest
46
57from fishaudio import WebSocketOptions
68from fishaudio .types import Prosody , TTSConfig , TextEvent , FlushEvent
9+ from fishaudio .types .shared import Model
710from .conftest import TEST_REFERENCE_ID
811
912
@@ -31,6 +34,26 @@ def text_stream():
3134 # Save the audio
3235 save_audio (audio_chunks , "test_websocket_streaming.mp3" )
3336
37+ def test_websocket_streaming_with_different_models (self , client , save_audio ):
38+ """Test WebSocket streaming with different models."""
39+ import time
40+
41+ models = get_args (Model )
42+
43+ for model in models :
44+
45+ def text_stream ():
46+ yield f"Testing model { model } via WebSocket."
47+
48+ audio_chunks = list (client .tts .stream_websocket (text_stream (), model = model ))
49+ assert len (audio_chunks ) > 0 , f"Failed for model: { model } "
50+
51+ # Write to output directory
52+ save_audio (audio_chunks , f"test_websocket_model_{ model } .mp3" )
53+
54+ # Brief delay to avoid SSL errors when opening next WebSocket connection
55+ time .sleep (0.3 )
56+
3457 def test_websocket_streaming_with_wav_format (self , client , save_audio ):
3558 """Test WebSocket streaming with WAV format."""
3659 config = TTSConfig (format = "wav" , chunk_length = 200 )
@@ -195,6 +218,34 @@ async def text_stream():
195218
196219 save_audio (audio_chunks , "test_async_websocket_streaming.mp3" )
197220
221+ @pytest .mark .asyncio
222+ async def test_async_websocket_streaming_with_different_models (
223+ self , async_client , save_audio
224+ ):
225+ """Test async WebSocket streaming with different models."""
226+ import asyncio
227+
228+ models = get_args (Model )
229+
230+ for model in models :
231+
232+ async def text_stream ():
233+ yield f"Testing model { model } via async WebSocket."
234+
235+ audio_chunks = []
236+ async for chunk in async_client .tts .stream_websocket (
237+ text_stream (), model = model
238+ ):
239+ audio_chunks .append (chunk )
240+
241+ assert len (audio_chunks ) > 0 , f"Failed for model: { model } "
242+
243+ # Write to output directory
244+ save_audio (audio_chunks , f"test_async_websocket_model_{ model } .mp3" )
245+
246+ # Brief delay to avoid SSL errors when opening next WebSocket connection
247+ await asyncio .sleep (0.3 )
248+
198249 @pytest .mark .asyncio
199250 async def test_async_websocket_streaming_with_format (
200251 self , async_client , save_audio
@@ -285,6 +336,8 @@ async def test_async_websocket_streaming_multiple_calls(
285336 self , async_client , save_audio
286337 ):
287338 """Test multiple async WebSocket streaming calls in sequence."""
339+ import asyncio
340+
288341 for i in range (3 ):
289342
290343 async def text_stream ():
@@ -297,6 +350,9 @@ async def text_stream():
297350 assert len (audio_chunks ) > 0 , f"Call { i + 1 } should return audio"
298351 save_audio (audio_chunks , f"test_async_websocket_call_{ i + 1 } .mp3" )
299352
353+ # Brief delay to avoid SSL errors when opening next WebSocket connection
354+ await asyncio .sleep (0.3 )
355+
300356 @pytest .mark .asyncio
301357 async def test_async_websocket_streaming_empty_text (self , async_client , save_audio ):
302358 """Test async WebSocket streaming with empty text stream raises error."""
0 commit comments