|
@@ -4,19 +4,21 @@ google voice service
|
|
|
"""
|
|
"""
|
|
|
import json
|
|
import json
|
|
|
import openai
|
|
import openai
|
|
|
|
|
+from config import conf
|
|
|
from common.log import logger
|
|
from common.log import logger
|
|
|
from voice.voice import Voice
|
|
from voice.voice import Voice
|
|
|
|
|
|
|
|
|
|
|
|
|
class OpenaiVoice(Voice):
|
|
class OpenaiVoice(Voice):
|
|
|
def __init__(self):
|
|
def __init__(self):
|
|
|
- pass
|
|
|
|
|
|
|
+ openai.api_key = conf().get('open_ai_api_key')
|
|
|
|
|
|
|
|
def voiceToText(self, voice_file):
|
|
def voiceToText(self, voice_file):
|
|
|
|
|
+ logger.debug(
|
|
|
|
|
+ '[Openai] voice file name={}'.format(voice_file))
|
|
|
file = open(voice_file, "rb")
|
|
file = open(voice_file, "rb")
|
|
|
reply = openai.Audio.transcribe("whisper-1", file)
|
|
reply = openai.Audio.transcribe("whisper-1", file)
|
|
|
- json_dict = json.loads(reply)
|
|
|
|
|
- text = json_dict['text']
|
|
|
|
|
|
|
+ text = reply["text"]
|
|
|
logger.info(
|
|
logger.info(
|
|
|
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
|
|
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
|
|
|
return text
|
|
return text
|