当前位置:网站首页 > 更多 > 编程开发 > 正文

[Python] 文字转语音保存为Mp3格式,接口:百度翻译

作者:CC下载站 日期:2020-06-21 00:00:00 浏览:44 分类:编程开发

调用的是百度翻译的接口,成品会生成到软件目录,文件名为文字的前10个字。

#-*-coding:utf-8-*-
"""
-------------------------------------------------
@Author:Lan
@Blog:www.lanol.cn
@Date:2020/6/21
@Description:I'minchargeofmyCode
-------------------------------------------------
"""
importrequests

word=input("请输入要转换的文字:")
speed=input("请输入语音的速度:")
url=f'https://fanyi.baidu.com/gettts?lan=zh&text={word}&spd={speed}&source=web'
result=requests.get(url).content
withopen(f'{word[:10]}.mp3','wb')asf:
f.write(result)
input(f"【{word}】语音成品已生成在软件根目录")


您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯