Skip to content

Commit 1749ecd

Browse files
committed
fix: unsupported message structure should not break loop; add transcription delta support
1 parent 163f529 commit 1749ecd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

realtime_agent/realtime/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def handle_server_message(self, message: str) -> ServerToClientMessage:
107107
return parse_server_message(message)
108108
except Exception as e:
109109
logger.error("Error handling message: " + str(e))
110-
raise e
110+
#raise e
111111

112112
async def close(self):
113113
# Close the websocket connection if it exists

realtime_agent/realtime/struct.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class EventType(str, Enum):
184184
ITEM_DELETED = "conversation.item.deleted"
185185
ITEM_TRUNCATED = "conversation.item.truncated"
186186
ITEM_INPUT_AUDIO_TRANSCRIPTION_COMPLETED = "conversation.item.input_audio_transcription.completed"
187+
ITEM_INPUT_AUDIO_TRANSCRIPTION_DELTA = "conversation.item.input_audio_transcription.delta"
187188
ITEM_INPUT_AUDIO_TRANSCRIPTION_FAILED = "conversation.item.input_audio_transcription.failed"
188189

189190
RESPONSE_CREATED = "response.created"
@@ -481,6 +482,13 @@ class ItemInputAudioTranscriptionCompleted(ServerToClientMessage):
481482
transcript: str # The transcribed text
482483
type: str = EventType.ITEM_INPUT_AUDIO_TRANSCRIPTION_COMPLETED # Fixed event type
483484

485+
@dataclass
486+
class ItemInputAudioTranscriptionDelta(ServerToClientMessage):
487+
item_id: str # The ID of the item for which transcription was completed
488+
content_index: int # Index of the content part that was transcribed
489+
delta: str # The transcribed text
490+
type: str = EventType.ITEM_INPUT_AUDIO_TRANSCRIPTION_DELTA # Fixed event type
491+
484492
@dataclass
485493
class ItemInputAudioTranscriptionFailed(ServerToClientMessage):
486494
item_id: str # The ID of the item for which transcription failed
@@ -726,6 +734,8 @@ def parse_server_message(unparsed_string: str) -> ServerToClientMessage:
726734
return from_dict(ItemInputAudioTranscriptionCompleted, data)
727735
elif data["type"] == EventType.ITEM_INPUT_AUDIO_TRANSCRIPTION_FAILED:
728736
return from_dict(ItemInputAudioTranscriptionFailed, data)
737+
elif data["type"] == EventType.ITEM_INPUT_AUDIO_TRANSCRIPTION_DELTA:
738+
return from_dict(ItemInputAudioTranscriptionDelta, data)
729739

730740
raise ValueError(f"Unknown message type: {data['type']}")
731741

0 commit comments

Comments
 (0)