import os import uuid from flask import Flask, flash, render_template, request from flask_cors import CORS from modules import Module model = Module() app = Flask(__name__) CORS(app) app.secret_key = "Testing" @app.route('/') def index(): flash(" Welcome to My Website") return render_template('index.html') @app.route('/audio_to_text/') def audio_to_text(): flash(" Press Start to start recording audio and press Stop to end recording audio") return render_template('audio_to_text.html') @app.route('/audio', methods=['POST']) def audio(): try: output_file = f"./tmp/{uuid.uuid4()}.wav" open(output_file, 'wb').write(request.data) text, emotion = model.predict(audio_path=output_file) os.remove(output_file) return_text = f" Transcription: {text}
Emotion: {emotion} " except Exception: return_text = " Sorry!!!! Voice not Detected " return return_text if __name__ == "__main__": app.run(debug=True, port=7860, host='0.0.0.0')