fcernafukuzaki commited on
Commit
086ae79
·
verified ·
1 Parent(s): 98983cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,28 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
  import numpy as np
4
- #from google.cloud import speech_v1
5
- #from google.protobuf import timestamp_pb2
6
 
7
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
8
 
9
- def transcribe(stream, audio_bytes):
10
  """Transcribe audio bytes to text using Google Cloud Speech to Text."""
11
 
12
  sr, y = audio_bytes
13
  y = y.astype(np.float32)
14
  y /= np.max(np.abs(y))
15
- if stream is not None:
16
- stream = np.concatenate([stream, y])
17
- else:
18
- stream = y
19
- return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
20
 
21
 
22
  demo = gr.Interface(
23
  transcribe,
24
- ["state", gr.Audio(sources=["microphone"], streaming=False)],
25
- ["state", "text"],
26
  live=True,
27
  )
28
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  import numpy as np
4
+ from google.cloud import speech_v1
5
+ from google.protobuf import timestamp_pb2
6
 
7
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
8
 
9
+ def transcribe(audio_bytes):
10
  """Transcribe audio bytes to text using Google Cloud Speech to Text."""
11
 
12
  sr, y = audio_bytes
13
  y = y.astype(np.float32)
14
  y /= np.max(np.abs(y))
15
+
16
+ return transcriber({"sampling_rate": sr, "raw": y})["text"]
 
 
 
17
 
18
 
19
  demo = gr.Interface(
20
  transcribe,
21
+ gr.Audio(sources=["microphone"], streaming=False),
22
+ "text",
23
  live=True,
24
  )
25