From ee751cb2039f2db6071a3cebb4a7ef27adbbb979 Mon Sep 17 00:00:00 2001 From: Shagun Bera <141054835+notV3NOM@users.noreply.github.com> Date: Wed, 17 Sep 2025 10:23:41 +0530 Subject: [PATCH] feat(voice)!: migrate STT streaming to match GA Realtime API (#1759) --- 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 d0a416b8..dbde6f9e 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 12333b02..f0255f24 100644 --- a/src/agents/voice/models/openai_stt.py +++ b/src/agents/voice/models/openai_stt.py @@ -163,11 +163,16 @@ class OpenAISTTTranscriptionSession(StreamedTranscriptionSession): 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 12c58a22..8eefc995 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()