Skip to content

Commit 8eddda1

Browse files
authored
chore: sync sdk code with DeepLearning repo (#177)
Add speech started event for u3pro streaming
1 parent 3147116 commit 8eddda1

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

assemblyai/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.54.0"
1+
__version__ = "0.54.1"

assemblyai/streaming/v3/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
EventMessage,
66
LLMGatewayResponseEvent,
77
SpeechModel,
8+
SpeechStartedEvent,
89
StreamingClientOptions,
910
StreamingError,
1011
StreamingEvents,
@@ -21,6 +22,7 @@
2122
"EventMessage",
2223
"LLMGatewayResponseEvent",
2324
"SpeechModel",
25+
"SpeechStartedEvent",
2426
"StreamingClient",
2527
"StreamingClientOptions",
2628
"StreamingError",

assemblyai/streaming/v3/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ForceEndpoint,
2121
LLMGatewayResponseEvent,
2222
OperationMessage,
23+
SpeechStartedEvent,
2324
StreamingClientOptions,
2425
StreamingError,
2526
StreamingErrorCodes,
@@ -236,6 +237,8 @@ def _parse_message(self, data: Dict[str, Any]) -> Optional[EventMessage]:
236237
return TerminationEvent.model_validate(data)
237238
elif event_type == StreamingEvents.Turn:
238239
return TurnEvent.model_validate(data)
240+
elif event_type == StreamingEvents.SpeechStarted:
241+
return SpeechStartedEvent.model_validate(data)
239242
elif event_type == StreamingEvents.LLMGatewayResponse:
240243
return LLMGatewayResponseEvent.model_validate(data)
241244
else:

assemblyai/streaming/v3/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class TerminationEvent(BaseModel):
4949
session_duration_seconds: Optional[int] = None
5050

5151

52+
class SpeechStartedEvent(BaseModel):
53+
type: Literal["SpeechStarted"] = "SpeechStarted"
54+
timestamp: int
55+
56+
5257
class ErrorEvent(BaseModel):
5358
error: str
5459

@@ -64,6 +69,7 @@ class LLMGatewayResponseEvent(BaseModel):
6469
BeginEvent,
6570
TerminationEvent,
6671
TurnEvent,
72+
SpeechStartedEvent,
6773
ErrorEvent,
6874
LLMGatewayResponseEvent,
6975
]
@@ -175,5 +181,6 @@ class StreamingEvents(Enum):
175181
Begin = "Begin"
176182
Termination = "Termination"
177183
Turn = "Turn"
184+
SpeechStarted = "SpeechStarted"
178185
Error = "Error"
179186
LLMGatewayResponse = "LLMGatewayResponse"

tests/unit/test_streaming.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from assemblyai.streaming.v3 import (
66
SpeechModel,
7+
SpeechStartedEvent,
78
StreamingClient,
89
StreamingClientOptions,
910
StreamingParameters,
@@ -352,3 +353,14 @@ def test_turn_event_without_speaker_label():
352353
}
353354
event = TurnEvent.parse_obj(data)
354355
assert event.speaker_label is None
356+
357+
358+
def test_speech_started_event():
359+
"""Test SpeechStarted event parsing (u3-rt-pro only)"""
360+
data = {
361+
"type": "SpeechStarted",
362+
"timestamp": 1280,
363+
}
364+
event = SpeechStartedEvent.parse_obj(data)
365+
assert event.type == "SpeechStarted"
366+
assert event.timestamp == 1280

0 commit comments

Comments
 (0)