1.使用百度的接口
1)安装pip install baidu-aip#然后发现安装到系统python路径中,使用虚拟环境的pip
2)百度智能云->创建应用->...->管理应用->记下
AppID
|
API Key
|
Secret Key
|
---|
from aip import AipSpeech
import os
""" 你的 APPID AK SK """
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
f = open("14.1.txt", "r", encoding='UTF8')
# str = f.read(1000)
# print(str)
f1 = open('14.1.mp3', 'ab')
while True:
str = f.read(1000)
if not str:
break
result = client.synthesis(str, 'zh', 1, { 'vol': 4,'per':5,})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
f1.write(result)
f.close()
f1.close()