compatible for voice

This commit is contained in:
lanvent
2023-03-13 00:12:34 +08:00
parent cee57e4ffc
commit 8d2e81815c
6 changed files with 64 additions and 40 deletions

View File

@@ -16,12 +16,18 @@ class OpenaiVoice(Voice):
def voiceToText(self, voice_file):
logger.debug(
'[Openai] voice file name={}'.format(voice_file))
file = open(voice_file, "rb")
reply = openai.Audio.transcribe("whisper-1", file)
text = reply["text"]
logger.info(
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
return text
reply={}
try:
file = open(voice_file, "rb")
result = openai.Audio.transcribe("whisper-1", file)
text = result["text"]
reply = {"type": "TEXT", "content": text}
logger.info(
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
except Exception as e:
reply = {"type": "ERROR", "content": str(e)}
finally:
return reply
def textToVoice(self, text):
pass