Files
chatgpt-on-wechat/bridge/bridge.py
2023-03-12 01:25:28 +08:00

31 lines
1020 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from bot import bot_factory
from common.singleton import singleton
from voice import voice_factory
@singleton
class Bridge(object):
def __init__(self):
self.bots = {
"chat": bot_factory.create_bot("chatGPT"),
"voice_to_text": voice_factory.create_voice("openai"),
# "text_to_voice": voice_factory.create_voice("baidu")
}
try:
self.bots["text_to_voice"] = voice_factory.create_voice("baidu")
except ModuleNotFoundError as e:
print(e)
# 以下所有函数需要得到一个reply字典格式如下
# reply["type"] = "ERROR" / "TEXT" / "VOICE" / ...
# reply["content"] = reply的内容
def fetch_reply_content(self, query, context):
return self.bots["chat"].reply(query, context)
def fetch_voice_to_text(self, voiceFile):
return self.bots["voice_to_text"].voiceToText(voiceFile)
def fetch_text_to_voice(self, text):
return self.bots["text_to_voice"].textToVoice(text)