[voice] add support for wispper

This commit is contained in:
wanggang
2023-03-08 11:02:01 +08:00
parent 720ad07f83
commit 882e6c3576
7 changed files with 60 additions and 42 deletions

View File

@@ -0,0 +1,22 @@
"""
baidu voice service
"""
from aip import AipSpeech
from voice.voice import Voice
from config import conf
class BaiduVoice(Voice):
APP_ID = conf().get('baidu_app_id')
API_KEY = conf().get('baidu_api_key')
SECRET_KEY = conf().get('baidu_secret_key')
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
def __init__(self):
pass
def voiceToText(self, voice_file):
pass
def textToVoice(self, text):
pass

View File

@@ -0,0 +1,25 @@
"""
google voice service
"""
import json
import openai
from common.log import logger
from voice.voice import Voice
class OpenaiVoice(Voice):
def __init__(self):
pass
def voiceToText(self, voice_file):
file = open(voice_file, "rb")
reply = openai.Audio.transcribe("whisper-1", file)
json_dict = json.loads(reply)
text = json_dict['text']
logger.info(
'[Openai] voiceToText text={} voice file name={}'.format(text, voice_file))
return text
def textToVoice(self, text):
pass

View File

@@ -8,10 +8,13 @@ def create_voice(voice_type):
:param voice_type: voice type code
:return: voice instance
"""
if voice_type == 'xfyun':
from voice.xfyun.xfyun_voice import XfyunVoice
return XfyunVoice()
if voice_type == 'baidu':
from voice.baidu.baidu_voice import BaiduVoice
return BaiduVoice()
elif voice_type == 'google':
from voice.google.google_voice import GoogleVoice
return GoogleVoice()
elif voice_type == 'openai':
from voice.openai.openai_voice import OpenaiVoice
return OpenaiVoice()
raise RuntimeError

View File

@@ -1,35 +0,0 @@
"""
科大讯飞 voice service
"""
from voice.voice import Voice
# 科大讯飞语音识别
lfasr_host = 'http://raasr.xfyun.cn/api'
# 请求的接口名
api_prepare = '/prepare'
api_upload = '/upload'
api_merge = '/merge'
api_get_progress = '/getProgress'
api_get_result = '/getResult'
# 文件分片大小10M
file_piece_sice = 10485760
# ——————————————————转写可配置参数————————————————
# 参数可在官网界面https://doc.xfyun.cn/rest_api/%E8%AF%AD%E9%9F%B3%E8%BD%AC%E5%86%99.html查看根据需求可自行在gene_params方法里添加修改
# 转写类型
lfasr_type = 0
# 是否开启分词
has_participle = 'false'
has_seperate = 'true'
# 多候选词个数
max_alternatives = 0
# 子用户标识
suid = ''
class XfyunVoice(Voice):
def __init__(self):
pass
def voiceToText(self, voice_file):
pass