anzorq commited on
Commit
9ff6d33
·
verified ·
1 Parent(s): d22f729

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -34,9 +34,9 @@ def transcribe_speech(audio):
34
  return replace_symbols_back(transcription)
35
 
36
  @spaces.GPU
37
- def transcribe_streaming(stream, new_chunk):
38
  if new_chunk is None: # Handle the NoneType error for microphone input
39
- return "No audio received.", ""
40
 
41
  sampling_rate, audio_data = new_chunk
42
  audio_data = audio_data.astype(np.float32)
@@ -51,9 +51,10 @@ def transcribe_streaming(stream, new_chunk):
51
  else:
52
  stream = audio_data
53
 
54
- transcription = pipe({"sampling_rate": sampling_rate, "raw": stream})['text']
 
55
 
56
- return stream, replace_symbols_back(transcription)
57
 
58
  def transcribe_from_youtube(url, progress=gr.Progress()):
59
  progress(0, "Downloading YouTube audio...")
@@ -88,7 +89,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
88
  mic_audio = gr.Audio(sources='microphone', streaming=True)
89
  transcription_output = gr.Textbox(label="Transcription", lines=10)
90
 
91
- mic_audio.stream(fn=transcribe_streaming, inputs=[gr.State(), mic_audio], outputs=[gr.State(), transcription_output])
92
 
93
  with gr.Tab("File Upload"):
94
  gr.Markdown("## Transcribe speech from uploaded file")
 
34
  return replace_symbols_back(transcription)
35
 
36
  @spaces.GPU
37
+ def transcribe_streaming(stream, transcription, new_chunk):
38
  if new_chunk is None: # Handle the NoneType error for microphone input
39
+ return stream, transcription
40
 
41
  sampling_rate, audio_data = new_chunk
42
  audio_data = audio_data.astype(np.float32)
 
51
  else:
52
  stream = audio_data
53
 
54
+ new_transcription = pipe({"sampling_rate": sampling_rate, "raw": stream})['text']
55
+ transcription += " " + replace_symbols_back(new_transcription)
56
 
57
+ return stream, transcription
58
 
59
  def transcribe_from_youtube(url, progress=gr.Progress()):
60
  progress(0, "Downloading YouTube audio...")
 
89
  mic_audio = gr.Audio(sources='microphone', streaming=True)
90
  transcription_output = gr.Textbox(label="Transcription", lines=10)
91
 
92
+ mic_audio.stream(fn=transcribe_streaming, inputs=[gr.State(), gr.State(""), mic_audio], outputs=[gr.State(), transcription_output])
93
 
94
  with gr.Tab("File Upload"):
95
  gr.Markdown("## Transcribe speech from uploaded file")