mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 13:28:11 +08:00
[voice] add support for whisper-1 model
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
google voice service
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import subprocess
|
||||
import time
|
||||
import speech_recognition
|
||||
@@ -12,7 +13,6 @@ from voice.voice import Voice
|
||||
|
||||
|
||||
class GoogleVoice(Voice):
|
||||
tmpFilePath = './tmp/'
|
||||
recognizer = speech_recognition.Recognizer()
|
||||
engine = pyttsx3.init()
|
||||
|
||||
|
||||
@@ -4,19 +4,21 @@ google voice service
|
||||
"""
|
||||
import json
|
||||
import openai
|
||||
from config import conf
|
||||
from common.log import logger
|
||||
from voice.voice import Voice
|
||||
|
||||
|
||||
class OpenaiVoice(Voice):
|
||||
def __init__(self):
|
||||
pass
|
||||
openai.api_key = conf().get('open_ai_api_key')
|
||||
|
||||
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)
|
||||
json_dict = json.loads(reply)
|
||||
text = json_dict['text']
|
||||
text = reply["text"]
|
||||
logger.info(
|
||||
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user