Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,29 @@ r = sr.Recognizer()
|
|
| 15 |
def handle_audio(data):
|
| 16 |
audio = sr.AudioData(data, 16000, 2)
|
| 17 |
recognized_text = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
recognized_text = r.recognize_google(audio, language='es-ES')
|
| 21 |
except sr.UnknownValueError:
|
|
@@ -25,6 +47,13 @@ def handle_audio(data):
|
|
| 25 |
|
| 26 |
socketio.emit('transcription', recognized_text)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
@socketio.on('start_recording')
|
| 29 |
def start_recording():
|
| 30 |
# L贸gica para comenzar la grabaci贸n en el servidor si es necesario
|
|
|
|
| 15 |
def handle_audio(data):
|
| 16 |
audio = sr.AudioData(data, 16000, 2)
|
| 17 |
recognized_text = ""
|
| 18 |
+
|
| 19 |
+
#######################################
|
| 20 |
+
import pygame
|
| 21 |
+
from io import BytesIO
|
| 22 |
+
|
| 23 |
+
# Configura Pygame
|
| 24 |
+
pygame.mixer.init()
|
| 25 |
+
# Crea un objeto de BytesIO para reproducir el audio
|
| 26 |
+
audio_stream = BytesIO(data)
|
| 27 |
|
| 28 |
+
try:
|
| 29 |
+
pygame.mixer.music.load(audio_stream)
|
| 30 |
+
pygame.mixer.music.play()
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return "Error al reproducir audio: {}".format(str(e))
|
| 33 |
+
|
| 34 |
+
return "Audio reproducido con 茅xito"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
#######################################
|
| 41 |
try:
|
| 42 |
recognized_text = r.recognize_google(audio, language='es-ES')
|
| 43 |
except sr.UnknownValueError:
|
|
|
|
| 47 |
|
| 48 |
socketio.emit('transcription', recognized_text)
|
| 49 |
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
@socketio.on('start_recording')
|
| 58 |
def start_recording():
|
| 59 |
# L贸gica para comenzar la grabaci贸n en el servidor si es necesario
|