Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

30 lignes
826B

  1. """
  2. google voice service
  3. """
  4. import json
  5. import openai
  6. from bridge.reply import Reply, ReplyType
  7. from common.log import logger
  8. from config import conf
  9. from voice.voice import Voice
  10. class OpenaiVoice(Voice):
  11. def __init__(self):
  12. openai.api_key = conf().get("open_ai_api_key")
  13. def voiceToText(self, voice_file):
  14. logger.debug("[Openai] voice file name={}".format(voice_file))
  15. try:
  16. file = open(voice_file, "rb")
  17. result = openai.Audio.transcribe("whisper-1", file)
  18. text = result["text"]
  19. reply = Reply(ReplyType.TEXT, text)
  20. logger.info("[Openai] voiceToText text={} voice file name={}".format(text, voice_file))
  21. except Exception as e:
  22. reply = Reply(ReplyType.ERROR, str(e))
  23. finally:
  24. return reply