mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 13:28:11 +08:00
[voice] using baidu service to gen reply voice
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
"""
|
||||
baidu voice service
|
||||
"""
|
||||
import time
|
||||
from aip import AipSpeech
|
||||
from common.log import logger
|
||||
from common.tmp_dir import TmpDir
|
||||
from voice.voice import Voice
|
||||
from config import conf
|
||||
|
||||
@@ -19,4 +22,15 @@ class BaiduVoice(Voice):
|
||||
pass
|
||||
|
||||
def textToVoice(self, text):
|
||||
pass
|
||||
result = self.client.synthesis(text, 'zh', 1, {
|
||||
'spd': 5, 'pit': 5, 'vol': 5, 'per': 111
|
||||
})
|
||||
if not isinstance(result, dict):
|
||||
fileName = TmpDir().path() + '语音回复_' + str(int(time.time())) + '.mp3'
|
||||
with open(fileName, 'wb') as f:
|
||||
f.write(result)
|
||||
logger.info('[Baidu] textToVoice text={} voice file name={}'.format(text, fileName))
|
||||
return fileName
|
||||
else:
|
||||
logger.error('[Baidu] textToVoice error={}'.format(result))
|
||||
return None
|
||||
|
||||
@@ -9,6 +9,7 @@ import time
|
||||
import speech_recognition
|
||||
import pyttsx3
|
||||
from common.log import logger
|
||||
from common.tmp_dir import TmpDir
|
||||
from voice.voice import Voice
|
||||
|
||||
|
||||
@@ -42,7 +43,7 @@ class GoogleVoice(Voice):
|
||||
return "抱歉,无法连接到 Google 语音识别服务;{0}".format(e)
|
||||
|
||||
def textToVoice(self, text):
|
||||
textFile = self.tmpFilePath + '语音回复_' + str(int(time.time())) + '.mp3'
|
||||
textFile = TmpDir().path() + '语音回复_' + str(int(time.time())) + '.mp3'
|
||||
self.engine.save_to_file(text, textFile)
|
||||
self.engine.runAndWait()
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user