CoolFace
Apppublic

Manutorresdev96/speech2text_app

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py34 linesDownload Raw Back to root
1import torch2from transformers import pipeline3import gradio as gr4import torch5import gradio as gr6 7def transcript_audio(audio_file):8    # Initialize the speech recognition pipeline9    pipe = pipeline(10        "automatic-speech-recognition",11        model="openai/whisper-small",12        chunk_length_s=30,13        device=0 if torch.cuda.is_available() else -1,14    )15 16    # Transcribe the audio file and return the result17    result = pipe(audio_file, batch_size=8)["text"]18 19    return result20 21 22# Set up Gradio interface23audio_input = gr.Audio(sources="upload", type="filepath")  # Audio input24output_text = gr.Textbox()  # Text output25 26# Create the Gradio interface with the function, inputs, and outputs27iface = gr.Interface(fn=transcript_audio,28                     inputs=audio_input, outputs=output_text,29                     title="Audio Transcription App",30                     description="Upload the audio file")31 32# Launch the Gradio app33iface.launch()34