您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

openai_voice.py 673B

123456789101112131415161718192021222324252627
  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. file = open(voice_file, "rb")
  16. reply = openai.Audio.transcribe("whisper-1", file)
  17. text = reply["text"]
  18. logger.info(
  19. '[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
  20. return text
  21. def textToVoice(self, text):
  22. pass