|
15 | 15 | "Install it with: pip install websockets" |
16 | 16 | ) |
17 | 17 |
|
| 18 | +from ..url_utils import build_ws_url |
18 | 19 | from .connection import RealtimeConnection |
19 | 20 |
|
20 | 21 |
|
@@ -367,30 +368,22 @@ def _build_websocket_url( |
367 | 368 | include_timestamps: typing.Optional[bool] = None |
368 | 369 | ) -> str: |
369 | 370 | """Build the WebSocket URL with query parameters""" |
370 | | - # Extract base domain |
371 | | - base = self.base_url.replace("https://", "wss://").replace("http://", "ws://") |
372 | | - |
373 | | - # Build query parameters |
374 | 371 | params = [ |
375 | | - f"model_id={model_id}", |
376 | | - f"audio_format={audio_format}", |
377 | | - f"commit_strategy={commit_strategy}" |
| 372 | + ("model_id", model_id), |
| 373 | + ("audio_format", audio_format), |
| 374 | + ("commit_strategy", commit_strategy), |
378 | 375 | ] |
379 | | - |
380 | | - # Add optional VAD parameters |
381 | | - if vad_silence_threshold_secs is not None: |
382 | | - params.append(f"vad_silence_threshold_secs={vad_silence_threshold_secs}") |
383 | | - if vad_threshold is not None: |
384 | | - params.append(f"vad_threshold={vad_threshold}") |
385 | | - if min_speech_duration_ms is not None: |
386 | | - params.append(f"min_speech_duration_ms={min_speech_duration_ms}") |
387 | | - if min_silence_duration_ms is not None: |
388 | | - params.append(f"min_silence_duration_ms={min_silence_duration_ms}") |
389 | | - if language_code is not None: |
390 | | - params.append(f"language_code={language_code}") |
| 376 | + for key, value in [ |
| 377 | + ("vad_silence_threshold_secs", vad_silence_threshold_secs), |
| 378 | + ("vad_threshold", vad_threshold), |
| 379 | + ("min_speech_duration_ms", min_speech_duration_ms), |
| 380 | + ("min_silence_duration_ms", min_silence_duration_ms), |
| 381 | + ("language_code", language_code), |
| 382 | + ]: |
| 383 | + if value is not None: |
| 384 | + params.append((key, str(value))) |
391 | 385 | if include_timestamps is not None: |
392 | | - params.append(f"include_timestamps={str(include_timestamps).lower()}") |
| 386 | + params.append(("include_timestamps", str(include_timestamps).lower())) |
393 | 387 |
|
394 | | - query_string = "&".join(params) |
395 | | - return f"{base}/v1/speech-to-text/realtime?{query_string}" |
| 388 | + return build_ws_url(self.base_url, "v1/speech-to-text/realtime", params) |
396 | 389 |
|
0 commit comments