求助-语音合成-只合成最后一个单词
123ABCDF11345 发布于2019-10 浏览:1412 回复:1
0
收藏

在运行如下代码时,合成模块永远只合成最后一个词语,比如今日气温AA,风向BB,湿度CC,却只合成了“CC”,求解达

向合成模块传入的是:

('你查询的当地天气信息如下:', ('省市:', '四川成都市'), ('城市:', '成都市'), ('天气:', '阴'), ('风向:', '东'), ('风力:', '≤3'), ('湿度:', '74'))

代码:

from aip import AipSpeech
import requests
url = "https://restapi.amap.com/v3/weather/weatherInfo"
key = '6ac7d591dd02c1ab3633864c5f5e8d1a'
data = {'key': key, "city": 510100}
req = requests.post(url, data)
info = dict(req.json())
info = dict(info)
print(info)
newinfo = info['lives'][0]
tit="你查询的当地天气信息如下:"
ss="省市:",newinfo['province']+newinfo['city']
cs="城市:", newinfo['city']
co="编码:", newinfo['adcode']
tq="天气:", newinfo['weather']
qw="气温:", newinfo['temperature']+'℃'
fx="风向:", newinfo['winddirection']
fl="风力:", newinfo['windpower']
sd="湿度:", newinfo['humidity']
bgsj="报告时间:", newinfo['reporttime']

"""合成模块 """
APP_ID = '17354017'
API_KEY = 'xAhOK4OrRN1FHUpHV5yqIMdf'
SECRET_KEY = 'TGKNTQiFve2B9GXqZ60jDlf17yOznZ2s'
A=tit,ss,cs,tq,fx,fl,sd
print(A)
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result  = client.synthesis(A, 'zh', 3, {
    'vol': 15,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
    with open('a10.mp3', 'wb') as f:
        f.write(result)
        print("OK")
else:
    print("错误!")
    print(result["err_msg"])
    if result["err_no"] == 501:
        print("错误代码501,键入空白或长度大于1024")
收藏
点赞
0
个赞
共1条回复 最后由用户已被禁言回复于2022-04
#2用户已被禁言回复于2019-10

传入的代码是你自己写的,需要你自行检查。可以先使用 api demo来检测百度语音合成是否有此问题。

0
TOP
切换版块