You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1020B

  1. from bot import bot_factory
  2. from common.singleton import singleton
  3. from voice import voice_factory
  4. @singleton
  5. class Bridge(object):
  6. def __init__(self):
  7. self.bots = {
  8. "chat": bot_factory.create_bot("chatGPT"),
  9. "voice_to_text": voice_factory.create_voice("openai"),
  10. # "text_to_voice": voice_factory.create_voice("baidu")
  11. }
  12. try:
  13. self.bots["text_to_voice"] = voice_factory.create_voice("baidu")
  14. except ModuleNotFoundError as e:
  15. print(e)
  16. # 以下所有函数需要得到一个reply字典,格式如下:
  17. # reply["type"] = "ERROR" / "TEXT" / "VOICE" / ...
  18. # reply["content"] = reply的内容
  19. def fetch_reply_content(self, query, context):
  20. return self.bots["chat"].reply(query, context)
  21. def fetch_voice_to_text(self, voiceFile):
  22. return self.bots["voice_to_text"].voiceToText(voiceFile)
  23. def fetch_text_to_voice(self, text):
  24. return self.bots["text_to_voice"].textToVoice(text)