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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -19
app.py CHANGED
@@ -1,27 +1,19 @@
 
1
  from transformers import pipeline
2
 
3
- def transcribe_with_whisper():
4
- temp_dir = tempfile.gettempdir()
5
- if not os.access(temp_dir, os.W_OK):
6
- raise PermissionError("No write access to the temporary directory.")
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=transcribe_with_whisper,
20
- inputs=[],
21
  outputs="text",
22
- title="تبدیل گفتار به نوشتار با Whisper - فقط فارسی",
23
- description="برای شروع ضبط صدا، روی دکمه زیر کلیک کنید و سپس صحبت کنید."
 
24
  )
25
 
26
  if __name__ == "__main__":
27
- interface.launch(server_name="0.0.0.0", server_port=7860)
 
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()