快活林资源网 Design By www.csstdc.com
使用Python生成不同声音的音频
第一步先去百度AI中注册账号,在控制台中创建语音技术应用,获取AppID,API Key,Secret Key
第二步 引用
from tkinter import * from tkinter.filedialog import askdirectory from aip import AipSpeech from tkinter import ttk
第三步搭建窗体
root = Tk() root.title('生成语音') path = StringVar() pathmc=StringVar() pathnr=StringVar() Label(root,text = "保存路径:").grid(row = 0, column = 0) Entry(root, textvariable = path).grid(row = 0, column = 1) Button(root, text = "路径选择", command = selectPath).grid(row = 0, column = 3) Label(root,text = "语音名称:").grid(row = 2, column = 0) Entry(root, textvariable = pathmc).grid(row = 2, column = 1) Label(root,text = "语音内容:").grid(row = 3, column = 0) Entry(root, textvariable = pathnr).grid(row = 3, column = 1) Button(root, text = "保存", command = Save).grid(row = 4, column = 0) #下拉框 Label(root,text = "声音类型:").grid(row =1, column = 0) number = StringVar() numberChosen = ttk.Combobox(root, width=12, textvariable=number) numberChosen['values'] = ('女声', '男声', '度逍遥', '度丫丫') numberChosen.grid(column=1, row=1) numberChosen.current(0) root.mainloop()
第四步 创建方法
#保存地址 def selectPath(): path_ = askdirectory() path.set(path_) print(path_) 生成音频的参数 def Save(): switch = {'女声': 0, '男声': 1, '度逍遥': 3, '度丫丫': 4, } lx=switch.get(number.get(),"0") yuying(path.get(),pathmc.get(),pathnr.get(),lx) #生成音频 def yuying(url,title,contain,lx): APP_ID = 'XXX'#百度AI中获得 API_KEY = 'XXX' SECRET_KEY = 'XXX' client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) result = client.synthesis(contain, 'zh', 1, { 'vol': 5,'per':lx,'spd':2,# per 发音人选择, 0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女 否 }) if not isinstance(result, dict): with open(url+'\\'+title+'.mp3', 'wb') as f: f.write(result)
合起来的代码就是
from tkinter import * from tkinter.filedialog import askdirectory from aip import AipSpeech from tkinter import ttk def selectPath(): path_ = askdirectory() path.set(path_) print(path_) def Save(): switch = {'女声': 0, '男声': 1, '度逍遥': 3, '度丫丫': 4, } lx=switch.get(number.get(),"0") yuying(path.get(),pathmc.get(),pathnr.get(),lx) def yuying(url,title,contain,lx): APP_ID = 'XXX'#百度AI中获得 API_KEY = 'XXX' SECRET_KEY = 'XXX' client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) result = client.synthesis(contain, 'zh', 1, { 'vol': 5,'per':lx,'spd':2,# per 发音人选择, 0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女 否 }) if not isinstance(result, dict): with open(url+'\\'+title+'.mp3', 'wb') as f: f.write(result) root = Tk() root.title('生成语音') path = StringVar() pathmc=StringVar() pathnr=StringVar() Label(root,text = "保存路径:").grid(row = 0, column = 0) Entry(root, textvariable = path).grid(row = 0, column = 1) Button(root, text = "路径选择", command = selectPath).grid(row = 0, column = 3) Label(root,text = "语音名称:").grid(row = 2, column = 0) Entry(root, textvariable = pathmc).grid(row = 2, column = 1) Label(root,text = "语音内容:").grid(row = 3, column = 0) Entry(root, textvariable = pathnr).grid(row = 3, column = 1) Button(root, text = "保存", command = Save).grid(row = 4, column = 0) Label(root,text = "声音类型:").grid(row =1, column = 0) number = StringVar() numberChosen = ttk.Combobox(root, width=12, textvariable=number) numberChosen['values'] = ('女声', '男声', '度逍遥', '度丫丫') numberChosen.grid(column=1, row=1) numberChosen.current(0) root.mainloop()
效果图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com
暂无评论...
更新日志
2025年01月06日
2025年01月06日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]