Spaces:
Runtime error
Runtime error
File size: 1,005 Bytes
81b8cf7 06d806f 81b8cf7 788669e 81b8cf7 7b5145c 81b8cf7 788669e 81b8cf7 788669e 880c111 06d806f 81b8cf7 788669e 7c90d11 ce0e38c 06d806f 788669e 7c90d11 06d806f 788669e 81b8cf7 |
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 30 31 32 33 34 35 36 37 38 39 40 |
import os
import gradio as gr
from transformers import pipeline
title = "Speech to text for German"
pipeline = pipeline(task="automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-german")
#pipeline = pipeline(task="automatic-speech-recognition", model="openai/whisper-large")
def transcribeFile(audio_path : str) -> str:
transcription = pipeline(audio_path)
return transcription["text"]
def transcribeMic(audio):
sr, data = audio
transcription = pipeline(data)
return transcription["text"]
app1 = gr.Interface(
fn=transcribeFile,
inputs=[gr.inputs.Audio(label="Upload audio file", type="filepath"), gr.Audio(source="microphone", type="filepath")],
outputs="text",
title=title
)
app2 = gr.Interface(
fn=transcribeFile,
inputs=gr.Audio(source="microphone", type="filepath"),
outputs="text",
title=title
)
demo = gr.TabbedInterface([app1, app2], ["Audio File", "Microphone"])
if __name__ == "__main__":
demo.launch()
|