4cfad5ae0f
- 全新ui - 全面优化websocket逻辑,提高数字人和ui连接的稳定性及资源开销 - 全面优化唤醒逻辑,提供稳定的普通唤醒模式和前置词唤醒模式 - 优化拾音质量,支持多声道麦克风拾音 - 优化自动播放服务器的对接机制,提供稳定和兼容旧版ue工程的对接模式 - 数字人接口输出机器人表情,以适应新fay ui及单片机的数字人表情输出 - 使用更高级的音频时长计算方式,可以更精准控制音频播放完成后的逻辑 - 修复点击关闭按钮会导致程序退出的bug - 修复没有麦克风的设备开启麦克风会出错的问题 - 为服务器主机地址提供配置项,以方便服务器部署
91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
import sqlite3
|
|
import time
|
|
import threading
|
|
import functools
|
|
from utils import util
|
|
def synchronized(func):
|
|
@functools.wraps(func)
|
|
def wrapper(self, *args, **kwargs):
|
|
with self.lock:
|
|
return func(self, *args, **kwargs)
|
|
return wrapper
|
|
|
|
__content_tb = None
|
|
def new_instance():
|
|
global __content_tb
|
|
if __content_tb is None:
|
|
__content_tb = Content_Db()
|
|
__content_tb.init_db()
|
|
return __content_tb
|
|
|
|
|
|
class Content_Db:
|
|
|
|
def __init__(self) -> None:
|
|
self.lock = threading.Lock()
|
|
|
|
|
|
|
|
#初始化
|
|
def init_db(self):
|
|
conn = sqlite3.connect('fay.db')
|
|
c = conn.cursor()
|
|
c.execute('''CREATE TABLE IF NOT EXISTS T_Msg
|
|
(id INTEGER PRIMARY KEY autoincrement,
|
|
type char(10),
|
|
way char(10),
|
|
content TEXT NOT NULL,
|
|
createtime Int,
|
|
username TEXT DEFAULT 'User',
|
|
uid Int);''')
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
|
|
|
|
|
|
#添加对话
|
|
@synchronized
|
|
def add_content(self,type,way,content,username='User',uid=0):
|
|
conn = sqlite3.connect("fay.db")
|
|
cur = conn.cursor()
|
|
try:
|
|
cur.execute("insert into T_Msg (type,way,content,createtime,username,uid) values (?,?,?,?,?,?)",(type,way,content,int(time.time()),username,uid))
|
|
conn.commit()
|
|
except:
|
|
util.log(1, "请检查参数是否有误")
|
|
conn.close()
|
|
return 0
|
|
conn.close()
|
|
return cur.lastrowid
|
|
|
|
|
|
|
|
#获取对话内容
|
|
@synchronized
|
|
def get_list(self,way,order,limit,uid=0):
|
|
conn = sqlite3.connect("fay.db")
|
|
cur = conn.cursor()
|
|
where_uid = ""
|
|
if int(uid) != 0:
|
|
where_uid = f" and uid = {uid} "
|
|
if(way == 'all'):
|
|
cur.execute("select type,way,content,createtime,datetime(createtime, 'unixepoch', 'localtime') as timetext,username from T_Msg where 1 "+where_uid+" order by id "+order+" limit ?",(limit,))
|
|
elif(way == 'notappended'):
|
|
cur.execute("select type,way,content,createtime,datetime(createtime, 'unixepoch', 'localtime') as timetext,username from T_Msg where way != 'appended' "+where_uid+" order by id "+order+" limit ?",(limit,))
|
|
else:
|
|
cur.execute("select type,way,content,createtime,datetime(createtime, 'unixepoch', 'localtime') as timetext,username from T_Msg where way = ? "+where_uid+" order by id "+order+" limit ?",(way,limit,))
|
|
|
|
list = cur.fetchall()
|
|
conn.close()
|
|
return list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|