SandraCLV commited on
Commit
76f44e6
·
1 Parent(s): 6f3c59e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -37
app.py CHANGED
@@ -1,43 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- from gtts import gTTS
4
- import IPython.display as ipd
5
 
6
- #Definir 2 modelos uno de imagen a texto y otro de texto a audio que inyecta
7
- # el resultado del primero modelo(texto generado) en la entrada del 2º modelo
8
- # texto to audio
9
 
10
-
11
- # Cargar el modelo que convierte imagen a texto
12
- image_to_text_model = pipeline("image-classification")
13
- text_to_audio_model = pipeline("text-to-speech")
14
 
15
- def image_to_texto(input_image):
16
- # Convertir la imagen a texto
17
- text_output = image_to_text_model(input_image)[0]['label']
18
- print('text_output is :'+text_output)
19
-
20
- return text_output
21
-
22
- # Función para la interfaz de Gradio
23
- def image_to_audio(input_image):
24
- # Convertir la imagen a texto
25
- text_output = image_to_texto(input_image)[0]['label']
26
- print('text_output is :'+text_output)
27
- # Generar audio a partir del texto
28
- audio_output = text_to_audio_model(text_output)[0]['audio']
29
- print('audio_output is :'+audio_output)
30
- return audio_output
31
-
32
- # Interfaz Gradio
33
- iface = gr.Interface(
34
- fn=image_to_audio,
35
- inputs=gr.Image(type='pil'),
36
- outputs=[gr.Textbox(), gr.Audio()],
37
- live=True,
38
- interpretation="default",
39
- capture_session=True
40
- )
41
 
42
- # Ejecutar la interfaz
43
- iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import speech_recognition as sr
 
4
 
5
+ def transcribe_speech():
6
+ r = sr.Recognizer()
 
7
 
8
+ # Record Audio
9
+ with sr.Microphone() as source:
10
+ print("Habla ahora:")
11
+ audio = r.listen(source)
12
 
13
+ # Speech recognition using Google Speech Recognition
14
+ try:
15
+ text = r.recognize_google(audio, language='es-ES')
16
+ print("Creo que dijiste: " + text)
17
+ except sr.UnknownValueError:
18
+ print("Google Speech Recognition no pudo entender el audio")
19
+ except sr.RequestError as e:
20
+ print("No se pudo solicitar resultados del servicio de Google Speech Recognition; {0}".format(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ transcribe_speech()