实例介绍
【实例简介】含 c# c demo
【实例截图】
【实例截图】
【核心代码】
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using IFLYTTSLib;
namespace CSharpSample
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox_syntext;
private System.Windows.Forms.Button button_Synth;
private System.Windows.Forms.Button button_Pause;
private System.Windows.Forms.CheckBox checkBox_SynMod;
private System.Windows.Forms.CheckBox checkBox_OutPut;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox_Param;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label Label5;
private AxIFLYTTSLib.AxTTSCtrl axTTSCtrl1;
private System.Windows.Forms.TextBox textBox_Speed;
private System.Windows.Forms.TextBox textBox_Volume;
private System.Windows.Forms.TextBox textBox_Pitch;
private System.Windows.Forms.TextBox textBox_FileName;
private System.Windows.Forms.ComboBox comboBox_DFmt;
private System.Windows.Forms.TextBox textBox_Event;
/// <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 Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox_syntext = new System.Windows.Forms.TextBox();
this.button_Synth = new System.Windows.Forms.Button();
this.button_Pause = new System.Windows.Forms.Button();
this.checkBox_SynMod = new System.Windows.Forms.CheckBox();
this.checkBox_OutPut = new System.Windows.Forms.CheckBox();
this.textBox_FileName = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.groupBox_Param = new System.Windows.Forms.GroupBox();
this.textBox_Pitch = new System.Windows.Forms.TextBox();
this.textBox_Volume = new System.Windows.Forms.TextBox();
this.textBox_Speed = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.comboBox_DFmt = new System.Windows.Forms.ComboBox();
this.Label5 = new System.Windows.Forms.Label();
this.axTTSCtrl1 = new AxIFLYTTSLib.AxTTSCtrl();
this.textBox_Event = new System.Windows.Forms.TextBox();
this.groupBox_Param.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.axTTSCtrl1)).BeginInit();
this.SuspendLayout();
//
// textBox_syntext
//
this.textBox_syntext.Location = new System.Drawing.Point(16, 8);
this.textBox_syntext.Multiline = true;
this.textBox_syntext.Name = "textBox_syntext";
this.textBox_syntext.Size = new System.Drawing.Size(328, 80);
this.textBox_syntext.TabIndex = 0;
this.textBox_syntext.Text = "欢迎使用科大讯飞语音合成系统";
//
// button_Synth
//
this.button_Synth.Location = new System.Drawing.Point(264, 312);
this.button_Synth.Name = "button_Synth";
this.button_Synth.Size = new System.Drawing.Size(80, 24);
this.button_Synth.TabIndex = 5;
this.button_Synth.Text = "播放";
this.button_Synth.Click = new System.EventHandler(this.button_Synth_Click);
//
// button_Pause
//
this.button_Pause.Location = new System.Drawing.Point(264, 344);
this.button_Pause.Name = "button_Pause";
this.button_Pause.Size = new System.Drawing.Size(80, 24);
this.button_Pause.TabIndex = 6;
this.button_Pause.Text = "暂停";
this.button_Pause.Click = new System.EventHandler(this.button_Pause_Click);
//
// checkBox_SynMod
//
this.checkBox_SynMod.Location = new System.Drawing.Point(16, 192);
this.checkBox_SynMod.Name = "checkBox_SynMod";
this.checkBox_SynMod.Size = new System.Drawing.Size(120, 24);
this.checkBox_SynMod.TabIndex = 0;
this.checkBox_SynMod.Text = "同步模式";
//
// checkBox_OutPut
//
this.checkBox_OutPut.Location = new System.Drawing.Point(16, 224);
this.checkBox_OutPut.Name = "checkBox_OutPut";
this.checkBox_OutPut.Size = new System.Drawing.Size(88, 24);
this.checkBox_OutPut.TabIndex = 9;
this.checkBox_OutPut.Text = "合成到文件";
//
// textBox_FileName
//
this.textBox_FileName.Location = new System.Drawing.Point(104, 224);
this.textBox_FileName.Name = "textBox_FileName";
this.textBox_FileName.Size = new System.Drawing.Size(240, 21);
this.textBox_FileName.TabIndex = 10;
this.textBox_FileName.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(216, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(40, 16);
this.label4.TabIndex = 2;
this.label4.Text = "音调:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(112, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(40, 16);
this.label3.TabIndex = 1;
this.label3.Text = "音量:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 16);
this.label2.TabIndex = 0;
this.label2.Text = "语速:";
//
// groupBox_Param
//
this.groupBox_Param.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox_Pitch,
this.textBox_Volume,
this.textBox_Speed,
this.label1,
this.comboBox_DFmt,
this.label4,
this.label3,
this.label2});
this.groupBox_Param.Location = new System.Drawing.Point(16, 96);
this.groupBox_Param.Name = "groupBox_Param";
this.groupBox_Param.Size = new System.Drawing.Size(328, 88);
this.groupBox_Param.TabIndex = 8;
this.groupBox_Param.TabStop = false;
this.groupBox_Param.Text = "参数设置";
//
// textBox_Pitch
//
this.textBox_Pitch.Location = new System.Drawing.Point(264, 24);
this.textBox_Pitch.Name = "textBox_Pitch";
this.textBox_Pitch.Size = new System.Drawing.Size(48, 21);
this.textBox_Pitch.TabIndex = 7;
this.textBox_Pitch.Text = "0";
//
// textBox_Volume
//
this.textBox_Volume.Location = new System.Drawing.Point(152, 24);
this.textBox_Volume.Name = "textBox_Volume";
this.textBox_Volume.Size = new System.Drawing.Size(48, 21);
this.textBox_Volume.TabIndex = 6;
this.textBox_Volume.Text = "0";
//
// textBox_Speed
//
this.textBox_Speed.Location = new System.Drawing.Point(48, 24);
this.textBox_Speed.Name = "textBox_Speed";
this.textBox_Speed.Size = new System.Drawing.Size(48, 21);
this.textBox_Speed.TabIndex = 5;
this.textBox_Speed.Text = "0";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 4;
this.label1.Text = "音频数据格式:";
//
// comboBox_DFmt
//
this.comboBox_DFmt.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox_DFmt.Items.AddRange(new object[] {
"缺省格式",
"TTS_ADF_PCM8K8B1C",
"TTS_ADF_PCM16K8B1C",
"TTS_ADF_PCM8K16B1C",
"TTS_ADF_PCM16K16B1C",
"TTS_ADF_PCM6K8B1C",
"TTS_ADF_PCM6K16B1C"});
this.comboBox_DFmt.Location = new System.Drawing.Point(96, 56);
this.comboBox_DFmt.Name = "comboBox_DFmt";
this.comboBox_DFmt.Size = new System.Drawing.Size(216, 20);
this.comboBox_DFmt.TabIndex = 3;
//
// Label5
//
this.Label5.Location = new System.Drawing.Point(16, 256);
this.Label5.Name = "Label5";
this.Label5.Size = new System.Drawing.Size(64, 16);
this.Label5.TabIndex = 12;
this.Label5.Text = "事件回调:";
//
// axTTSCtrl1
//
this.axTTSCtrl1.Enabled = true;
this.axTTSCtrl1.Location = new System.Drawing.Point(24, 16);
this.axTTSCtrl1.Name = "axTTSCtrl1";
this.axTTSCtrl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axTTSCtrl1.OcxState")));
this.axTTSCtrl1.Size = new System.Drawing.Size(30, 30);
this.axTTSCtrl1.TabIndex = 16;
this.axTTSCtrl1.SentenceStart = new AxIFLYTTSLib._ISpeakEvents_SentenceStartEventHandler(this.axTTSCtrl1_SentenceStart);
this.axTTSCtrl1.SpeakStart = new AxIFLYTTSLib._ISpeakEvents_SpeakStartEventHandler(this.axTTSCtrl1_SpeakStart);
this.axTTSCtrl1.SpeakEnd = new AxIFLYTTSLib._ISpeakEvents_SpeakEndEventHandler(this.axTTSCtrl1_SpeakEnd);
this.axTTSCtrl1.Progress = new AxIFLYTTSLib._ISpeakEvents_ProgressEventHandler(this.axTTSCtrl1_Progress);
this.axTTSCtrl1.SentenceEnd = new AxIFLYTTSLib._ISpeakEvents_SentenceEndEventHandler(this.axTTSCtrl1_SentenceEnd);
this.axTTSCtrl1.ErrorNotify = new AxIFLYTTSLib._ISpeakEvents_ErrorNotifyEventHandler(this.axTTSCtrl1_ErrorNotify);
//
// textBox_Event
//
this.textBox_Event.Location = new System.Drawing.Point(24, 272);
this.textBox_Event.Multiline = true;
this.textBox_Event.Name = "textBox_Event";
this.textBox_Event.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox_Event.Size = new System.Drawing.Size(224, 96);
this.textBox_Event.TabIndex = 15;
this.textBox_Event.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(360, 381);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox_Event,
this.axTTSCtrl1,
this.Label5,
this.textBox_FileName,
this.checkBox_OutPut,
this.groupBox_Param,
this.button_Pause,
this.button_Synth,
this.textBox_syntext,
this.checkBox_SynMod});
this.Name = "Form1";
this.Load = new System.EventHandler(this.Form1_Load);
this.Closed = new System.EventHandler(this.Form1_Closed);
this.groupBox_Param.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.axTTSCtrl1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.comboBox_DFmt.SelectedIndex = 0;
//改为正确的合成系统路径
//axTTSCtrl1.Executor = "C:\\iFly Info Tek\\InterPhonic C&E Ver2.1\\Bin\\iflytts.dll";
}
private void button_Synth_Click(object sender, System.EventArgs e)
{
textBox_Event.Clear();
if( button_Synth.Text == "播放" )
{
//设置TTSCtrl的Speed、Pitch、Volume属性
axTTSCtrl1.Speed = int.Parse(textBox_Speed.Text);
axTTSCtrl1.Pitch = int.Parse(textBox_Pitch.Text);
axTTSCtrl1.Volume = int.Parse(textBox_Volume.Text);
//设置TTSCtrl的AudioFmt属性
IFLYTTSLib.enAudioFmt eAudio = IFLYTTSLib.enAudioFmt.eAdfDefault;
switch( comboBox_DFmt.SelectedIndex )
{
case 1:
eAudio = IFLYTTSLib.enAudioFmt.eAdfPcm8k8b;
break;
case 2:
eAudio = IFLYTTSLib.enAudioFmt.eAdfPcm16k8b;
break;
case 3:
eAudio = IFLYTTSLib.enAudioFmt.eAdfPcm8k16b;
break;
case 4:
eAudio = IFLYTTSLib.enAudioFmt.eAdfPcm16k16b;
break;
case 5:
eAudio = IFLYTTSLib.enAudioFmt.eAdfPcm6k8b;
break;
case 6:
eAudio = IFLYTTSLib.enAudioFmt.eAdfPcm6k16b;
break;
case 0:
default:
break;
}
axTTSCtrl1.AudioDataFmt = eAudio;
//设置SyncMod属性(同步/异步)
axTTSCtrl1.SyncMod = Convert.ToInt32(checkBox_SynMod.Checked);
//设置Output属性(音频设备/文件),默认为“#Audio”
if( checkBox_OutPut.Checked )
{
axTTSCtrl1.Output = textBox_FileName.Text;
}
//调用Speak方法进行合成
axTTSCtrl1.Speak(textBox_syntext.Text,IFLYTTSLib.enSpeakFlags.esfText,0);
}
else
{
//调用Stop方法停止合成
axTTSCtrl1.Stop();
button_Pause.Text = "暂停";
}
}
private void button_Pause_Click(object sender, System.EventArgs e)
{
if( button_Pause.Text == "暂停" && Convert.ToBoolean(axTTSCtrl1.Busy) )
{
button_Pause.Text = "继续";
axTTSCtrl1.Pause();
}
else if( button_Pause.Text == "继续" && Convert.ToBoolean(axTTSCtrl1.Busy) )
{
button_Pause.Text = "暂停";
axTTSCtrl1.Resume();
}
}
private void axTTSCtrl1_SpeakStart(object sender, AxIFLYTTSLib._ISpeakEvents_SpeakStartEvent e)
{
textBox_Event.AppendText("合成开始!" " 用户数据是:" e.user.ToString() "\n");
button_Synth.Text = "停止";
}
private void axTTSCtrl1_SpeakEnd(object sender, AxIFLYTTSLib._ISpeakEvents_SpeakEndEvent e)
{
textBox_Event.AppendText("合成结束,结束的原因是" string.Format(e.eReason.ToString()) " 用户数据是:" e.user.ToString() "\n");
button_Synth.Text = "播放";
}
private void axTTSCtrl1_SentenceEnd(object sender, AxIFLYTTSLib._ISpeakEvents_SentenceEndEvent e)
{
textBox_Event.AppendText( "合成结束位置" string.Format(e.nEndPos.ToString()) " 用户数据是:" e.user.ToString() "\n");
}
private void axTTSCtrl1_SentenceStart(object sender, AxIFLYTTSLib._ISpeakEvents_SentenceStartEvent e)
{
textBox_Event.AppendText("合成开始位置" string.Format(e.nStartPos.ToString()) " 用户数据是:" e.user.ToString() "\n");
}
private void axTTSCtrl1_Progress(object sender, AxIFLYTTSLib._ISpeakEvents_ProgressEvent e)
{
textBox_Event.AppendText("当前进度:" (int)(e.fPercent) "%" " 用户数据是:" e.user.ToString() "\n");
}
private void axTTSCtrl1_ErrorNotify(object sender, AxIFLYTTSLib._ISpeakEvents_ErrorNotifyEvent e)
{
textBox_Event.AppendText("合成出错!错误原因是:" e.nErrCode);
}
private void Form1_Closed(object sender, System.EventArgs e)
{
axTTSCtrl1.Stop();
}
}
}
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)
支持(0) 盖楼(回复)