Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Load a fast automatic speech recognition pipeline
|
8 |
+
asr_pipeline = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
|
9 |
+
|
10 |
+
def transcribe_audio(audio):
|
11 |
+
if audio is None:
|
12 |
+
return "No audio input"
|
13 |
+
|
14 |
+
text = asr_pipeline(audio)["text"]
|
15 |
+
return text
|
16 |
+
|
17 |
+
# Gradio Interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=transcribe_audio,
|
20 |
+
inputs=gr.Audio(sources=["microphone"], type="filepath"),
|
21 |
+
outputs=gr.Textbox(label="Recognized Text"),
|
22 |
+
live=True,
|
23 |
+
title="Real-time Voice to Text (Fast Version)",
|
24 |
+
description="Speak into your microphone and get instant transcription!",
|
25 |
+
)
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
iface.launch()
|