Using ffmpeg-python package instead of requiring having ffmpeg installed in system

This commit is contained in:
Jesús Hormigo
2023-12-10 19:34:27 +01:00
parent f3cd20fbf3
commit b6dee4e46e
2 changed files with 14 additions and 13 deletions
+6
View File
@@ -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. 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 ## Transcribe audio from browser
- Run the server - Run the server
+8 -13
View File
@@ -11,7 +11,6 @@ import json
import websocket import websocket
import uuid import uuid
import time import time
import subprocess
def resample(file: str, sr: int = 16000): def resample(file: str, sr: int = 16000):
@@ -355,19 +354,14 @@ class Client:
print("[INFO]: Connecting to HLS stream...") print("[INFO]: Connecting to HLS stream...")
process = None # Initialize process to None process = None # Initialize process to None
try: try:
# Launch an FFMPEG process to connect to the HLS stream # Connecting to the HLS stream using ffmpeg-python
command = [ process = (
'ffmpeg', ffmpeg
'-i', hls_url, # Input URL .input(hls_url, threads=0)
'-acodec', 'pcm_s16le', # Output codec .output('-', format='s16le', acodec='pcm_s16le', ac=1, ar=self.rate)
'-f', 's16le', # Output format .run_async(pipe_stdout=True, pipe_stderr=True)
'-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)
# Process the stream # Process the stream
while True: while True:
@@ -385,6 +379,7 @@ class Client:
print("[INFO]: HLS stream processing finished.") print("[INFO]: HLS stream processing finished.")
def record(self, out_file="output_recording.wav"): def record(self, out_file="output_recording.wav"):
""" """
Record audio data from the input stream and save it to a WAV file. Record audio data from the input stream and save it to a WAV file.