55fb0896b8
Fay2.0: 1、控制器pc内网穿透,音频输入输出设备远程直连; 2、提供android 音频输入输出工程示例代码; 3、提供python音频输入输出工程示例代码(远程PC、树莓派等可用); 4、补传1.0语音指令音乐播放模块(暂不支持远程播放); 5、重构及补充若干工具模块:websocket、多线程、缓冲器、音频流录制器等; 6、修复1.x版本的多个bug。
84 lines
2.0 KiB
Python
84 lines
2.0 KiB
Python
import json
|
|
import time
|
|
|
|
import pyaudio
|
|
from flask import Flask, render_template, request
|
|
from flask_cors import CORS
|
|
|
|
import fay_booter
|
|
from core import wsa_server
|
|
from core.tts_voice import EnumVoice
|
|
from scheduler.thread_manager import MyThread
|
|
from utils import config_util
|
|
|
|
__app = Flask(__name__)
|
|
CORS(__app, supports_credentials=True)
|
|
|
|
|
|
def __get_template():
|
|
return render_template('index.html')
|
|
|
|
|
|
def __get_device_list():
|
|
audio = pyaudio.PyAudio()
|
|
device_list = []
|
|
for i in range(audio.get_device_count()):
|
|
devInfo = audio.get_device_info_by_index(i)
|
|
if devInfo['hostApi'] == 0:
|
|
device_list.append(devInfo["name"])
|
|
|
|
return list(set(device_list))
|
|
|
|
|
|
@__app.route('/api/submit', methods=['post'])
|
|
def api_submit():
|
|
data = request.values.get('data')
|
|
# print(data)
|
|
config_data = json.loads(data)
|
|
config_util.save_config(config_data['config'])
|
|
return '{"result":"successful"}'
|
|
|
|
|
|
@__app.route('/api/get-data', methods=['post'])
|
|
def api_get_data():
|
|
wsa_server.get_web_instance().add_cmd({
|
|
"voiceList": [
|
|
{"id": EnumVoice.XIAO_XIAO.name, "name": "晓晓"},
|
|
{"id": EnumVoice.YUN_XI.name, "name": "云溪"}
|
|
]
|
|
})
|
|
wsa_server.get_web_instance().add_cmd({"deviceList": __get_device_list()})
|
|
return json.dumps({'config': config_util.config})
|
|
|
|
|
|
@__app.route('/api/start-live', methods=['post'])
|
|
def api_start_live():
|
|
# time.sleep(5)
|
|
fay_booter.start()
|
|
time.sleep(1)
|
|
wsa_server.get_web_instance().add_cmd({"liveState": 1})
|
|
return '{"result":"successful"}'
|
|
|
|
|
|
@__app.route('/api/stop-live', methods=['post'])
|
|
def api_stop_live():
|
|
# time.sleep(1)
|
|
fay_booter.stop()
|
|
time.sleep(1)
|
|
wsa_server.get_web_instance().add_cmd({"liveState": 0})
|
|
return '{"result":"successful"}'
|
|
|
|
|
|
@__app.route('/', methods=['get'])
|
|
def home_get():
|
|
return __get_template()
|
|
|
|
|
|
@__app.route('/', methods=['post'])
|
|
def home_post():
|
|
return __get_template()
|
|
|
|
|
|
def start():
|
|
MyThread(target=__app.run).start()
|