Skip to content

Commit ee751cb

Browse files
authored
feat(voice)!: migrate STT streaming to match GA Realtime API (#1759)
1 parent aeaf83f commit ee751cb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/agents/tracing/spans.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class SpanError(TypedDict):
2222
message: A human-readable error description
2323
data: Optional dictionary containing additional error context
2424
"""
25+
2526
message: str
2627
data: dict[str, Any] | None
2728

src/agents/voice/models/openai_stt.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,16 @@ async def _configure_session(self) -> None:
163163
await self._websocket.send(
164164
json.dumps(
165165
{
166-
"type": "transcription_session.update",
166+
"type": "session.update",
167167
"session": {
168-
"input_audio_format": "pcm16",
169-
"input_audio_transcription": {"model": self._model},
170-
"turn_detection": self._turn_detection,
168+
"type": "transcription",
169+
"audio": {
170+
"input": {
171+
"format": {"type": "audio/pcm", "rate": 24000},
172+
"transcription": {"model": self._model},
173+
"turn_detection": self._turn_detection,
174+
}
175+
},
171176
},
172177
}
173178
)

tests/voice/test_openai_stt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ async def test_session_connects_and_configures_successfully():
115115
assert headers.get("OpenAI-Beta") is None
116116
assert headers.get("OpenAI-Log-Session") == "1"
117117

118-
# Check that we sent a 'transcription_session.update' message
118+
# Check that we sent a 'session.update' message
119119
sent_messages = [call.args[0] for call in mock_ws.send.call_args_list]
120-
assert any('"type": "transcription_session.update"' in msg for msg in sent_messages), (
121-
f"Expected 'transcription_session.update' in {sent_messages}"
120+
assert any('"type": "session.update"' in msg for msg in sent_messages), (
121+
f"Expected 'session.update' in {sent_messages}"
122122
)
123123

124124
await session.close()

0 commit comments

Comments
 (0)