From 44cb54a9ea499c0c86bbcf83bf343e5c98f1de64 Mon Sep 17 00:00:00 2001 From: SSMario Date: Tue, 16 May 2023 09:38:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=89=8B=E6=9C=BA=E4=B8=8A?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E6=B6=88=E6=81=AF=EF=BC=8C=E4=B8=8D=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- channel/chat_message.py | 1 + channel/wechat/wechat_channel.py | 3 +++ channel/wechat/wechat_message.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/channel/chat_message.py b/channel/chat_message.py index fdd4d90..0e2f652 100644 --- a/channel/chat_message.py +++ b/channel/chat_message.py @@ -48,6 +48,7 @@ class ChatMessage(object): to_user_nickname = None other_user_id = None other_user_nickname = None + my_msg = False is_group = False is_at = False diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index c888157..10c5003 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -59,6 +59,9 @@ def _check(func): if conf().get("hot_reload") == True and int(create_time) < int(time.time()) - 60: # 跳过1分钟前的历史消息 logger.debug("[WX]history message {} skipped".format(msgId)) return + if cmsg.my_msg: + logger.debug("[WX]my message {} skipped".format(msgId)) + return return func(self, cmsg) return wrapper diff --git a/channel/wechat/wechat_message.py b/channel/wechat/wechat_message.py index 5d9bf28..b9824f9 100644 --- a/channel/wechat/wechat_message.py +++ b/channel/wechat/wechat_message.py @@ -58,6 +58,8 @@ class WechatMessage(ChatMessage): if self.to_user_id == user_id: self.to_user_nickname = nickname try: # 陌生人时候, 'User'字段可能不存在 + self.my_msg = itchat_msg["ToUserName"] == itchat_msg["User"]["UserName"] and \ + itchat_msg["ToUserName"] != itchat_msg["FromUserName"] self.other_user_id = itchat_msg["User"]["UserName"] self.other_user_nickname = itchat_msg["User"]["NickName"] if self.other_user_id == self.from_user_id: From 1d4ff796d79a49cd173e27121a365d7925305932 Mon Sep 17 00:00:00 2001 From: SSMario Date: Tue, 16 May 2023 11:50:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0eleventLabs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- requirements-optional.txt | 1 + voice/elevent/elevent_voice.py | 32 ++++++++++++++++++++++++++++++++ voice/factory.py | 4 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 voice/elevent/elevent_voice.py diff --git a/config.py b/config.py index ae1cfd7..782beac 100644 --- a/config.py +++ b/config.py @@ -53,7 +53,7 @@ available_setting = { "voice_reply_voice": False, # 是否使用语音回复语音,需要设置对应语音合成引擎的api key "always_reply_voice": False, # 是否一直使用语音回复 "voice_to_text": "openai", # 语音识别引擎,支持openai,baidu,google,azure - "text_to_voice": "baidu", # 语音合成引擎,支持baidu,google,pytts(offline),azure + "text_to_voice": "baidu", # 语音合成引擎,支持baidu,google,pytts(offline),azure,eleven # baidu 语音api配置, 使用百度语音识别和语音合成时需要 "baidu_app_id": "", "baidu_api_key": "", diff --git a/requirements-optional.txt b/requirements-optional.txt index c248689..9901de4 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -9,6 +9,7 @@ baidu_aip>=4.16.10 # baidu voice azure-cognitiveservices-speech # azure voice numpy<=1.24.2 langid # language detect +elevenlabs==0.2.15 #install plugin dulwich diff --git a/voice/elevent/elevent_voice.py b/voice/elevent/elevent_voice.py new file mode 100644 index 0000000..72d5bcd --- /dev/null +++ b/voice/elevent/elevent_voice.py @@ -0,0 +1,32 @@ +""" +eleventLabs voice service +""" + +import time + +from elevenlabs import generate + +from bridge.reply import Reply, ReplyType +from common.log import logger +from common.tmp_dir import TmpDir +from voice.voice import Voice + + +class ElevenLabsVoice(Voice): + + def __init__(self): + pass + + def voiceToText(self, voice_file): + pass + + def textToVoice(self, text): + audio = generate( + text=text + ) + fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3" + with open(fileName, "wb") as f: + f.write(audio) + logger.info("[ElevenLabs] textToVoice text={} voice file name={}".format(text, fileName)) + return Reply(ReplyType.VOICE, fileName) + diff --git a/voice/factory.py b/voice/factory.py index 45fe0d1..0cf1a05 100644 --- a/voice/factory.py +++ b/voice/factory.py @@ -29,4 +29,8 @@ def create_voice(voice_type): from voice.azure.azure_voice import AzureVoice return AzureVoice() + elif voice_type == "eleven": + from voice.elevent.elevent_voice import ElevenLabsVoice + + return ElevenLabsVoice() raise RuntimeError From 4dbc54fa15ff77b7acda570cc494f8fef6a87a42 Mon Sep 17 00:00:00 2001 From: SSMario Date: Tue, 16 May 2023 12:00:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"feat:=20=E5=A2=9E=E5=8A=A0elevent?= =?UTF-8?q?Labs"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1d4ff796d79a49cd173e27121a365d7925305932. --- config.py | 2 +- requirements-optional.txt | 1 - voice/elevent/elevent_voice.py | 32 -------------------------------- voice/factory.py | 4 ---- 4 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 voice/elevent/elevent_voice.py diff --git a/config.py b/config.py index 782beac..ae1cfd7 100644 --- a/config.py +++ b/config.py @@ -53,7 +53,7 @@ available_setting = { "voice_reply_voice": False, # 是否使用语音回复语音,需要设置对应语音合成引擎的api key "always_reply_voice": False, # 是否一直使用语音回复 "voice_to_text": "openai", # 语音识别引擎,支持openai,baidu,google,azure - "text_to_voice": "baidu", # 语音合成引擎,支持baidu,google,pytts(offline),azure,eleven + "text_to_voice": "baidu", # 语音合成引擎,支持baidu,google,pytts(offline),azure # baidu 语音api配置, 使用百度语音识别和语音合成时需要 "baidu_app_id": "", "baidu_api_key": "", diff --git a/requirements-optional.txt b/requirements-optional.txt index 9901de4..c248689 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -9,7 +9,6 @@ baidu_aip>=4.16.10 # baidu voice azure-cognitiveservices-speech # azure voice numpy<=1.24.2 langid # language detect -elevenlabs==0.2.15 #install plugin dulwich diff --git a/voice/elevent/elevent_voice.py b/voice/elevent/elevent_voice.py deleted file mode 100644 index 72d5bcd..0000000 --- a/voice/elevent/elevent_voice.py +++ /dev/null @@ -1,32 +0,0 @@ -""" -eleventLabs voice service -""" - -import time - -from elevenlabs import generate - -from bridge.reply import Reply, ReplyType -from common.log import logger -from common.tmp_dir import TmpDir -from voice.voice import Voice - - -class ElevenLabsVoice(Voice): - - def __init__(self): - pass - - def voiceToText(self, voice_file): - pass - - def textToVoice(self, text): - audio = generate( - text=text - ) - fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3" - with open(fileName, "wb") as f: - f.write(audio) - logger.info("[ElevenLabs] textToVoice text={} voice file name={}".format(text, fileName)) - return Reply(ReplyType.VOICE, fileName) - diff --git a/voice/factory.py b/voice/factory.py index 0cf1a05..45fe0d1 100644 --- a/voice/factory.py +++ b/voice/factory.py @@ -29,8 +29,4 @@ def create_voice(voice_type): from voice.azure.azure_voice import AzureVoice return AzureVoice() - elif voice_type == "eleven": - from voice.elevent.elevent_voice import ElevenLabsVoice - - return ElevenLabsVoice() raise RuntimeError