Using ffmpeg-python package instead of requiring having ffmpeg installed in system
This commit is contained in:
@@ -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
|
||||
|
||||
+8
-13
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user