From ddd32cc30f0937680a104140c7fc4666c6f1c752 Mon Sep 17 00:00:00 2001 From: Kiran Lonikar Date: Mon, 7 Jul 2025 13:24:13 +0530 Subject: [PATCH] adding test client to transcribe audio files --- run_client.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 run_client.py diff --git a/run_client.py b/run_client.py new file mode 100644 index 0000000..fde26e6 --- /dev/null +++ b/run_client.py @@ -0,0 +1,57 @@ +from pathlib import Path +import sys +from whisper_live.client import TranscriptionClient +import argparse + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--port', '-p', + type=int, + default=9090, + help="Websocket port to run the server on.") + parser.add_argument('--server', '-s', + type=str, + default='localhost', + help='hostname or ip address of server') + parser.add_argument('--files', '-f', + type=str, + nargs='+', + help='hostname or ip address of server') + parser.add_argument('--output_file', '-o', + type=str, + default='./output_recording.wav', + help='hostname or ip address of server') + args = parser.parse_args() + + # Validate audio files + valid_files = [] + for file_path in args.files: + path = Path(file_path) + if path.exists() and path.is_file(): + valid_files.append(str(path)) + else: + print(f"Warning: File not found: {file_path}") + + if not valid_files: + print("Error: No valid audio files found!") + sys.exit(1) + + print(f"Found {len(valid_files)} audio file(s) to stream:") + for file_path in valid_files: + print(f" - {file_path}") + + for f in valid_files: + client = TranscriptionClient( + args.server, + args.port, + lang="en", + translate=False, + model="large-v3", # also support hf_model => `Systran/faster-whisper-small` + use_vad=False, + save_output_recording=False, # Only used for microphone input, False by Default + output_recording_filename=args.output_file, # Only used for microphone input + max_clients=4, + max_connection_time=600, + mute_audio_playback=True, # Only used for file input, False by Default + ) + client(f)