Skip to content

Commit 231f916

Browse files
Merge pull request #263 from dvonthenen/impl-vad-events-speech-start
Implements vad_events for SpeechStarted
2 parents 6b56474 + 058dcd2 commit 231f916

File tree

17 files changed

+93
-5
lines changed

17 files changed

+93
-5
lines changed

deepgram/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .client import (
2121
LiveResultResponse,
2222
MetadataResponse,
23+
SpeechStartedResponse,
2324
UtteranceEndResponse,
2425
ErrorResponse,
2526
)

deepgram/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .clients import (
2222
LiveResultResponse,
2323
MetadataResponse,
24+
SpeechStartedResponse,
2425
UtteranceEndResponse,
2526
ErrorResponse,
2627
)

deepgram/clients/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .live import (
1414
LiveResultResponse,
1515
MetadataResponse,
16+
SpeechStartedResponse,
1617
UtteranceEndResponse,
1718
ErrorResponse,
1819
)

deepgram/clients/listen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from .live import (
3737
LiveResultResponse,
3838
MetadataResponse,
39+
SpeechStartedResponse,
3940
UtteranceEndResponse,
4041
ErrorResponse,
4142
)

deepgram/clients/live/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .client import (
1010
LiveResultResponse,
1111
MetadataResponse,
12+
SpeechStartedResponse,
1213
UtteranceEndResponse,
1314
ErrorResponse,
1415
)

deepgram/clients/live/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .v1.response import (
1010
LiveResultResponse as LiveResultResponseLatest,
1111
MetadataResponse as MetadataResponseLatest,
12+
SpeechStartedResponse as SpeechStartedResponseLatest,
1213
UtteranceEndResponse as UtteranceEndResponseLatest,
1314
ErrorResponse as ErrorResponseLatest,
1415
)
@@ -45,6 +46,14 @@ class MetadataResponse(MetadataResponseLatest):
4546
pass
4647

4748

49+
class SpeechStartedResponse(SpeechStartedResponseLatest):
50+
"""
51+
pass through for SpeechStartedResponse based on API version
52+
"""
53+
54+
pass
55+
56+
4857
class UtteranceEndResponse(UtteranceEndResponseLatest):
4958
"""
5059
pass through for UtteranceEndResponse based on API version

deepgram/clients/live/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ class LiveTranscriptionEvents(Enum):
1515
Transcript = "Results"
1616
Metadata = "Metadata"
1717
UtteranceEnd = "UtteranceEnd"
18+
SpeechStarted = "SpeechStarted"
1819
Error = "Error"
1920
Warning = "Warning"

deepgram/clients/live/v1/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .response import (
1010
LiveResultResponse,
1111
MetadataResponse,
12+
SpeechStartedResponse,
1213
UtteranceEndResponse,
1314
ErrorResponse,
1415
)

deepgram/clients/live/v1/async_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .response import (
1515
LiveResultResponse,
1616
MetadataResponse,
17+
SpeechStartedResponse,
1718
UtteranceEndResponse,
1819
ErrorResponse,
1920
)
@@ -129,6 +130,19 @@ async def _start(self) -> None:
129130
metadata=result,
130131
**dict(self.kwargs),
131132
)
133+
case LiveTranscriptionEvents.SpeechStarted.value:
134+
self.logger.debug(
135+
"response_type: %s, data: %s", response_type, data
136+
)
137+
result = SpeechStartedResponse.from_json(message)
138+
if result is None:
139+
self.logger.error("SpeechStartedResponse.from_json is None")
140+
continue
141+
await self._emit(
142+
LiveTranscriptionEvents.SpeechStarted,
143+
speech_started=result,
144+
**dict(self.kwargs),
145+
)
132146
case LiveTranscriptionEvents.UtteranceEnd.value:
133147
self.logger.debug(
134148
"response_type: %s, data: %s", response_type, data

deepgram/clients/live/v1/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .response import (
1717
LiveResultResponse,
1818
MetadataResponse,
19+
SpeechStartedResponse,
1920
UtteranceEndResponse,
2021
ErrorResponse,
2122
)
@@ -161,6 +162,19 @@ def _listening(self) -> None:
161162
metadata=result,
162163
**dict(self.kwargs),
163164
)
165+
case LiveTranscriptionEvents.SpeechStarted.value:
166+
self.logger.debug(
167+
"response_type: %s, data: %s", response_type, data
168+
)
169+
result = SpeechStartedResponse.from_json(message)
170+
if result is None:
171+
self.logger.error("SpeechStartedResponse.from_json is None")
172+
continue
173+
self._emit(
174+
LiveTranscriptionEvents.SpeechStarted,
175+
speech_started=result,
176+
**dict(self.kwargs),
177+
)
164178
case LiveTranscriptionEvents.UtteranceEnd.value:
165179
self.logger.debug(
166180
"response_type: %s, data: %s", response_type, data

0 commit comments

Comments
 (0)