C#WPF 语音开发教程 TTS中英文语音(男女声音)朗读 源代码下载 csdn tts(text to sound) 一步一步 教你制作语音软件 附图和源代码
C#WPF 语音开发教程 TTS中文语音朗读 一步一步 教你制作语音软件
附图和源代码
使用时,请确认电脑喇叭打开,并且不是静音额。
效果展示
一 项目准备
1.vs2012开发平台
2.微软的语音软件库
下载:http://download.csdn.net/detail/wyx100/8431269 (含实例项目源代码)
二.开发目标
制作一个语音软件,可以朗读文字;
多个语音库:男音和女音、支持英文和中文朗读;
支持选择播放设备
支持朗读语速选择
支持音量选择
三 开发过程
1.新建WpfSpeechDemo工程
文件(vs开发平台左上角)----新建(快捷方式 Ctrl+Shift+New)
2.导入微软语音库
3.建立软件界面
见开始 效果展示
4.软件功能开发
支持语音库选择
支持选择播放设备
支持朗读语速选择
支持音量选择
四 软件代码
1.界面代码
<Window x:Class="WpfSpeechDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfSpeechDemo" Height="350" Width="525">
<Grid>
<ComboBox x:Name="cmbVoices" HorizontalAlignment="Left" Margin="86,23,0,0" VerticalAlignment="Top" Width="222" SelectionChanged="cmbVoices_SelectionChanged"/>
<ComboBox x:Name="cmbAudioOut" HorizontalAlignment="Left" Margin="86,69,0,0" VerticalAlignment="Top" Width="222" SelectionChanged="cmbAudioOut_SelectionChanged"/>
<Label Content="语音库(引擎): " HorizontalAlignment="Left" Margin="0,23,0,0" VerticalAlignment="Top" Width="81"/>
<Label Content="语音输出方式: " HorizontalAlignment="Left" Margin="0,65,0,0" VerticalAlignment="Top" Width="81"/>
<Button Content="朗读|Speek" HorizontalAlignment="Left" Margin="33,119,0,0" VerticalAlignment="Top" Width="104" Click="bt_speek_Click"/>
<Button Content="停止|Stop" HorizontalAlignment="Left" Margin="170,119,0,0" VerticalAlignment="Top" Width="93" RenderTransformOrigin="2.042,0.064" Click="bt_stop_Click"/>
<TextBox Name="tbspeech" HorizontalAlignment="Left" Height="125" Margin="20,172,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="484" BorderThickness="3" Text="Wpf语音,hello world!">
<TextBox.BorderBrush>
<LinearGradientBrush EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
<GradientStop Color="#FFABADB3" Offset="0.05"/>
<GradientStop Color="#FFE2E3EA" Offset="0.07"/>
<GradientStop Color="#FF1A72C9" Offset="1"/>
</LinearGradientBrush>
</TextBox.BorderBrush>
</TextBox>
<Slider x:Name="tbarRate" Orientation="Vertical"
Minimum="0"
Maximum="10"
IsMoveToPointEnabled="True"
AutoToolTipPrecision="2" AutoToolTipPlacement="BottomRight"
TickPlacement="BottomRight"
Ticks="1, 2, 3, 4, 5, 6, 7, 8, 9,10"
IsSelectionRangeEnabled="true"
SelectionStart="1" SelectionEnd="9"
HorizontalAlignment="Left" Margin="357,51,0,0" VerticalAlignment="Top" Height="103" ValueChanged="tbarRate_ValueChanged" Background="#FFEFEBF0"/>
<Slider x:Name="trbVolume" Orientation="Vertical"
Minimum="0"
Maximum="10"
IsMoveToPointEnabled="True"
AutoToolTipPrecision="2" AutoToolTipPlacement="BottomRight"
TickPlacement="BottomRight"
Ticks="1, 2, 3, 4, 5, 6, 7, 8, 9,10"
IsSelectionRangeEnabled="true"
SelectionStart="1" SelectionEnd="9"
HorizontalAlignment="Left" Margin="426,51,0,0" VerticalAlignment="Top" Height="103" ValueChanged="trbVolume_ValueChanged" Background="#FFF2EFF3"/>
<Label Content="语速" HorizontalAlignment="Left" Margin="350,19,0,0" VerticalAlignment="Top" Width="35" />
<Label Content="音量" HorizontalAlignment="Left" Margin="418,19,0,0" VerticalAlignment="Top" Width="35"/>
</Grid>
</Window>
2.功能代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DotNetSpeech;//cs文件中引入库
namespace WpfSpeechDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
SpVoice speech = new SpVoice();
int speechRate = 0;
int volume = 70;
public MainWindow()
{
InitializeComponent();
init();
}
private void init()
{
//初始化语音引擎列表
foreach (ISpeechObjectToken Token in speech.GetVoices(string.Empty, string.Empty))
{
cmbVoices.Items.Add(Token.GetDescription(49));
}
//取得音频输出列表
foreach (ISpeechObjectToken AudioOut in speech.GetAudioOutputs(string.Empty, string.Empty))
{
cmbAudioOut.Items.Add(AudioOut.GetDescription(49));
}
cmbVoices.SelectedIndex = 0;
cmbAudioOut.SelectedIndex = 0;
tbarRate.Value = speechRate;
trbVolume.Value = volume;
}
private void tbarRate_Scroll(object sender, EventArgs e)
{
speech.Rate = (int)tbarRate.Value;
}
private void trbVolume_Scroll(object sender, EventArgs e)
{
speech.Volume = (int)trbVolume.Value;
}
private void cmbVoices_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
speech.Voice = speech.GetVoices(string.Empty, string.Empty).Item(cmbVoices.SelectedIndex);
}
private void cmbAudioOut_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
speech.AudioOutput = speech.GetAudioOutputs(string.Empty, string.Empty).Item(cmbAudioOut.SelectedIndex);
}
private void bt_speek_Click(object sender, EventArgs e)
{
//终止先前朗读,如果有
speech.Speak(" ", SpeechVoiceSpeakFlags.SVSFlagsAsync);
speech.Speak(tbspeech.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
private void bt_stop_Click(object sender, EventArgs e)
{
speech.Speak("", SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
private void tbarRate_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
speech.Rate = (int)e.NewValue;
}
private void trbVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
speech.Volume = (int)e.NewValue;
}
}
}
五 编译和运行
C#WPF 语音开发教程 TTS中英文语音(男女声音)朗读 源代码下载 csdn tts(text to sound) 一步一步 教你制作语音软件 附图和源代码相关推荐
- WPF DataGrid 和LINQ to SQL示例程序之一 (提供源代码下载)
WPF DataGrid 和LINQ to SQL示例程序之一 (提供源代码下载) WPF DataGrid 系列示例程序,由浅入深逐步介绍如何在WPF 应用程序中使用新的DataGrid 控件.本篇 ...
- 谷歌tts android手机自带引擎,自动下载android TTS引擎
Is there a way to install a language automatically? 是的,但这不会自动发生(未经用户同意),如docs所述: Since the installat ...
- WPF 3D开发教程(一)
一.3D基础知识 1.1 坐标系 我们知道,在2D平面绘图时,WPF使用的坐标系(其实计算机上的图形处理一般都是这样)是以屏幕左上角为原点,向右为x轴正方向,向下为y轴正方向.而WPF的3D坐标系,取 ...
- WPF 3D开发教程(三)
三.3D模型 3D模型就是物体,是3D开发中的主角.我们在第一部分提过,使用三角网格法表示面.而三角形由顶点组成,每个面又有一定的材质,这些都是怎么表示的呢?三角形面由Positions和Triang ...
- WPF UI开发教程LinkButton链接按钮
开发应用软件也需要像网页,加个超链接样式按钮.和网页需求一样需要把按钮字体颜色变蓝色,加上下划线,鼠标放上变成手型就行啦. 直接上按钮样式代码,需要加更多依赖属性可以修改到样式. <Style ...
- WPF 3D开发教程(四)
四.实战:展示一个圆柱体 4.1 圆柱体分解 我们知道,3D模型是用三角形表示的,那一个圆该如何表示呢?其实用的就是割圆法,也就是用一个近似的多边形就表示一个圆.下图展示了10.20.50个顶点的正多 ...
- java调用espeak_espeak-example Java for windows文本转语音,用 引擎 Other systems 其他 244万源代码下载- www.pudn.com...
文件名称: espeak-example下载 收藏√ [ 5 4 3 2 1 ] 开发工具: Java 文件大小: 1286 KB 上传时间: 2015-10-04 下载次数: 0 提 供 ...
- 微信小程序开发教程(一)--注册小程序、下载开发工具及新建工程
从本章开始,我们将讲解微信小程序的简单开发流程,我将尽量使用简洁的语言,逐个步骤详细讲解,让大家都能跟得上,也希望和大家交流学习. 注册 首先,开发小程序需要先在微信注册. 打开网页:https:// ...
- 文顶顶iOS开发博客链接整理及部分项目源代码下载
网上的iOS开发的教程很多,但是像cnblogs博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程却很难找.如果你是初学者,在学习了斯坦福iOS7公开课 ...
最新文章
- 【C++】【十二】排序实现及思路
- linux 通过命令行获取本机外网IP
- 一篇文章带你了解python装饰器
- Django:快速搭建简单的Blog
- 云桌面部署_云桌面时代降临-青椒云工作站
- gvim最简化设置,去掉工具栏和菜单栏
- deepinu盘制作工具_用U盘装系统,试试这款多系统启动盘制作工具!
- ubunt 文件permission denied问题的解决
- 深入浅出WPF知识点汇总二
- 【TBSchedule】TBSchedule应用实战手册
- git提交代码至码云
- win10或者win11如何将中文用户名更改成英文用户名文件几乎无损(适合终端显示的中文名)亲测可用(操作有风险运行需谨慎)
- 请大家帮忙看下这个shader的问题:
- 数据库读写分离与分库分表
- 大学四年努力学好编程
- SpringCloud+Kubernetes 微服务容器化交付实战(9):JFrog Artifactory安装 配置
- [20210429更新]软件方法(下)分析和设计 第8章 连载
- 爬虫(1)-正则化表达式爬取猫眼电影排行榜前100部电影
- php股票波动率计算公式,因子选股系列:波动率因子的改进,异质波动率
- 记录一次Centos磁盘空间占满的解决办法
热门文章
- android 怎么输出人民币符号¥
- Linux第一章:3.VMTools设置共享文件夹
- day24_SQL语言(四)约束和策略
- 第四章 第一节:函数下
- 上古卷轴5mo初始化python失败_NIF Texcase Fixer Script-适用于Linux的紫色和绝对引用修复程序...
- python初中可以学吗_初中学历零基础想转行Python,能否学会?Python难吗?
- Go 并发编程之并发基础
- 查看 WIFI 密码
- GraphQL的探索之路 – SpringBoot集成GraphQL之Mutation篇四 - 第317篇
- 计算机绘画小房子教案,可爱的小房子──《画方形和圆形》教学案例