fcernafukuzaki commited on
Commit
d9607d1
·
verified ·
1 Parent(s): 9163b2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -3,7 +3,7 @@ from google.cloud import speech_v1
3
  from google.protobuf import timestamp_pb2
4
 
5
 
6
- def transcribe(audio_bytes):
7
  """Transcribe audio bytes to text using Google Cloud Speech to Text."""
8
 
9
  # Crea un cliente de Speech to Text
@@ -19,19 +19,24 @@ def transcribe(audio_bytes):
19
  audio = speech_v1.RecognitionAudio(content=audio_bytes)
20
  request = speech_v1.RecognizeSpeechRequest(config=config, audio=audio)
21
 
22
- # Realiza la transcripción
23
- response = client.recognize_speech(request)
24
-
25
- # Extrae el texto transcrito
26
- transcript = response.results[0].alternatives[0].transcript
27
-
28
- return transcript
 
 
 
 
 
29
 
30
 
31
  demo = gr.Interface(
32
  transcribe,
33
- gr.Audio(sources=["microphone"], streaming=True),
34
- "text",
35
  live=True,
36
  )
37
 
 
3
  from google.protobuf import timestamp_pb2
4
 
5
 
6
+ def transcribe(stream, audio_bytes):
7
  """Transcribe audio bytes to text using Google Cloud Speech to Text."""
8
 
9
  # Crea un cliente de Speech to Text
 
19
  audio = speech_v1.RecognitionAudio(content=audio_bytes)
20
  request = speech_v1.RecognizeSpeechRequest(config=config, audio=audio)
21
 
22
+ sr, y = audio_bytes
23
+ y = y.astype(np.float32)
24
+ y /= np.max(np.abs(y))
25
+ if stream is not None:
26
+ # Realiza la transcripción
27
+ response = client.recognize_speech(request)
28
+
29
+ # Extrae el texto transcrito
30
+ transcript = response.results[0].alternatives[0].transcript
31
+ else:
32
+ stream = y
33
+ return stream, transcript
34
 
35
 
36
  demo = gr.Interface(
37
  transcribe,
38
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
39
+ ["state", "text"],
40
  live=True,
41
  )
42