File size: 734 Bytes
a263f35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
from transformers import pipeline
from librosa import load, resample


asr_model = 'facebook/wav2vec2-base-960h'

asr = pipeline('automatic-speech-recognition', model=asr_model, feature_extractor=asr_model)

def transcribe(filepath):
	speech, sampling_rate = load(filepath)
	if sampling_rate != 16000:
		speech = resample(speech, sampling_rate, 16000)
	text = asr(speech)['text']
	return text

mic = gr.inputs.Audio(source='microphone', type='filepath', label='Speech input', optional=False)

transcript = gr.outputs.Textbox(type='auto', label='Transcription')

iface = gr.Interface(
	theme='huggingface',
	description='Testing transcription',
	fn=transcribe,
	inputs=[mic],
	outputs=[transcript]
)
iface.launch()