Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e1a6f03
feat(tests): add eou feou test for voice transcription
sam-s10s Feb 4, 2026
9b1730c
feat: update and add new audio samples for tests
sam-s10s Feb 4, 2026
0873abb
Squashed commit of the following:
sam-s10s Feb 18, 2026
b6cb0e6
feat: add audio timestamp to ForceEndOfUtterance message
sam-s10s Feb 18, 2026
1567b28
enhance: add tracking of audio bytes sent and timestamps
sam-s10s Feb 18, 2026
f708c65
feat: add timestamp to force_end_of_utterance method
sam-s10s Feb 18, 2026
e9ea4d8
Merge branch 'main' into fix/feou
sam-s10s Feb 18, 2026
35318b2
revert change not meant for this MR
sam-s10s Feb 18, 2026
656ab23
test: add new test for audio timestamp accuracy
sam-s10s Feb 18, 2026
ba2d382
fix: adjust tolerance to zero in timestamp test
sam-s10s Feb 18, 2026
38432c1
refactor: update test for varied audio formats
sam-s10s Feb 18, 2026
21c09c5
updated test URL
sam-s10s Feb 18, 2026
f1a94de
enhance: add custom listeners for improved test logging
sam-s10s Feb 18, 2026
5a5245e
feat: enable additional audio test cases in test_17_eou_feou
sam-s10s Feb 22, 2026
33e693f
refactor: enhance end of turn penalty logic
sam-s10s Feb 23, 2026
301bcf4
refactor: enhance end of turn penalty logic
sam-s10s Feb 23, 2026
d9de589
Add Penalty when Smart Turn hasn't been run (#86)
LArmstrongDev Feb 25, 2026
3375c3d
Merge branch 'fix/smart-turn' of https://github.com/speechmatics/spee…
sam-s10s Feb 25, 2026
7a52b3f
test: add `test_no_feou_fix` for FEOU disabled
sam-s10s Mar 2, 2026
1443b33
feat: integrate config validation and improve presets
sam-s10s Mar 2, 2026
386f37b
fix: enforce use of forced end of utterance
sam-s10s Mar 3, 2026
155fceb
refactor: simplify EOU and VAD logic, improve readability
sam-s10s Mar 3, 2026
0b28473
refactor: remove forced end-of-utterance config from tests
sam-s10s Mar 3, 2026
31aa3ac
remove: Delete outdated conditional validation for 'use_forced_eou' i…
sam-s10s Mar 3, 2026
ca0f22f
fix: handle forced EOU more securely in turn management
sam-s10s Mar 3, 2026
95dda05
manually set FEOU to be disabled for the tests.
sam-s10s Mar 3, 2026
5ecc473
remove `ws_headers` as part of a different PR
sam-s10s Mar 3, 2026
e30cc5e
fix: correct logic for end of utterance handling
sam-s10s Mar 3, 2026
cd7de39
`refactor: extract config setup and ensure client disconnect`
sam-s10s Mar 3, 2026
7f03cc5
chore: pin speechmatics-rt dependency version for voice
sam-s10s Mar 5, 2026
81815ee
fix: support 8kHz audio in VAD and smart turn
sam-s10s Mar 10, 2026
0e56620
fix: only predict end of turn when speech ended
sam-s10s Mar 11, 2026
4182979
test: re-enable speaker focus test cases
sam-s10s Mar 11, 2026
5583174
test: use env var for RT URL and fix assertions
sam-s10s Mar 11, 2026
18b56f9
fix: remove unused turn extend delay and dead code
sam-s10s Mar 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions sdk/rt/speechmatics/rt/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def __init__(
self.on(ServerMessageType.WARNING, self._on_warning)
self.on(ServerMessageType.AUDIO_ADDED, self._on_audio_added)

# Audio format is set when start_session is called with an explicit format.
# Deliberately None until then to avoid silently using incorrect defaults.
self._audio_format: Optional[AudioFormat] = None

self._logger.debug("AsyncClient initialized (request_id=%s)", self._session.request_id)

async def start_session(
Expand Down Expand Up @@ -133,7 +137,10 @@ async def start_session(
... await client.start_session()
... await client.send_audio(frame)
"""
await self._start_recognition_session(

# _start_recognition_session resolves defaults (e.g. AudioFormat() if None),
# so we capture the resolved format to keep _audio_format in sync.
_, self._audio_format = await self._start_recognition_session(
transcription_config=transcription_config,
audio_format=audio_format,
translation_config=translation_config,
Expand Down Expand Up @@ -161,16 +168,27 @@ async def stop_session(self) -> None:
await self._session_done_evt.wait() # Wait for end of transcript event to indicate we can stop listening
await self.close()

async def force_end_of_utterance(self) -> None:
async def force_end_of_utterance(self, timestamp: Optional[float] = None) -> float:
"""
This method sends a ForceEndOfUtterance message to the server to signal
the end of an utterance. Forcing end of utterance will cause the final
transcript to be sent to the client early.

Takes an optional timestamp parameter to specify a marker for the engine
to use for timing of the end of the utterance. If not provided, the timestamp
will be calculated based on the cumulative audio sent to the server.

Args:
timestamp: Optional timestamp for the request.

Returns:
The timestamp that was used for the request.

Raises:
ConnectionError: If the WebSocket connection fails.
TranscriptionError: If the server reports an error during teardown.
TimeoutError: If the connection or teardown times out.
ValueError: If the audio format does not have an encoding set.

Examples:
Basic streaming:
Expand All @@ -179,7 +197,26 @@ async def force_end_of_utterance(self) -> None:
... await client.send_audio(frame)
... await client.force_end_of_utterance()
"""
await self.send_message({"message": ClientMessageType.FORCE_END_OF_UTTERANCE})
if timestamp is None:
timestamp = self.audio_seconds_sent

await self.send_message({"message": ClientMessageType.FORCE_END_OF_UTTERANCE, "timestamp": timestamp})

return timestamp

@property
def audio_seconds_sent(self) -> float:
"""Number of audio seconds sent to the server.

Raises:
ValueError: If called before start_session has set the audio format,
or if the audio format does not have an encoding set.
"""
# _audio_format is only set once start_session receives an explicit AudioFormat.
# Failing here prevents silently computing with wrong defaults (e.g. 44100Hz).
if self._audio_format is None:
raise ValueError("audio_seconds_sent is not available before start_session is called with an audio format")
return self._audio_bytes_sent / (self._audio_format.sample_rate * self._audio_format.bytes_per_sample)

async def transcribe(
self,
Expand Down
7 changes: 7 additions & 0 deletions sdk/rt/speechmatics/rt/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, transport: Transport) -> None:
self._recv_task: Optional[asyncio.Task[None]] = None
self._closed_evt = asyncio.Event()
self._eos_sent = False
self._audio_bytes_sent = 0
self._seq_no = 0

self._logger = get_logger("speechmatics.rt.base_client")
Expand Down Expand Up @@ -122,11 +123,17 @@ async def send_audio(self, payload: bytes) -> None:

try:
await self._transport.send_message(payload)
self._audio_bytes_sent += len(payload)
self._seq_no += 1
except Exception:
self._closed_evt.set()
raise

@property
def audio_bytes_sent(self) -> int:
"""Number of audio bytes sent to the server."""
return self._audio_bytes_sent

async def send_message(self, message: dict[str, Any]) -> None:
"""
Send a message through the WebSocket.
Expand Down
23 changes: 23 additions & 0 deletions sdk/rt/speechmatics/rt/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,29 @@ class AudioFormat:
sample_rate: int = 44100
chunk_size: int = 4096

_BYTES_PER_SAMPLE = {
AudioEncoding.PCM_F32LE: 4,
AudioEncoding.PCM_S16LE: 2,
AudioEncoding.MULAW: 1,
}

@property
def bytes_per_sample(self) -> int:
"""Number of bytes per audio sample based on encoding.

Raises:
ValueError: If encoding is None (file type) or unrecognized.
"""
if self.encoding is None:
raise ValueError(
"Cannot determine bytes per sample for file-type audio format. "
"Set an explicit encoding on AudioFormat."
)
try:
return self._BYTES_PER_SAMPLE[self.encoding]
except KeyError:
raise ValueError(f"Unknown encoding: {self.encoding}")

def to_dict(self) -> dict[str, Any]:
"""
Convert audio format to dictionary.
Expand Down
2 changes: 1 addition & 1 deletion sdk/voice/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [{ name = "Speechmatics", email = "support@speechmatics.com" }]
license = "MIT"
requires-python = ">=3.9"
dependencies = [
"speechmatics-rt>=0.5.3",
"speechmatics-rt==0.5.3",
"pydantic>=2.10.6,<3",
"numpy>=1.26.4,<3"
]
Expand Down
Loading
Loading