From 67a7c71d929c4dcba39841c021c8cff702fb5c54 Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 9 Jun 2025 15:23:58 +0100 Subject: [PATCH 1/4] Fix non-multichannel sessions --- CHANGELOG.md | 5 +++++ VERSION | 2 +- speechmatics/cli.py | 14 ++++++-------- speechmatics/client.py | 14 +++++++++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2292a0f..4c1be2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.0.4] - 2025-06-09 + +- Fixed non-multichannel sessions bugging out after adding multichannel support + + ## [4.0.3] - 2025-06-06 - Fixed microphone transcription tests not working after adding multichan dz support diff --git a/VERSION b/VERSION index aa31e71..7d666cb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.3 \ No newline at end of file +4.0.4 \ No newline at end of file diff --git a/speechmatics/cli.py b/speechmatics/cli.py index e34d4a1..77e2205 100755 --- a/speechmatics/cli.py +++ b/speechmatics/cli.py @@ -810,21 +810,19 @@ def rt_main(args): def run(stream=None, channel_stream_pairs=None): try: - # Pass in either stream or channel_stream_pairs depending on what != None - # Dynamically construct the args based on the input - args_list = [transcription_config] + stream_or_channel_stream_pairs = None if stream is not None: - args_list.append(stream) + stream_or_channel_stream_pairs = stream elif channel_stream_pairs is not None: - args_list.append(None) # This skips the stream argument - args_list.append(channel_stream_pairs) + stream_or_channel_stream_pairs = channel_stream_pairs else: raise SystemExit( "Neither stream nor channel_stream_pairs were provided." ) api.run_synchronously( - *args_list, - audio_settings=get_audio_settings(args), + stream_or_channel_stream_pairs, + transcription_config, + get_audio_settings(args), from_cli=True, extra_headers=extra_headers, ) diff --git a/speechmatics/client.py b/speechmatics/client.py index 93e3eaa..f9d2999 100644 --- a/speechmatics/client.py +++ b/speechmatics/client.py @@ -9,6 +9,7 @@ from collections import defaultdict from contextlib import AsyncExitStack import copy +from io import IOBase import json import logging import os @@ -521,9 +522,8 @@ async def _communicate(self, stream, audio_settings): async def run( self, + stream: Union[IOBase, dict], transcription_config: TranscriptionConfig, - stream: Optional[Any] = None, - channel_stream_pairs=None, audio_settings: AudioSettings = None, from_cli: bool = False, extra_headers: Dict = None, @@ -552,7 +552,14 @@ async def run( :raises Exception: Can raise any exception returned by the consumer/producer tasks. """ - if channel_stream_pairs: + # Check we get either a dict or a file-like object + channel_stream_pairs = None + if isinstance(stream, dict): + # Case where stream is channel stream pairs + channel_stream_pairs = stream + + # Set channel_stream pairs if provided + if channel_stream_pairs is not None: opened_streams = {} self._stream_exits = AsyncExitStack() for channel_name, path in channel_stream_pairs.items(): @@ -564,6 +571,7 @@ async def run( self.channel_stream_pairs = opened_streams else: self.channel_stream_pairs = None + self.transcription_config = transcription_config self._language_pack_info = None await self._init_synchronization_primitives() From cfdef28f29f976b43504fde32921ed4b8aa84640 Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 9 Jun 2025 15:53:52 +0100 Subject: [PATCH 2/4] simplify run method --- speechmatics/cli.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/speechmatics/cli.py b/speechmatics/cli.py index 77e2205..bbdaac4 100755 --- a/speechmatics/cli.py +++ b/speechmatics/cli.py @@ -808,19 +808,10 @@ def rt_main(args): translation_config=transcription_config.translation_config, ) - def run(stream=None, channel_stream_pairs=None): + def run(stream): try: - stream_or_channel_stream_pairs = None - if stream is not None: - stream_or_channel_stream_pairs = stream - elif channel_stream_pairs is not None: - stream_or_channel_stream_pairs = channel_stream_pairs - else: - raise SystemExit( - "Neither stream nor channel_stream_pairs were provided." - ) api.run_synchronously( - stream_or_channel_stream_pairs, + stream, transcription_config, get_audio_settings(args), from_cli=True, @@ -858,7 +849,7 @@ def run(stream=None, channel_stream_pairs=None): # Here the order matters, as stream positions and diarization labels correspond to one another. channel_name = transcription_config.channel_diarization_labels[i] channel_stream_pairs[channel_name] = args["files"][i] - run(channel_stream_pairs=channel_stream_pairs) + run(stream=channel_stream_pairs) else: for filename in args["files"]: From f7e5adb13f698f6406897ac83d98560480acd310 Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 9 Jun 2025 15:55:45 +0100 Subject: [PATCH 3/4] Add proper type hinting for stream --- speechmatics/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speechmatics/client.py b/speechmatics/client.py index f9d2999..6007458 100644 --- a/speechmatics/client.py +++ b/speechmatics/client.py @@ -522,7 +522,7 @@ async def _communicate(self, stream, audio_settings): async def run( self, - stream: Union[IOBase, dict], + stream: Union[IOBase, Dict[str, IOBase]], transcription_config: TranscriptionConfig, audio_settings: AudioSettings = None, from_cli: bool = False, From cc877fdd1a71d6174d0b89f88c5d26262ec67a4f Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 9 Jun 2025 16:17:54 +0100 Subject: [PATCH 4/4] Fix docstring. --- speechmatics/client.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/speechmatics/client.py b/speechmatics/client.py index 6007458..61a2554 100644 --- a/speechmatics/client.py +++ b/speechmatics/client.py @@ -537,11 +537,8 @@ async def run( :param transcription_config: Configuration for the transcription. :type transcription_config: speechmatics.models.TranscriptionConfig - :param stream: Optional file-like object which an audio stream can be read from. - :type stream: io.IOBase - - :param channel_stream_pairs: Optional dict containing channel-name stream pairs. - :type channel_stream_pairs dict[str, io.IOBase] + :param stream: Optional file-like object or Dict of file-likes which an audio stream can be read from. + :type stream: Union[IOBase, Dict[str, IOBase]], :param audio_settings: Configuration for the audio stream. :type audio_settings: speechmatics.models.AudioSettings