标签:data cpi pat pre 函数 int get 故事 instance
主要内容: 博客drogonfire博客
语音合成: ai.baidu.com.. 查看文档的具体内容.
语音识别: ai.baidu.com.. 查看文档的具体内容.
智能机器人: www.tuling123.com
from aip import AipSpeech, AipNlp
APP_ID = ‘15217769‘
API_KEY = ‘j6C0iHttxaLcPIVqlynHyuP9‘
SECRET_KEY = ‘Symuy2zsS3LB2N4Lfr5ic7rTKCb6M26W ‘
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
nlp_client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis(‘美好的一天‘, ‘zh‘, 1, {
‘vol‘: 5,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
with open(‘auido.mp3‘, ‘wb‘) as f:
f.write(result)
import os
# 读取文件
def get_file_content(filePath):
os.system(f"ffmpeg -y -i {filePath} -acodec pcm_s16le -f s16le -ac 1 -ar 16000 {filePath}.pcm")
with open(f"{filePath}.pcm", ‘rb‘) as fp:
return fp.read()
# 识别本地文件
res = client.asr(get_file_content(‘1.m4a‘), ‘pcm‘, 16000, {
‘dev_pid‘: 1536,
})
print(res)
Q = res.get("result")[0]
print(Q)
if nlp_client.simnet(Q, "讲个故事吧").get("score") >= 0.7:
# 语音合成
A = "当然好了."
result = client.synthesis(A, ‘zh‘, 1, {
"per": 4,
"pit": 8,
"spd": 4,
‘vol‘: 5,
})
if not isinstance(result, dict):
with open(‘auido.mp3‘, ‘wb‘) as f:
f.write(result)
# 读取声音,
os.system(‘auido.mp3‘)
else:
import tuling
A = tuling.rbots("讲个故事吧", "haha")
result =client.synthesis(A, ‘zh‘, 1, {
"per": 4,
"pit": 8,
"spd": 4,
‘vol‘: 5,
})
if not isinstance(result, dict):
with open(‘auido.mp3‘, ‘wb‘) as f:
f.write(result)
os.system(‘auido.mp3‘)
函数:
import requests
url = "http://openapi.tuling123.com/openapi/api/v2"
data = {
"reqType":0,
"perception": {
"inputText": {
"text": "郑州"
},
},
"userInfo": {
"apiKey": "dd4648b191304eecaabd82df63e7e354",
"userId": "wonderful"
}
}
def rbots(text, uid):
data["perception"]["inputText"]["text"] = text
data["userInfo"]["userId"]= uid
res = requests.post(url, json=data)
res_json = res.json()
return res_json.get("results")[0].get("values").get("text")
标签:data cpi pat pre 函数 int get 故事 instance
原文地址:https://www.cnblogs.com/gyh412724/p/10151720.html