|
|
@ -25,6 +25,7 @@ import time
|
|
|
|
import cv2
|
|
|
|
import cv2
|
|
|
|
import glob
|
|
|
|
import glob
|
|
|
|
import resampy
|
|
|
|
import resampy
|
|
|
|
|
|
|
|
import aiohttp
|
|
|
|
|
|
|
|
|
|
|
|
import queue
|
|
|
|
import queue
|
|
|
|
from queue import Queue
|
|
|
|
from queue import Queue
|
|
|
@ -93,6 +94,7 @@ class BaseReal:
|
|
|
|
|
|
|
|
|
|
|
|
self.liv_speaking = False
|
|
|
|
self.liv_speaking = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.manual_control_mode = False
|
|
|
|
self.recording = False
|
|
|
|
self.recording = False
|
|
|
|
self._record_video_pipe = None
|
|
|
|
self._record_video_pipe = None
|
|
|
|
self._record_audio_pipe = None
|
|
|
|
self._record_audio_pipe = None
|
|
|
@ -163,14 +165,36 @@ class BaseReal:
|
|
|
|
for key in self.custom_index:
|
|
|
|
for key in self.custom_index:
|
|
|
|
self.custom_index[key]=0
|
|
|
|
self.custom_index[key]=0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def update_is_speaking(self, status: bool):
|
|
|
|
|
|
|
|
"""调用本地接口,更新 is_speaking 状态"""
|
|
|
|
|
|
|
|
url = "http://127.0.0.1:8000/speaking-status"
|
|
|
|
|
|
|
|
data = {"is_speaking": status}
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
|
|
|
|
async with session.post(url, json=data) as response:
|
|
|
|
|
|
|
|
if response.status == 200:
|
|
|
|
|
|
|
|
result = await response.json()
|
|
|
|
|
|
|
|
print(f"更新is_speaking状态:{result}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
print(f"请求失败,状态码:{response.status}")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print(f"请求更新is_speaking失败: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_speaking_state(self, state: bool):
|
|
|
|
|
|
|
|
"""设置 liv_speaking 状态并调用接口更新"""
|
|
|
|
|
|
|
|
self.liv_speaking = state
|
|
|
|
|
|
|
|
asyncio.create_task(self.update_is_speaking(self.liv_speaking)) # 异步调用更新接口
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def notify(self, eventpoint):
|
|
|
|
def notify(self, eventpoint):
|
|
|
|
logger.info("notify:%s", eventpoint)
|
|
|
|
logger.info("notify:%s", eventpoint)
|
|
|
|
# 使用字典的键访问方式,而不是对象属性方式
|
|
|
|
|
|
|
|
if eventpoint['status'] == "start":
|
|
|
|
# 如果是手动控制模式,忽略 TTS 结束信号,不设置 liv_speaking 为 False
|
|
|
|
self.liv_speaking = True
|
|
|
|
if self.manual_control_mode:
|
|
|
|
logger.info("tts start") # 这里可能是笔误,改为start更合理
|
|
|
|
return # 如果处于手动接管状态,直接返回,不改变 liv_speaking 的状态
|
|
|
|
|
|
|
|
|
|
|
|
if eventpoint['status'] == "end":
|
|
|
|
if eventpoint['status'] == "end":
|
|
|
|
self.liv_speaking = False
|
|
|
|
self.set_speaking_state(False)
|
|
|
|
logger.info("tts end")
|
|
|
|
logger.info("tts end")
|
|
|
|
|
|
|
|
|
|
|
|
def start_recording(self):
|
|
|
|
def start_recording(self):
|
|
|
|