Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
|