Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,34 +10,35 @@ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = '/'.join(rutas)
|
|
10 |
|
11 |
def transcribe(file_name):
|
12 |
"""Transcribe audio bytes to text using Google Cloud Speech to Text."""
|
13 |
-
if
|
14 |
-
|
15 |
-
client = speech.SpeechClient()
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
content = audio_file.read()
|
28 |
-
audio = speech.RecognitionAudio(content=content)
|
29 |
-
|
30 |
-
# Realiza la transcripción
|
31 |
-
response = client.recognize(request={"config": config, "audio": audio})
|
32 |
-
|
33 |
-
transcript = []
|
34 |
-
# Reads the response
|
35 |
-
for result in response.results:
|
36 |
-
print("Transcript: {}".format(result.alternatives[0].transcript))
|
37 |
-
transcript.append(result.alternatives[0].transcript)
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
demo = gr.Interface(
|
|
|
10 |
|
11 |
def transcribe(file_name):
|
12 |
"""Transcribe audio bytes to text using Google Cloud Speech to Text."""
|
13 |
+
if file_name is None:
|
14 |
+
return ''
|
|
|
15 |
|
16 |
+
# Crea un cliente de Speech to Text
|
17 |
+
client = speech.SpeechClient()
|
18 |
+
|
19 |
+
# Configura la configuración de la solicitud
|
20 |
+
config = speech.RecognitionConfig(
|
21 |
+
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
|
22 |
+
enable_automatic_punctuation=True,
|
23 |
+
audio_channel_count=1,
|
24 |
+
language_code="es-AR",
|
25 |
+
)
|
26 |
+
|
27 |
+
# Crea una solicitud de reconocimiento de audio
|
28 |
+
with io.open(file_name, "rb") as audio_file:
|
29 |
+
content = audio_file.read()
|
30 |
+
audio = speech.RecognitionAudio(content=content)
|
31 |
|
32 |
+
# Realiza la transcripción
|
33 |
+
response = client.recognize(request={"config": config, "audio": audio})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
transcript = []
|
36 |
+
# Reads the response
|
37 |
+
for result in response.results:
|
38 |
+
print("Transcript: {}".format(result.alternatives[0].transcript))
|
39 |
+
transcript.append(result.alternatives[0].transcript)
|
40 |
+
|
41 |
+
return ' '.join(transcript)
|
42 |
|
43 |
|
44 |
demo = gr.Interface(
|