DotNetSpeech.dll的使用
语音是人类最自然的交互方式,也是现阶段软件用户界面发展的最高目标。微软公司一直积极推动语音技术的发展,并且公布了语音开发平台Speech SDK帮助开发人员实现语音应用。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using DotNetSpeech;
namespace SpeechApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button ButtonSynthesis;
private System.Windows.Forms.Button ButtonTTStoWave;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.ButtonSynthesis = new System.Windows.Forms.Button();
this.ButtonTTStoWave = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(272, 144);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "请输入要合成的文本";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 24);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(256, 112);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "欢迎光临Lion互动网络";
//
// ButtonSynthesis
//
this.ButtonSynthesis.CausesValidation = false;
this.ButtonSynthesis.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.ButtonSynthesis.Location = new System.Drawing.Point(24, 160);
this.ButtonSynthesis.Name = "ButtonSynthesis";
this.ButtonSynthesis.TabIndex = 1;
this.ButtonSynthesis.Text = "朗 读";
this.ButtonSynthesis.Click += new System.EventHandler(this.ButtonSynthesis_Click);
//
// ButtonTTStoWave
//
this.ButtonTTStoWave.CausesValidation = false;
this.ButtonTTStoWave.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.ButtonTTStoWave.Location = new System.Drawing.Point(128, 160);
this.ButtonTTStoWave.Name = "ButtonTTStoWave";
this.ButtonTTStoWave.Size = new System.Drawing.Size(136, 23);
this.ButtonTTStoWave.TabIndex = 2;
this.ButtonTTStoWave.Text = "生成声音文件(WAV)";
this.ButtonTTStoWave.Click += new System.EventHandler(this.ButtonTTStoWave_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 191);
this.Controls.Add(this.ButtonTTStoWave);
this.Controls.Add(this.ButtonSynthesis);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
this.Text = "欢迎光临Lion互动网络";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
/// <summary>
/// 朗读
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSynthesis_Click(object sender, System.EventArgs e)
{
try
{
DotNetSpeech.SpeechVoiceSpeakFlags SSF = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;
DotNetSpeech.SpVoice vo = new SpVoiceClass();
vo.Speak(this.textBox1.Text,SSF);
}
catch(System.Exception ec)
{
MessageBox.Show(ec.ToString(),"SpeechApp",MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
}
}
/// <summary>
/// 生成声音文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonTTStoWave_Click(object sender, System.EventArgs e)
{
try
{
DotNetSpeech.SpeechVoiceSpeakFlags SSF = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;
DotNetSpeech.SpVoice vo = new SpVoiceClass();
System.Windows.Forms.SaveFileDialog SFD = new System.Windows.Forms.SaveFileDialog();
SFD.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
SFD.Title = "Save to a wav file";
SFD.FilterIndex = 2;
SFD.RestoreDirectory = true;
if(SFD.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
DotNetSpeech.SpeechStreamFileMode SSFM = DotNetSpeech.SpeechStreamFileMode.SSFMCreateForWrite;
DotNetSpeech.SpFileStream SFS = new DotNetSpeech.SpFileStreamClass();
SFS.Open(SFD.FileName,SSFM,false);
vo.AudioOutputStream = SFS;
vo.Speak(this.textBox1.Text,SSF);
vo.WaitUntilDone(System.Threading.Timeout.Infinite);
SFS.Close();
}
}
catch(System.Exception ec)
{
MessageBox.Show(ec.ToString(),"SpeechApp",MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
}
}
}
}
DotNetSpeech.dll的使用相关推荐
- c# 实现文本读取,语音报警功能
c# 实现文本读取,语音报警功能 在测试软件功能过程中,由于需要操作硬件进行变位,但是操作完成后在去看监控软件有时间延迟,除非2个人配合,就想实现告警进行语音播报功能 实现方法1 [DllImport ...
- SAPI使用总结——SpVoice的使用方法
最近使用C#重做了点名系统(要用到TTS,让计算机点名)使用了SAPI,在这里总结一下SpVoice的使用方法. 要使用SAPI,首先添加引用DotNetSpeech,请自行下载DotNetSpeec ...
- java sapi.spvoice_SAPI使用总结——SpVoice的使用方法
最近使用C#重做了点名系统(要用到TTS,让计算机点名)使用了SAPI,在这里总结一下SpVoice的使用方法. 要使用SAPI,首先添加引用DotNetSpeech,请自行下载DotNetSpeec ...
- C# 文本转语音朗读
1. 利用DONET框架自带的 SpeechSynthesizer ,缺点是没有感情色彩,抑扬顿挫等. using System; using System.Collections.Generic; ...
- C#.NET使用TTS引擎实现文语转换
[转载] 本文讲述使用微软TTS5.1语音引擎(中文)实现文本阅读和音频输出为WAV完美解决方案. 网上很多文章说的是要安装SAPI.51 SDK,而这个东西有好几十M,并且用起来比较复杂.微软官方网 ...
- .net实现简单语音朗读(TTS)功能
首先,添加DotNetSpeech.dll引用,可以在这里直接下载,也可以参照这篇文章说的,在安装Speech SDK以后,在Common Files\Microsoft Shared\Speech\ ...
- C#生成音频文件以及转换成需要的格式
花了三天才做出来这么个小东西,其中碰到了好多意向不到的问题与难题,直接看代码吧还是.其中需要DotNetSpeech.dll(生成因文件)和lame_enc.dll(用于音频格式的转换)两个类库,还需 ...
- 音频文件变成html文档,C#生成音频文件以及转换成需要的格式
花了三天才做出来这么个小东西,其中碰到了好多意向不到的问题与难题,直接看代码吧还是.其中需要DotNetSpeech.dll(生成因文件)和lame_enc.dll(用于音频格式的转换)两个类库,还需 ...
- C#使用微软的TTS引擎发音
随着.net技术深入人心,越来越多的程序员开始转到.net平台上进行开发.然而,在新发布的.net speech SDK里面并没有对中文语音进行支持,目前支持中文的Speech SDK最高版本为Win ...
最新文章
- #pragma pack(n) 的作用
- 等差数列末项_等差数列末项(第n项)公式
- java中capitals,Java GlobalConfiguration.isCapitalMode方法代码示例
- 【企业管理】价值创造的两个轮子
- spring 基于xml方式配置aop
- 改bug过程中的新发现,重新认识String trim方法
- php yii2模块,Yii2 中关于模块(Modules)的使用及配置
- android ijk 播放器,ijkplayer 播放器:在Android端进行native调试
- 如何使用浏览器网络监视工具进行黑客攻击
- 火车头 php 插件,插件 - 火车采集器官方博客
- 80后年轻老板创业心经
- Windows10搭建turn服务器
- VSCode 修改系统界面和编辑面板字体大小
- mysql导出excel 科学计数法_mysql导出长数字到excel避免显示为科学记数法 解决方法...
- 欧拉函数φ(x)简要介绍及c++实现
- 51单片机中断的调用寄存器组(PSW)的作用,以及汇编堆栈的作用,堆栈指针的SP的使用方法,RAM的运行和ROM在单片机具体运行和C语言的优势和中断,定时器基础知识(上)
- UE使用(UltraEdit)
- android 语音识别 离线,Android离线语音识别 PocketSphinx
- 如何使用FME在Revit中导出IFC
- ethereum-etl学习
热门文章
- Github上如何在组织中创建代码仓库,并如何授予该组织中某个小组权限?
- mysql创建和删除用户
- python 奇偶拆分list,python拆分list,得到一个原来list的奇数list,一个原来list的偶数list...
- Codeforces Round #370 (Div. 2) A. Memory and Crow 水题
- Microsoft Azure Express Route (专线直连)到云端数据中心(2)
- Linux学习笔记——Linux磁盘管理
- golang for android
- 用于判断用户注册时,密码强度的JS代码。
- Web Intents:Google的内部WebApp互联机制
- 理解 QEMU/KVM 和 Ceph(2):QEMU 的 RBD 块驱动(block driver)