Spaces:
Sleeping
Sleeping
from flask import Flask, render_template, request, jsonify | |
import speech_recognition as sr | |
app = Flask(__name__) | |
def index(): | |
return render_template('index.html') | |
def send_message(): | |
user_input = request.form['user_input'] | |
response = echo_response(user_input) | |
return jsonify({'response': response, 'user_input': user_input}) | |
def echo_response(user_input): | |
return user_input | |
def process_audio(): | |
if 'audio' not in request.files: | |
return "No audio file provided", 400 | |
audio_file = request.files['audio'] | |
recognizer = sr.Recognizer() | |
with sr.AudioFile(audio_file) as source: | |
audio = recognizer.record(source) | |
try: | |
text = recognizer.recognize_google(audio) | |
print("Transcribed Text:", text) | |
return text | |
except sr.UnknownValueError: | |
return "Could not understand audio", 400 | |
except sr.RequestError as e: | |
return f"Could not request results from Google Speech Recognition service; {e}", 500 | |
if __name__ == '__main__': | |
app.run(host="0.0.0.0", port=7860) |