mehdi364 commited on
Commit
2b4320d
·
verified ·
1 Parent(s): 0b41553

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -1,19 +1,12 @@
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()
 
1
  import gradio as gr
2
+ import torchaudio
3
 
4
+ def transcribe(audio):
5
+ recognizer = sr.Recognizer()
6
+ with sr.AudioFile(audio) as source:
7
+ audio_data = recognizer.record(source)
8
+ text = recognizer.recognize_google(audio_data, language="fa-IR")
9
+ return text
10
 
11
+ interface = gr.Interface(fn=transcribe, inputs="microphone", outputs="text")
12
+ interface.launch()