Spaces:
Runtime error
Runtime error
ktangri
commited on
Commit
·
a263f35
1
Parent(s):
a893c73
Add speech transcription
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from librosa import load, resample
|
4 |
+
|
5 |
+
|
6 |
+
asr_model = 'facebook/wav2vec2-base-960h'
|
7 |
+
|
8 |
+
asr = pipeline('automatic-speech-recognition', model=asr_model, feature_extractor=asr_model)
|
9 |
+
|
10 |
+
def transcribe(filepath):
|
11 |
+
speech, sampling_rate = load(filepath)
|
12 |
+
if sampling_rate != 16000:
|
13 |
+
speech = resample(speech, sampling_rate, 16000)
|
14 |
+
text = asr(speech)['text']
|
15 |
+
return text
|
16 |
+
|
17 |
+
mic = gr.inputs.Audio(source='microphone', type='filepath', label='Speech input', optional=False)
|
18 |
+
|
19 |
+
transcript = gr.outputs.Textbox(type='auto', label='Transcription')
|
20 |
+
|
21 |
+
iface = gr.Interface(
|
22 |
+
theme='huggingface',
|
23 |
+
description='Testing transcription',
|
24 |
+
fn=transcribe,
|
25 |
+
inputs=[mic],
|
26 |
+
outputs=[transcript]
|
27 |
+
)
|
28 |
+
iface.launch()
|