Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 49 additions & 37 deletions tests/integration/test_tts_websocket_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,31 @@ def text_stream():
save_audio(audio_chunks, "test_websocket_streaming.mp3")

@pytest.mark.flaky(reruns=9, reruns_delay=1)
def test_websocket_streaming_with_different_models(self, client, save_audio):
"""Test WebSocket streaming with different models."""
import time
@pytest.mark.parametrize(
"model",
[
pytest.param(
m,
marks=pytest.mark.xfail(
reason="WebSocket unreliable for legacy models"
),
)
if not m.startswith("s1")
else m
for m in get_args(Model)
],
)
def test_websocket_streaming_with_model(self, client, save_audio, model):
"""Test WebSocket streaming with a specific model."""

models = get_args(Model)

for model in models:

def text_stream():
yield f"Testing model {model} via WebSocket."

audio_chunks = list(client.tts.stream_websocket(text_stream(), model=model))
assert len(audio_chunks) > 0, f"Failed for model: {model}"
def text_stream():
yield f"Testing model {model} via WebSocket."

# Write to output directory
save_audio(audio_chunks, f"test_websocket_model_{model}.mp3")
audio_chunks = list(client.tts.stream_websocket(text_stream(), model=model))
assert len(audio_chunks) > 0, f"Failed for model: {model}"

# Brief delay to avoid SSL errors when opening next WebSocket connection
time.sleep(1.0)
# Write to output directory
save_audio(audio_chunks, f"test_websocket_model_{model}.mp3")

def test_websocket_streaming_with_wav_format(self, client, save_audio):
"""Test WebSocket streaming with WAV format."""
Expand Down Expand Up @@ -221,32 +227,38 @@ async def text_stream():

@pytest.mark.asyncio
@pytest.mark.flaky(reruns=9, reruns_delay=1)
async def test_async_websocket_streaming_with_different_models(
self, async_client, save_audio
@pytest.mark.parametrize(
"model",
[
pytest.param(
m,
marks=pytest.mark.xfail(
reason="WebSocket unreliable for legacy models"
),
)
if not m.startswith("s1")
else m
for m in get_args(Model)
],
)
async def test_async_websocket_streaming_with_model(
self, async_client, save_audio, model
):
"""Test async WebSocket streaming with different models."""
import asyncio

models = get_args(Model)
"""Test async WebSocket streaming with a specific model."""

for model in models:

async def text_stream():
yield f"Testing model {model} via async WebSocket."

audio_chunks = []
async for chunk in async_client.tts.stream_websocket(
text_stream(), model=model
):
audio_chunks.append(chunk)
async def text_stream():
yield f"Testing model {model} via async WebSocket."

assert len(audio_chunks) > 0, f"Failed for model: {model}"
audio_chunks = []
async for chunk in async_client.tts.stream_websocket(
text_stream(), model=model
):
audio_chunks.append(chunk)

# Write to output directory
save_audio(audio_chunks, f"test_async_websocket_model_{model}.mp3")
assert len(audio_chunks) > 0, f"Failed for model: {model}"

# Brief delay to avoid SSL errors when opening next WebSocket connection
await asyncio.sleep(1.0)
# Write to output directory
save_audio(audio_chunks, f"test_async_websocket_model_{model}.mp3")

@pytest.mark.asyncio
async def test_async_websocket_streaming_with_format(
Expand Down