feat: cleanup and rework audio system
This commit is contained in:
36
app.py
36
app.py
@@ -1,20 +1,13 @@
|
||||
import logging
|
||||
import base64
|
||||
import json
|
||||
from pprint import pprint
|
||||
from threading import Thread
|
||||
|
||||
# import eventlet
|
||||
# eventlet.monkey_patch()
|
||||
from typing import List
|
||||
|
||||
from flask import Flask, jsonify, send_file, Response
|
||||
from flask import Flask, send_file, jsonify
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
from redis import Redis
|
||||
|
||||
# from control.camera import Camera
|
||||
# from control.walle import WallE
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
LOG = logging.getLogger(__name__)
|
||||
DATA_URL_PREFIX = 'data:image/jpeg;base64,'
|
||||
# DEBUG = True
|
||||
|
||||
@@ -24,9 +17,6 @@ sio = SocketIO(app)
|
||||
|
||||
redisdb = Redis()
|
||||
|
||||
# camera = Camera()
|
||||
# walle = WallE()
|
||||
|
||||
|
||||
class CameraListener:
|
||||
def __init__(self):
|
||||
@@ -59,10 +49,24 @@ def index(path):
|
||||
return send_file('client/dist/index.html')
|
||||
|
||||
|
||||
@app.route('/api/sounds')
|
||||
def get_available_sounds():
|
||||
try:
|
||||
sound_data = json.loads(redisdb.get('sound_data'))
|
||||
except ValueError:
|
||||
sound_data = []
|
||||
return jsonify(sound_data)
|
||||
|
||||
|
||||
@sio.on('playSound')
|
||||
def play_sound(name):
|
||||
redisdb.publish('sound', json.dumps({'action': 'play', 'name': name}))
|
||||
|
||||
|
||||
@sio.on("camera")
|
||||
def camera_message(directions):
|
||||
# walle.set_eye_velocity(directions['angle'], directions['force'])
|
||||
print(f"Moving camera in direction {directions['angle']:f} with velocity {directions['force']}")
|
||||
LOG.debug(f"Moving camera in direction {directions['angle']:f} with velocity {directions['force']}")
|
||||
redisdb.publish('look', json.dumps({
|
||||
'force': directions['force'],
|
||||
'angle': directions['angle'],
|
||||
@@ -72,7 +76,7 @@ def camera_message(directions):
|
||||
@sio.on("move")
|
||||
def move_message(directions):
|
||||
# walle.set_movement(directions['angle'], directions['force'])
|
||||
print(f"Moving in direction {directions['angle']:f} with velocity {directions['force']}")
|
||||
LOG.debug(f"Moving in direction {directions['angle']:f} with velocity {directions['force']}")
|
||||
redisdb.publish('move', json.dumps({
|
||||
'force': directions['force'],
|
||||
'angle': directions['angle'],
|
||||
|
||||
Reference in New Issue
Block a user