From b6dee4e46e96dbbe091601d11dec3840ceb714d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Hormigo?= Date: Sun, 10 Dec 2023 19:34:27 +0100 Subject: [PATCH] Using ffmpeg-python package instead of requiring having ffmpeg installed in system --- README.md | 6 ++++++ whisper_live/client.py | 21 ++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f1e1542..3977c47 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ Unlike traditional speech recognition systems that rely on continuous audio stre ``` This command captures audio from the microphone and sends it to the server for transcription. It uses the same options as the previous command, enabling the multilingual feature and specifying the target language and task. + - To trasncribe from a HLS stream: + ```python + client = TranscriptionClient(host, port, is_multilingual=True, lang="en", translate=False) + client(hls_url="http://domain.url/playlist.m3u8") + ``` + This command streams audio into the server from a HLS stream. It uses the same options as the previous command, enabling the multilingual feature and specifying the target language and task. ## Transcribe audio from browser - Run the server diff --git a/whisper_live/client.py b/whisper_live/client.py index 4ab30fa..070845d 100644 --- a/whisper_live/client.py +++ b/whisper_live/client.py @@ -11,7 +11,6 @@ import json import websocket import uuid import time -import subprocess def resample(file: str, sr: int = 16000): @@ -355,19 +354,14 @@ class Client: print("[INFO]: Connecting to HLS stream...") process = None # Initialize process to None - try: - # Launch an FFMPEG process to connect to the HLS stream - command = [ - 'ffmpeg', - '-i', hls_url, # Input URL - '-acodec', 'pcm_s16le', # Output codec - '-f', 's16le', # Output format - '-ac', '1', # Set audio channels to 1 (mono) - '-ar', str(self.rate), # Resample audio to the specified rate - '-' - ] - process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # Connecting to the HLS stream using ffmpeg-python + process = ( + ffmpeg + .input(hls_url, threads=0) + .output('-', format='s16le', acodec='pcm_s16le', ac=1, ar=self.rate) + .run_async(pipe_stdout=True, pipe_stderr=True) + ) # Process the stream while True: @@ -385,6 +379,7 @@ class Client: print("[INFO]: HLS stream processing finished.") + def record(self, out_file="output_recording.wav"): """ Record audio data from the input stream and save it to a WAV file.