mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
refactor: use enum to specify type
This commit is contained in:
@@ -4,6 +4,7 @@ google voice service
|
||||
"""
|
||||
import json
|
||||
import openai
|
||||
from bridge.reply import Reply, ReplyType
|
||||
from config import conf
|
||||
from common.log import logger
|
||||
from voice.voice import Voice
|
||||
@@ -16,16 +17,15 @@ class OpenaiVoice(Voice):
|
||||
def voiceToText(self, voice_file):
|
||||
logger.debug(
|
||||
'[Openai] voice file name={}'.format(voice_file))
|
||||
reply={}
|
||||
try:
|
||||
file = open(voice_file, "rb")
|
||||
result = openai.Audio.transcribe("whisper-1", file)
|
||||
text = result["text"]
|
||||
reply = {"type": "TEXT", "content": text}
|
||||
reply = Reply(ReplyType.TEXT, text)
|
||||
logger.info(
|
||||
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
|
||||
except Exception as e:
|
||||
reply = {"type": "ERROR", "content": str(e)}
|
||||
reply = Reply(ReplyType.ERROR, str(e))
|
||||
finally:
|
||||
return reply
|
||||
|
||||
|
||||
Reference in New Issue
Block a user