Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

30 lines
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