Spaces:
Running
Running
Fix audio loading script
Browse files- app.py +8 -2
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
from librosa import
|
| 4 |
|
| 5 |
def transcribe(input_audio):
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
output = pipe(speech, chunk_length_s=30, stride_length_s=5)['text']
|
| 8 |
return output
|
| 9 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from librosa import resample
|
| 4 |
|
| 5 |
def transcribe(input_audio):
|
| 6 |
+
sr, speech = input_audio
|
| 7 |
+
# Convert to mono if stereo
|
| 8 |
+
if speech.ndim > 1:
|
| 9 |
+
speech = speech.mean(axis=1)
|
| 10 |
+
# Resample if sampling rate is not 16kHz
|
| 11 |
+
if sr!=16000:
|
| 12 |
+
speech = librosa.resample(speech, orig_sr=sr, target_sr=16000)
|
| 13 |
output = pipe(speech, chunk_length_s=30, stride_length_s=5)['text']
|
| 14 |
return output
|
| 15 |
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
transformers
|
| 2 |
torch
|
| 3 |
-
librosa
|
|
|
|
|
|
|
|
|
| 1 |
transformers
|
| 2 |
torch
|
| 3 |
+
librosa
|
| 4 |
+
samplerate
|
| 5 |
+
resampy
|