File size: 1,036 Bytes
50a4084
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aa150d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask, render_template
from flask_socketio import SocketIO
import speech_recognition as sr

app = Flask(__name__)
socketio = SocketIO(app)

@app.route('/')
def index():
    return render_template('index.html')

@socketio.on('message')
def handle_message(message):
    print(f'Received: {message}')
    socketio.emit('response', message)

@socketio.on('recognize_speech')
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'))