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.

openai_voice.py 894B

il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
il y a 1 an
123456789101112131415161718192021222324252627282930313233
  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(
  21. "[Openai] voiceToText text={} voice file name={}".format(
  22. text, voice_file
  23. )
  24. )
  25. except Exception as e:
  26. reply = Reply(ReplyType.ERROR, str(e))
  27. finally:
  28. return reply