From 8e8553d2bd21f338e8d2e60c6d70a8f883027231 Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 6 Jun 2025 16:50:36 +0100 Subject: [PATCH 1/3] change run synch to use explicit args --- .../youtube_transcribe.py | 6 +++- speechmatics/cli.py | 14 +++----- speechmatics/client.py | 33 +++++++++++++++++-- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/examples/transcribe_from_youtube/youtube_transcribe.py b/examples/transcribe_from_youtube/youtube_transcribe.py index 4024e81..9af57c3 100644 --- a/examples/transcribe_from_youtube/youtube_transcribe.py +++ b/examples/transcribe_from_youtube/youtube_transcribe.py @@ -52,7 +52,11 @@ def main(args): def run(stream): try: - api.run_synchronously(stream, transcription_config, AudioSettings()) + api.run_synchronously( + stream=stream, + transcription_config=transcription_config, + audio_settings=AudioSettings(), + ) except KeyboardInterrupt: # Gracefully handle Ctrl-C, else we get a huge stack-trace. LOGGER.warning("Keyboard interrupt received.") diff --git a/speechmatics/cli.py b/speechmatics/cli.py index e34d4a1..51b77d5 100755 --- a/speechmatics/cli.py +++ b/speechmatics/cli.py @@ -810,20 +810,14 @@ 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] - if stream is not None: - args_list.append(stream) - elif channel_stream_pairs is not None: - args_list.append(None) # This skips the stream argument - args_list.append(channel_stream_pairs) - else: + if stream is None and channel_stream_pairs is None: raise SystemExit( "Neither stream nor channel_stream_pairs were provided." ) api.run_synchronously( - *args_list, + transcription_config=transcription_config, + stream=stream, + channel_stream_pairs=channel_stream_pairs, audio_settings=get_audio_settings(args), from_cli=True, extra_headers=extra_headers, diff --git a/speechmatics/client.py b/speechmatics/client.py index 93e3eaa..915a5f3 100644 --- a/speechmatics/client.py +++ b/speechmatics/client.py @@ -553,6 +553,10 @@ async def run( consumer/producer tasks. """ if channel_stream_pairs: + if not isinstance(channel_stream_pairs, dict): + raise TypeError( + "channel_stream_pairs must be a dict of {str: file-like or path}" + ) opened_streams = {} self._stream_exits = AsyncExitStack() for channel_name, path in channel_stream_pairs.items(): @@ -569,6 +573,9 @@ async def run( await self._init_synchronization_primitives() if extra_headers is None: extra_headers = {} + else: + if not isinstance(extra_headers, dict): + raise TypeError("extra_headers must be a dict") if audio_settings is None: audio_settings = AudioSettings() if ( @@ -632,13 +639,35 @@ def stop(self): """ self._session_needs_closing = True - def run_synchronously(self, *args, timeout=None, **kwargs): + def run_synchronously( + self, + transcription_config: TranscriptionConfig, + *, + stream: Optional[Any] = None, + channel_stream_pairs: Optional[Dict[str, Any]] = None, + audio_settings: Optional[AudioSettings] = None, + from_cli: bool = False, + extra_headers: Optional[Dict] = None, + timeout=None, + ): """ Run the transcription synchronously. :raises asyncio.TimeoutError: If the given timeout is exceeded. """ # pylint: disable=no-value-for-parameter - asyncio.run(asyncio.wait_for(self.run(*args, **kwargs), timeout=timeout)) + asyncio.run( + asyncio.wait_for( + self.run( + transcription_config=transcription_config, + stream=stream, + channel_stream_pairs=channel_stream_pairs, + audio_settings=audio_settings, + from_cli=from_cli, + extra_headers=extra_headers, + ), + timeout=timeout, + ) + ) async def send_message(self, message_type: str, data: Optional[Any] = None): """ From bf28e5bf50a5f3b0f0b2ce7c8e92b7ee9b85e127 Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 6 Jun 2025 17:17:49 +0100 Subject: [PATCH 2/3] change version and changelog --- CHANGELOG.md | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2292a0f..d5e76e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [4.0.3] - 2025-06-06 +- Changing async run wrapper to use explicit arguments to fix multichannel tests in aladdin + +## [4.0.3] - 2025-06-06 + - Fixed microphone transcription tests not working after adding multichan dz support ## [4.0.2] - 2025-06-04 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 From a5f93afac40d10bb9cf73d5577cc7c31c6a19178 Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 6 Jun 2025 17:40:17 +0100 Subject: [PATCH 3/3] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5e76e8..7c7baaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ 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.3] - 2025-06-06 +## [4.0.4] - 2025-06-06 - Changing async run wrapper to use explicit arguments to fix multichannel tests in aladdin