From a2271806c39a3ad8631d7acd0879ad03afdb6d05 Mon Sep 17 00:00:00 2001 From: giubots Date: Mon, 28 Apr 2025 17:21:33 +0200 Subject: [PATCH] feat: client sends new parameters to server --- whisper_live/client.py | 41 ++++++++++++++++++++++++++++++++++++++--- whisper_live/server.py | 12 ++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/whisper_live/client.py b/whisper_live/client.py index 4fc9281..24de1a0 100644 --- a/whisper_live/client.py +++ b/whisper_live/client.py @@ -33,6 +33,10 @@ class Client: log_transcription=True, max_clients=4, max_connection_time=600, + send_last_n_segments=10, + no_speech_thresh=0.45, + clip_audio=False, + same_output_threshold=10, ): """ Initializes a Client instance for audio recording and streaming to a server. @@ -52,6 +56,10 @@ class Client: log_transcription (bool, optional): Whether to log transcription output to the console. Default is True. max_clients (int, optional): Maximum number of client connections allowed. Default is 4. max_connection_time (int, optional): Maximum allowed connection time in seconds. Default is 600. + send_last_n_segments (int, optional): Number of most recent segments to send to the client. Defaults to 10. + no_speech_thresh (float, optional): Segments with no speech probability above this threshold will be discarded. Defaults to 0.45. + clip_audio (bool, optional): Whether to clip audio with no valid segments. Defaults to False. + same_output_threshold (int, optional): Number of repeated outputs before considering it as a valid segment. Defaults to 10. """ self.recording = False self.task = "transcribe" @@ -69,6 +77,10 @@ class Client: self.log_transcription = log_transcription self.max_clients = max_clients self.max_connection_time = max_connection_time + self.send_last_n_segments = send_last_n_segments + self.no_speech_thresh = no_speech_thresh + self.clip_audio = clip_audio + self.same_output_threshold = same_output_threshold if translate: self.task = "translate" @@ -212,6 +224,10 @@ class Client: "use_vad": self.use_vad, "max_clients": self.max_clients, "max_connection_time": self.max_connection_time, + "send_last_n_segments": self.send_last_n_segments, + "no_speech_thresh": self.no_speech_thresh, + "clip_audio": self.clip_audio, + "same_output_threshold": self.same_output_threshold, } ) ) @@ -682,6 +698,10 @@ class TranscriptionClient(TranscriptionTeeClient): max_clients (int, optional): Maximum number of client connections allowed. Default is 4. max_connection_time (int, optional): Maximum allowed connection time in seconds. Default is 600. mute_audio_playback (bool, optional): If True, mutes audio playback during file playback. Default is False. + send_last_n_segments (int, optional): Number of most recent segments to send to the client. Defaults to 10. + no_speech_thresh (float, optional): Segments with no speech probability above this threshold will be discarded. Defaults to 0.45. + clip_audio (bool, optional): Whether to clip audio with no valid segments. Defaults to False. + same_output_threshold (int, optional): Number of repeated outputs before considering it as a valid segment. Defaults to 10. Attributes: client (Client): An instance of the underlying Client class responsible for handling the WebSocket connection. @@ -708,11 +728,26 @@ class TranscriptionClient(TranscriptionTeeClient): max_clients=4, max_connection_time=600, mute_audio_playback=False, + send_last_n_segments=10, + no_speech_thresh=0.45, + clip_audio=False, + same_output_threshold=10, ): self.client = Client( - host, port, lang, translate, model, srt_file_path=output_transcription_path, - use_vad=use_vad, log_transcription=log_transcription, max_clients=max_clients, - max_connection_time=max_connection_time + host, + port, + lang, + translate, + model, + srt_file_path=output_transcription_path, + use_vad=use_vad, + log_transcription=log_transcription, + max_clients=max_clients, + max_connection_time=max_connection_time, + send_last_n_segments=send_last_n_segments, + no_speech_thresh=no_speech_thresh, + clip_audio=clip_audio, + same_output_threshold=same_output_threshold, ) if save_output_recording and not output_recording_filename.endswith(".wav"): diff --git a/whisper_live/server.py b/whisper_live/server.py index 5a59ff7..b89e7d1 100644 --- a/whisper_live/server.py +++ b/whisper_live/server.py @@ -168,6 +168,10 @@ class TranscriptionServer: client_uid=options["uid"], model=whisper_tensorrt_path, single_model=self.single_model, + send_last_n_segments=options.get("send_last_n_segments", 10), + no_speech_thresh=options.get("no_speech_thresh", 0.45), + clip_audio=options.get("clip_audio", False), + same_output_threshold=options.get("same_output_threshold", 10), ) logging.info("Running TensorRT backend.") except Exception as e: @@ -191,6 +195,10 @@ class TranscriptionServer: client_uid=options["uid"], model=options["model"], single_model=self.single_model, + send_last_n_segments=options.get("send_last_n_segments", 10), + no_speech_thresh=options.get("no_speech_thresh", 0.45), + clip_audio=options.get("clip_audio", False), + same_output_threshold=options.get("same_output_threshold", 10), ) logging.info("Running OpenVINO backend.") except Exception as e: @@ -220,6 +228,10 @@ class TranscriptionServer: vad_parameters=options.get("vad_parameters"), use_vad=self.use_vad, single_model=self.single_model, + send_last_n_segments=options.get("send_last_n_segments", 10), + no_speech_thresh=options.get("no_speech_thresh", 0.45), + clip_audio=options.get("clip_audio", False), + same_output_threshold=options.get("same_output_threshold", 10), ) logging.info("Running faster_whisper backend.")