Spaces:
Runtime error
Runtime error
# !pip install transformers | |
# !pip install -U datasets | |
# !pip install soundfile | |
# !pip install librosa | |
# !pip install gradio | |
from transformers.utils import logging | |
logging.set_verbosity_error() | |
from datasets import load_dataset | |
dataset = load_dataset("librispeech_asr", | |
split="train.clean.100", | |
streaming=True, | |
trust_remote_code=True) | |
from transformers import pipeline | |
asr = pipeline(task="automatic-speech-recognition", | |
model="distil-whisper/distil-small.en") | |
asr.feature_extractor.sampling_rate | |
import os | |
import gradio as gr | |
demo = gr.Blocks() | |
def transcribe_speech(filepath): | |
if filepath is None: | |
gr.Warning("No audio found, please retry.") | |
return "" | |
output = asr(filepath) | |
return output["text"] | |
mic_transcribe = gr.Interface(fn=transcribe_speech, inputs=gr.Audio(sources="microphone", type="filepath"), | |
outputs=gr.Textbox(label="Transcription", lines=3), allow_flagging="never") | |
file_transcribe = gr.Interface( fn=transcribe_speech,inputs=gr.Audio(sources="upload",type="filepath"), | |
outputs=gr.Textbox(label="Transcription", lines=3), allow_flagging="never", | |
) | |
with demo: | |
gr.TabbedInterface( | |
[mic_transcribe, | |
file_transcribe], | |
["Transcribe Microphone", | |
"Transcribe Audio File"], | |
) | |
demo.launch(share=True) | |