本帖最后由 ivor 于 2018-2-19 16:57 编辑
利用百度API,把文本拖放到脚本上面转换成合成语音audio.mp3。 | """ | | 如果已安装pip,执行pip install baidu-aip即可。 | | 如果已安装setuptools,执行python setup.py install即可。 | | """ | | import re | | from os import system | | from aip import AipSpeech | | from sys import argv | | | | def baiduAudio(inputStr): | | | | """ | | 你的 APPID AK SK | | APP_ID只用于演示,不保证稳定性 | | """ | | APP_ID = '10837454' | | API_KEY = 'mPHGma7u4j5N5VpxsIexBlr7' | | SECRET_KEY = 'ZDclPeFqhXlaZTjcqusF6pCgWBZ5cPGL' | | | | client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) | | | | """ | | per String 发音人选择, 0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女 | | """ | | | | | | result = client.synthesis(inputStr, 'zh', 1, { | | 'spd': 5, | | 'pit': 5, | | 'vol': 5, | | 'per': 3, | | } | | ) | | if not isinstance(result, dict): | | return result | | | | with open("audio.mp3","wb") as file: | | if (len(argv) > 1): | | with open(argv[1],"r") as textfile: | | for line in textfile: | | for i in re.split(r'[,,。.]',line): | | if re.match(r'.*(\S+).*',i): | | print("str: %s" % i) | | file.write(baiduAudio(i)) | | COPY |
|