Commit
•
42dbc3a
1
Parent(s):
b522f73
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import logging
|
3 |
+
from transformers import pipeline
|
4 |
+
import torch
|
5 |
+
|
6 |
+
description = "Simple Speech Recognition App"
|
7 |
+
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."
|
8 |
+
|
9 |
+
asr = pipeline(task="automatic-speech-recognition",
|
10 |
+
model="distil-whisper/distil-small.en")
|
11 |
+
|
12 |
+
# Adjusted function assuming 'asr' expects a file path as input
|
13 |
+
def transcribe_speech(audio_file_path):
|
14 |
+
if not audio_file_path:
|
15 |
+
logging.error("No audio file provided.")
|
16 |
+
return "No audio found, please retry."
|
17 |
+
try:
|
18 |
+
logging.info(f"Processing file: {audio_file_path}")
|
19 |
+
output = asr(audio_file_path) # Assuming `asr` directly takes a file path
|
20 |
+
return output["text"]
|
21 |
+
except Exception as e:
|
22 |
+
logging.error(f"Error during transcription: {str(e)}")
|
23 |
+
return f"Error processing the audio file: {str(e)}"
|
24 |
+
|
25 |
+
logging.basicConfig(level=logging.INFO)
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
with gr.Row():
|
29 |
+
gr.Markdown("# Simple Speech Recognition App")
|
30 |
+
with gr.Row():
|
31 |
+
gr.Markdown("### This app allows you to record or upload audio and see its transcription. Powered by the speech_recognition library.")
|
32 |
+
with gr.Row():
|
33 |
+
mic = gr.Audio(label="Record from Microphone or Upload File", type="filepath")
|
34 |
+
transcribe_button = gr.Button("Transcribe Audio")
|
35 |
+
with gr.Row():
|
36 |
+
transcription = gr.Textbox(label="Transcription", lines=3, placeholder="Transcription will appear here...")
|
37 |
+
|
38 |
+
transcribe_button.click(transcribe_speech, inputs=mic, outputs=transcription)
|
39 |
+
|
40 |
+
demo.launch(share=True)
|