diff --git a/requirements.txt b/requirements.txt index 32739385..a79d8bc0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,10 +14,10 @@ websocket-client pypinyin jieba pvporcupine -pvrecorder +pvrecorder==1.1.1 openai apscheduler asyncio edge-tts nest_asyncio -funasr_onnx \ No newline at end of file +funasr_onnx diff --git a/robot/AI.py b/robot/AI.py index 2e28263f..aca9ba9d 100644 --- a/robot/AI.py +++ b/robot/AI.py @@ -114,6 +114,59 @@ def chat(self, texts, parsed): return "抱歉, 百度UNIT服务回答失败" +class BingRobot(AbstractRobot): + + SLUG = "bing" + + def __init__(self, prefix, proxy, mode): + """ + bing + """ + super(self.__class__, self).__init__() + self.prefix = prefix + self.proxy = proxy + self.mode = mode + + @classmethod + def get_config(cls): + return config.get("bing", {}) + + def chat(self, texts, parsed): + """ + + Arguments: + texts -- user input, typically speech, to be parsed by a module + """ + msg = "".join(texts) + msg = utils.stripPunctuation(msg) + try: + import asyncio, json + from EdgeGPT.EdgeGPT import Chatbot, ConversationStyle + + async def query_bing(): + # Passing cookies is "optional" + bot = await Chatbot.create(proxy=self.proxy) + m2s = { + "creative": ConversationStyle.creative, + "balanced": ConversationStyle.balanced, + "precise": ConversationStyle.precise + } + response = await bot.ask(prompt=self.prefix + "\n" + msg, + conversation_style=m2s[self.mode], + simplify_response=True) + #print(json.dumps(response, indent=2)) # Returns + return response["text"] + await bot.close() + + result = asyncio.run(query_bing()) + + logger.info("{} 回答:{}".format(self.SLUG, result)) + return result + except Exception: + logger.critical("bing robot failed to response for %r", msg, exc_info=True) + return "抱歉, bing回答失败" + + class AnyQRobot(AbstractRobot): SLUG = "anyq" diff --git a/static/default.yml b/static/default.yml index cf6b065f..8a2f1db9 100755 --- a/static/default.yml +++ b/static/default.yml @@ -23,7 +23,7 @@ server: # 可选值: # porcupine # snowboy -detector: snowboy +detector: porcupine # 灵敏度 sensitivity: 0.5 @@ -33,11 +33,13 @@ sensitivity: 0.5 porcupine: keywords: - 'porcupine' + - 'hello bing' keyword_paths: # 支持追加多个唤醒词 # 自定义唤醒词请放到 $HOME/.wukong 目录中 # - 'spiderman.ppn' - access_key: 'xxxxxxxxxxxxxxxxxxxxxxxx' + - 'hello-bing_en_raspberry-pi_v3_0_0.ppn' + access_key: '' # snowboy 离线唤醒 # 建议使用 snowboy-seasalt (https://github.com/rhasspy/snowboy-seasalt) @@ -228,7 +230,27 @@ nlu_engine: unit # openai - OpenAI ChatGPT # anyq - AnyQ # tuling - 图灵机器人 -robot: unit +robot: bing + + +# 必应 bing +bing: + prefix: " + # 角色: 语音化必应智能音箱 + ## 目标 + - 您是一个语音化智能音箱,具备配合其他模块将你输出的文字转换为语音的能力。 + ## 约束 + - 您的回复必须以口语化的形式呈现,不能包含任何链接、emoji表情、图片、网站推荐以及其他形式的书面语言。 + - 请避免涉及到代码、图片生成等专业性的工作场景内容。 + ## 技能 + - 百科问答技能: 您可以解答各种百科性的问题,进行科普教育。 + - 咨询服务技能: 您可以接受各领域的咨询,为用户提供一对一的解答服务。 + - 常见智能音箱功能: 您还能讲笑话、阅读短新闻,提供今日头条、热点等信息。 + - 闲聊: 倾听倾诉给予建议" + + proxy: "http://127.0.0.1:7890" + # creative, balanced, precise + mode: "creative" # 百度 UNIT unit: