Spaces:
Sleeping
Sleeping
from flask import Flask, render_template | |
from flask_socketio import SocketIO | |
import speech_recognition as sr | |
app = Flask(__name__) | |
socketio = SocketIO(app) | |
def index(): | |
return render_template('index.html') | |
def handle_message(message): | |
print(f'Received: {message}') | |
socketio.emit('response', message) | |
def recognize_speech(): | |
r = sr.Recognizer() | |
with sr.Microphone() as source: | |
print("Escuchando...") | |
audio = r.listen(source) | |
try: | |
recognized_text = r.recognize_google(audio, language='es-ES') | |
print(f"Texto reconocido: {recognized_text}") | |
socketio.emit('response', recognized_text) | |
except sr.UnknownValueError: | |
print("No se pudo reconocer el audio") | |
except sr.RequestError as e: | |
print(f"Error en la solicitud a Google: {e}") | |
if __name__ == '__main__': | |
socketio.run(app, host='0.0.0.0', port=7860, ssl_context=('cert.pem', 'key.pem')) | |