Spaces:
Sleeping
Sleeping
File size: 1,879 Bytes
7400283 9854ee3 a4e347a a8a6273 a4e347a a7370d6 148cae6 a4e347a ccee400 9854ee3 7400283 9854ee3 ccee400 9854ee3 7400283 ee2727c 72823aa cea3a6b 4f455f6 72823aa ee2727c 72823aa 4d6774a 7400283 |
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 41 42 43 44 45 46 47 48 |
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)
|