fix: 新增参数配置强制打断小爱说话

This commit is contained in:
涵曦 2024-07-06 11:16:42 +00:00
parent 86f158532a
commit a4ab1af160
2 changed files with 5 additions and 2 deletions

View File

@ -120,6 +120,9 @@ class Config:
user_key_word_dict: dict[str, str] = field( user_key_word_dict: dict[str, str] = field(
default_factory=default_user_key_word_dict default_factory=default_user_key_word_dict
) )
enable_force_stop: bool = (
os.getenv("XIAOMUSIC_ENABLE_FORCE_STOP", "false").lower() == "true"
)
def append_keyword(self, keys, action): def append_keyword(self, keys, action):
for key in keys.split(","): for key in keys.split(","):

View File

@ -344,11 +344,11 @@ class XiaoMusic:
async def stop_if_xiaoai_is_playing(self, device_id): async def stop_if_xiaoai_is_playing(self, device_id):
is_playing = await self.get_if_xiaoai_is_playing(device_id) is_playing = await self.get_if_xiaoai_is_playing(device_id)
if is_playing: if is_playing or self.config.enable_force_stop:
# stop it # stop it
ret = await self.mina_service.player_stop(device_id) ret = await self.mina_service.player_stop(device_id)
self.log.info( self.log.info(
f"stop_if_xiaoai_is_playing player_stop device_id:{device_id} ret:{ret}" f"stop_if_xiaoai_is_playing player_stop device_id:{device_id} enable_force_stop:{self.config.enable_force_stop} ret:{ret}"
) )
async def force_stop_one_xiaoai(self, device_id): async def force_stop_one_xiaoai(self, device_id):