#!/usr/bin/env python # -*- coding: utf-8 -*- from flask import Flask, jsonify from flask import request from flask import render_template import speech_recognition as sr from werkzeug.datastructures import FileStorage import os import sys from flask_caching import Cache app = Flask(__name__) semaforo=False app.config['CACHE_TYPE'] = 'simple' cache = Cache(app) r = sr.Recognizer() @app.route("/", methods=['POST', 'GET']) def index(): recognized_text = "" # Valor predeterminado if request.method == "POST": f = request.files['audio_data'] # Cargar el archivo adjunto directamente with sr.AudioFile(f) as source: audio_data = r.record(source) # Realizar el reconocimiento de voz try: recognized_text = r.recognize_google(audio_data, language='es-ES') except sr.UnknownValueError: recognized_text = "No se pudo reconocer el audio" except sr.RequestError as e: recognized_text = f"Error en la solicitud: {str(e)}" print(recognized_text) return render_template('index.html', recognized_text=recognized_text) if __name__ == "__main__": app.run(host='0.0.0.0', port=7860,debug=True) #if __name__ == '__main__': # socketio.run(app, host='0.0.0.0', port=7860, debug=True)