python 声音合成_Python 音频生成器的实现示例
使用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()
效果图
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
python 声音合成_Python 音频生成器的实现示例相关推荐
- doc python 颜色_Python wordcloud.ImageColorGenerator方法代码示例
本文整理汇总了Python中wordcloud.ImageColorGenerator方法的典型用法代码示例.如果您正苦于以下问题:Python wordcloud.ImageColorGenerat ...
- python兔子_python 实现兔子生兔子示例
如下所示: # -*- coding: utf-8 -*- # 简述:话说有一对可爱的兔子,出生后的第三个月开始,每一月都会生一对小兔子. # 当小兔子长到第三个月后,也会每个月再生一对小小兔子. # ...
- 拉格朗日插值python代码_Python实现的拉格朗日插值法示例
本文实例讲述了Python实现的拉格朗日插值法.分享给大家供大家参考,具体如下: 拉格朗日插值简单介绍 拉格朗日插值法是以法国十八世纪数学家约瑟夫·拉格朗日命名的一种多项式插值方法. 许多实际问题中都 ...
- g的python实现_Python flask.g方法代码示例
本文整理汇总了Python中flask.g方法的典型用法代码示例.如果您正苦于以下问题:Python flask.g方法的具体用法?Python flask.g怎么用?Python flask.g使用 ...
- 高斯消元法python编程_Python基于高斯消元法计算线性方程组示例
本文实例讲述了Python基于高斯消元法计算线性方程组.分享给大家供大家参考,具体如下: #!/usr/bin/env python # coding=utf-8 # 以上的信息随自己的需要改动吧 d ...
- python 二项分布_Python绘制的二项分布概率图示例
本文实例讲述了Python绘制的二项分布概率图.分享给大家供大家参考,具体如下: 问题: 抛硬币,20次,每一次朝上的概率是0.3.要求绘制连续几次正面朝上的概率图 Python代码: #-*- co ...
- set python用法_Python set()用法及代码示例
集合(Set)是由不同语言组成的序列的数学术语,Python也对其语言进行了扩展,并且可以使用set()轻松制作. set()方法用于将任何可迭代元素转换为可迭代元素的不同元素和排序序列,通常称为Se ...
- python排序问题_Python简单处理坐标排序问题示例
本文实例讲述了Python简单处理坐标排序问题.分享给大家供大家参考,具体如下: 前面一篇学了列表的冒泡排序算法,这一节利用此算法处理一下坐标排序的问题 我实现的功能是从上到下,从左到右的排序坐标点 ...
- python嵌套_Python嵌套生成器
我试图实现itertools.izip文件在Python2.7.1上.问题是我发现了一个问题,我没有解释. 解决方案1,iunzip_v1工作完美.但解决方案2.iunzip_v2,无法按预期工作.直 ...
最新文章
- appscan无法连接到服务器_SQL Server无法连接服务器
- nyoj-257-郁闷的C小加(一 )中缀式变后缀式
- 【Boost】boost库asio详解9——UDP的简单例子1
- HTML郑州宅急送试题
- Java基础02 位运算符<<、>>
- html+css个人博客_如何在互联网放置 HTML 页面
- Missing artifact com.sun:tools:jar:1.5.0解决的方法
- 数据库索引键uk_数据库SQLServer
- 【数据结构笔记08】哨兵查找、二分查找、树、儿子-兄弟表示法、二叉树的引子
- 移动端数据爬取和Scrapy框架
- 勤哲cad服务器注册机,勤哲CAD服务器
- topsis法_topsis法量化多个评价指标,找出最优方案
- 移动机顶盒migu-jt-u1 unt400c刷机 hi3798 root
- 货币金融学(2): 利率/金融市场
- watch和computer的区别
- 澳洲2022人口普查结果出炉--华人占比开始下降
- Launcher3 翻页动画详解与修改
- computed 和 watch的区别
- 锐捷服务器虚拟化技术_打造数字新基建 | 锐捷5G云小站助力行业数字化转型
- 鸿蒙系统电脑适配双面打印机,win10系统实现打印机双面打印的操作方法
热门文章
- mysql general error_SQLSTATE[HY000]: General error:
- 2022年全球市场单线激光雷达总体规模、主要生产商、主要地区、产品和应用细分研究报告
- 西门子触摸屏读取HTML,西门子触摸屏VBScript编程系列教程(3)——变量
- Date相关日期格式转换
- 快手 KSCAD 矢量绘图软件
- 用python编写彩色螺旋线
- 《需求工程——软件建模与分析》01
- 从Office2003彻底删除Acrobat工具栏按钮
- 2021年建筑电工(建筑特殊工种)考试技巧及建筑电工(建筑特殊工种)复审考试
- mtpusb设备感叹号_MTP USB安装失败完美解决方法