fcernafukuzaki commited on
Commit
4de176d
·
verified ·
1 Parent(s): 3816bd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
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 not file_name:
14
- # Crea un cliente de Speech to Text
15
- client = speech.SpeechClient()
16
 
17
- # Configura la configuración de la solicitud
18
- config = speech.RecognitionConfig(
19
- encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
20
- enable_automatic_punctuation=True,
21
- audio_channel_count=1,
22
- language_code="es-AR",
23
- )
 
 
 
 
 
 
 
 
24
 
25
- # Crea una solicitud de reconocimiento de audio
26
- with io.open(file_name, "rb") as audio_file:
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
- return ' '.join(transcript)
40
- return ''
 
 
 
 
 
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(