Skip to content

Commit 570c888

Browse files
authored
Merge pull request #50 from speechmatics/feature/force-end-of-utterance
Add force eou
2 parents cb65397 + 3489fbf commit 570c888

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

sdk/rt/speechmatics/rt/_async_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ async def stop_session(self) -> None:
161161
await self._session_done_evt.wait() # Wait for end of transcript event to indicate we can stop listening
162162
await self.close()
163163

164+
async def force_end_of_utterance(self) -> None:
165+
"""
166+
This method sends a ForceEndOfUtterance message to the server to signal
167+
the end of an utterance. Forcing end of utterance will cause the final
168+
transcript to be sent to the client early.
169+
170+
Raises:
171+
ConnectionError: If the WebSocket connection fails.
172+
TranscriptionError: If the server reports an error during teardown.
173+
TimeoutError: If the connection or teardown times out.
174+
175+
Examples:
176+
Basic streaming:
177+
>>> async with AsyncClient() as client:
178+
... await client.start_session()
179+
... await client.send_audio(frame)
180+
... await client.force_end_of_utterance()
181+
"""
182+
await self.send_message({"message": ClientMessageType.FORCE_END_OF_UTTERANCE})
183+
164184
async def transcribe(
165185
self,
166186
source: BinaryIO,

sdk/rt/speechmatics/rt/_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class ClientMessageType(str, Enum):
6363
SetRecognitionConfig: Updates transcription configuration during
6464
an active session (advanced use).
6565
GetSpeakers: Allows the client to request speaker data.
66+
AddChannelAudio: Indicates that audio data follows (not used in message
67+
headers, audio is sent as binary data).
68+
EndOfChannel: Signals that no more audio data will be sent.
69+
ForceEndOfUtterance: Signals that the end of an utterance has been reached.
6670
6771
Examples:
6872
>>> # Starting a recognition session
@@ -86,6 +90,7 @@ class ClientMessageType(str, Enum):
8690
GET_SPEAKERS = "GetSpeakers"
8791
ADD_CHANNEL_AUDIO = "AddChannelAudio"
8892
END_OF_CHANNEL = "EndOfChannel"
93+
FORCE_END_OF_UTTERANCE = "ForceEndOfUtterance"
8994

9095

9196
class ServerMessageType(str, Enum):

0 commit comments

Comments
 (0)