diff --git a/main/xiaozhi-server/core/handle/jellyfinHandler.py b/main/xiaozhi-server/core/handle/jellyfinHandler.py index 5b10a326d..067701cdc 100644 --- a/main/xiaozhi-server/core/handle/jellyfinHandler.py +++ b/main/xiaozhi-server/core/handle/jellyfinHandler.py @@ -33,9 +33,9 @@ class JellyfinHandler: def __init__(self, config): self.config = config self.music_related_keywords = [] - default_music_related_keywords = ["来一首歌", "唱一首歌", "播放音乐", "来点音乐", "背景音乐", "放首歌", "播放歌曲", "来点背景音乐", "我想听歌", "我要听歌", "放点音乐"] + self.music_files = ['播放音乐'] if "music" in self.config: self.music_config = self.config["music"] self.jellyfin_endpoint = self.music_config['jellyfin']['endpoint'] @@ -49,12 +49,18 @@ class JellyfinHandler: async def handle_music_command(self, conn, text): """处理音乐播放指令""" - clean_text = re.sub(r'[^\w\s]', '', text).strip() - logger.bind(tag=TAG).debug(f"检查是否是音乐命令: {clean_text}") + try: + content = (re.findall(r"'([^']*)'", text) or [text])[0] + clean_text = re.sub(r'[^\w\s]', '', content).strip() + potential_song = clean_text.split(' ')[-1] + except Exception as e: + logger.bind(tag=TAG).error(f"非intent命令: {str(e)}") + clean_text = re.sub(r'[^\w\s]', '', text).strip() + logger.bind(tag=TAG).debug(f"检查是否是音乐命令: {clean_text}") + potential_song = _extract_song_name(clean_text) # 尝试匹配具体歌名 if self.jellyfin_endpoint: - potential_song = _extract_song_name(clean_text) if potential_song: best_match_item = self._find_best_match(potential_song) if best_match_item: diff --git a/main/xiaozhi-server/core/providers/tts/base.py b/main/xiaozhi-server/core/providers/tts/base.py index 80ca95e76..77100fe26 100644 --- a/main/xiaozhi-server/core/providers/tts/base.py +++ b/main/xiaozhi-server/core/providers/tts/base.py @@ -47,18 +47,18 @@ class TTSProviderBase(ABC): if not wav_bytes: raise IOError('stream null') audio = AudioSegment.from_file(BytesIO(wav_bytes)) - return self.audio_to_opus_data(audio) + return self.audio_seg_to_opus_data(audio) - def audio_to_opus_data(self, audio_file_path:str): + def audio_to_opus_data(self, wav_file_path:str): """音频文件转换为Opus编码""" # 获取文件后缀名 - file_type = os.path.splitext(audio_file_path)[1] + file_type = os.path.splitext(wav_file_path)[1] if file_type: file_type = file_type.lstrip('.') audio = AudioSegment.from_file(wav_file_path, format=file_type) - return self.audio_to_opus_data(audio) + return self.audio_seg_to_opus_data(audio) - def audio_to_opus_data(self, audio:AudioSegment): + def audio_seg_to_opus_data(self, audio:AudioSegment): # 转换为单声道/16kHz采样率/16位小端编码(确保与编码器匹配) audio = audio.set_channels(1).set_frame_rate(16000).set_sample_width(2)