Spaces:
Sleeping
Sleeping
import gradio as gr | |
import logging | |
from transformers import pipeline | |
import torch | |
description = "Simple Speech Recognition App" | |
title = "This app allows users to record audio through the microphone or upload audio files to be transcribed into text. It uses the speech_recognition library to process audio and extract spoken words. Ideal for quick transcription of short speeches and audio notes." | |
asr = pipeline(task="automatic-speech-recognition", | |
model="distil-whisper/distil-small.en") | |
# Adjusted function assuming 'asr' expects a file path as input | |
def transcribe_speech(audio_file_path): | |
if not audio_file_path: | |
logging.error("No audio file provided.") | |
return "No audio found, please retry." | |
try: | |
logging.info(f"Processing file: {audio_file_path}") | |
output = asr(audio_file_path) # Assuming `asr` directly takes a file path | |
return output["text"] | |
except Exception as e: | |
logging.error(f"Error during transcription: {str(e)}") | |
return f"Error processing the audio file: {str(e)}" | |
logging.basicConfig(level=logging.INFO) | |
css = """ | |
button { | |
background-color: blue !important; | |
color: white !important; | |
} | |
""" | |
with gr.Blocks(css=css) as demo: | |
with gr.Row(): | |
gr.Markdown("# Simple Speech Recognition App") | |
with gr.Row(): | |
gr.Markdown("### This app allows you to record or upload audio and see its transcription. Powered by the speech_recognition library.") | |
with gr.Row(): | |
mic = gr.Audio(label="Record from Microphone or Upload File", type="filepath") | |
transcribe_button = gr.Button("Transcribe Audio") | |
with gr.Row(): | |
transcription = gr.Textbox(label="Transcription", lines=3, placeholder="Transcription will appear here...") | |
transcribe_button.click(transcribe_speech, inputs=mic, outputs=transcription) | |
demo.launch(share=True) | |