From 017a10e1a1ec780efc8406cc4627678dad5aeaad Mon Sep 17 00:00:00 2001 From: notV3NOM <123deeznuts456789@gmail.com> Date: Tue, 16 Sep 2025 20:36:18 +0530 Subject: [PATCH] feat(voice)!: migrate STT streaming to match GA Realtime API --- src/agents/tracing/spans.py | 1 + src/agents/voice/models/openai_stt.py | 13 +++++++++---- tests/voice/test_openai_stt.py | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/agents/tracing/spans.py b/src/agents/tracing/spans.py index d0a416b8c..dbde6f9ec 100644 --- a/src/agents/tracing/spans.py +++ b/src/agents/tracing/spans.py @@ -22,6 +22,7 @@ class SpanError(TypedDict): message: A human-readable error description data: Optional dictionary containing additional error context """ + message: str data: dict[str, Any] | None diff --git a/src/agents/voice/models/openai_stt.py b/src/agents/voice/models/openai_stt.py index 12333b025..f0255f24b 100644 --- a/src/agents/voice/models/openai_stt.py +++ b/src/agents/voice/models/openai_stt.py @@ -163,11 +163,16 @@ async def _configure_session(self) -> None: await self._websocket.send( json.dumps( { - "type": "transcription_session.update", + "type": "session.update", "session": { - "input_audio_format": "pcm16", - "input_audio_transcription": {"model": self._model}, - "turn_detection": self._turn_detection, + "type": "transcription", + "audio": { + "input": { + "format": {"type": "audio/pcm", "rate": 24000}, + "transcription": {"model": self._model}, + "turn_detection": self._turn_detection, + } + }, }, } ) diff --git a/tests/voice/test_openai_stt.py b/tests/voice/test_openai_stt.py index 12c58a22c..8eefc995f 100644 --- a/tests/voice/test_openai_stt.py +++ b/tests/voice/test_openai_stt.py @@ -115,10 +115,10 @@ async def test_session_connects_and_configures_successfully(): assert headers.get("OpenAI-Beta") is None assert headers.get("OpenAI-Log-Session") == "1" - # Check that we sent a 'transcription_session.update' message + # Check that we sent a 'session.update' message sent_messages = [call.args[0] for call in mock_ws.send.call_args_list] - assert any('"type": "transcription_session.update"' in msg for msg in sent_messages), ( - f"Expected 'transcription_session.update' in {sent_messages}" + assert any('"type": "session.update"' in msg for msg in sent_messages), ( + f"Expected 'session.update' in {sent_messages}" ) await session.close()