Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
audio_path = os.path.join(temp_dir, "temp_audio.wav")
|
| 9 |
-
|
| 10 |
-
subprocess.run([
|
| 11 |
-
"ffmpeg", "-f", "alsa", "-i", "default", "-t", "5", "-ar", "16000", "-ac", "1", audio_path
|
| 12 |
-
], check=True)
|
| 13 |
-
|
| 14 |
-
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
|
| 15 |
-
result = transcriber(audio_path)
|
| 16 |
-
return result["text"]
|
| 17 |
|
| 18 |
interface = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
-
inputs=
|
| 21 |
outputs="text",
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
-
interface.launch(
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
def transcribe_audio(audio):
|
| 5 |
+
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 6 |
+
result = transcriber(audio)
|
| 7 |
+
return result['text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
interface = gr.Interface(
|
| 10 |
+
fn=transcribe_audio,
|
| 11 |
+
inputs=gr.Audio(source="microphone", type="filepath", label="Input Audio"),
|
| 12 |
outputs="text",
|
| 13 |
+
live=True,
|
| 14 |
+
title="Speech to Text - Persian",
|
| 15 |
+
description="Record your voice in Persian and see the transcription here."
|
| 16 |
)
|
| 17 |
|
| 18 |
if __name__ == "__main__":
|
| 19 |
+
interface.launch()
|