Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

openai_voice.py 889B

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