diff --git a/jarvis/api.py b/jarvis/api.py index 1f39f56..abd26d6 100644 --- a/jarvis/api.py +++ b/jarvis/api.py @@ -10,7 +10,7 @@ app = Flask(__name__) # .WAV (i.e.) FILE REQUEST -@app.route("/process_audio_request_file", methods=['POST']) +@app.route("/process_voice", methods=['POST']) def process_audio_request_android(): print("[" + request.remote_addr + "] - New STT request") @@ -22,7 +22,7 @@ def process_audio_request_android(): # TODO: send to each skill to answer the questions - return {"transcription": text, "answer": "I'm still learning how to respond to that..."} + return {"transcription": text, "status": 200} @app.route("/process_text", methods=['POST']) diff --git a/jarvis/utils/templates/index.html b/jarvis/utils/templates/index.html new file mode 100644 index 0000000..96ff693 --- /dev/null +++ b/jarvis/utils/templates/index.html @@ -0,0 +1,47 @@ + + + + Socket-Test + + + + + + +

Socket

+
+ + +
+ +
+ +
+

Logs

+
+ + \ No newline at end of file diff --git a/jarvis/utils/websocketstest.py b/jarvis/utils/websocketstest.py new file mode 100644 index 0000000..ec8540f --- /dev/null +++ b/jarvis/utils/websocketstest.py @@ -0,0 +1,39 @@ +from flask import Flask, render_template, session, copy_current_request_context +from flask_socketio import SocketIO, emit, disconnect +from threading import Lock + + +async_mode = None +app = Flask(__name__) +app.config['SECRET_KEY'] = 'secret!' +socket_ = SocketIO(app, async_mode=async_mode) +thread = None +thread_lock = Lock() + + +@app.route('/') +def index(): + return render_template('index.html', async_mode=socket_.async_mode) + + +@socket_.on('my_event', namespace='/test') +def test_message(message): + session['receive_count'] = session.get('receive_count', 0) + 1 + emit('my_response', + {'data': message['data'], 'count': session['receive_count']}) + + +@socket_.on('disconnect_request', namespace='/test') +def disconnect_request(): + @copy_current_request_context + def can_disconnect(): + disconnect() + + session['receive_count'] = session.get('receive_count', 0) + 1 + emit('my_response', + {'data': 'Disconnected!', 'count': session['receive_count']}, + callback=can_disconnect) + + +if __name__ == '__main__': + socket_.run(app, debug=True, host='0.0.0.0') diff --git a/requirements.txt b/requirements.txt index ef36775..32efb67 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ requests~=2.28.1 Flask~=2.2.2 adapt-parser==1.0.0 lingua-franca~=0.4.3 +Flask-SocketIO==5.3.2 \ No newline at end of file