【C#朗读文本DLL动态按钮控件组及按钮事件文本框拖放数据】2022-1-21
缘由https://bbs.csdn.net/topics/604357098 DotNetSpeech.dll下载_DotNetSpeech.dll免费版下载 - 系统之家 dotnetspeech.dll 64下载-dotnetspeech.dll下载 v10.2 官方版-IT猫扑网
下载了一个DotNetSpeech.dll,放到 \bin\Debug里,添加引用,然后直接DotNetSpeech.SpVoice sp = new DotNetSpeech.SpVoice();朗读速度(-10,10)
private void 朗读文本(string text){DotNetSpeech.SpVoice sp = new DotNetSpeech.SpVoice();DotNetSpeech.SpeechVoiceSpeakFlags sFlags = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;sp.Speak(text, sFlags);}朗读文本("解答 专用 窗体.演示 朗读 文本");
C++
#using "..\Debug\农历引用.dll"
using namespace 农历引用;string 返回月历(int 年, int 月, int 日, bool 选 = true)
{系统农历^ 农历 = gcnew 系统农历();string aa = ((CT2A)(CString)(农历->月历加载(年, 月, 日))), aaa = "";aaa.push_back(aa[8]); aaa.push_back(aa[9]); aaa.push_back(aa[10]); aaa.push_back(aa[11]);return (选 ? aa : aaa);
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 文本朗读转音频
{public partial class Form1 : Form{TextBox 录入框 = new TextBox();ToolTip 控件说明 = new ToolTip();Button[] 按钮集 = { };ImageList 图标集 = new ImageList();StatusBar 状态栏 = new StatusBar();public Form1(){InitializeComponent();this.ResizeRedraw = true;}private void Form1_Resize(object sender, EventArgs e){尺寸();}private void Form1_Load(object sender, EventArgs e){初值(); 布局(); 尺寸(); 停靠(); 跟随(); 注明(); 图标(); 事件();}private void 动态文本框_DragDrop(object sender, DragEventArgs e){录入框.Text += (System.String)e.Data.GetData(typeof(System.String));}private void 动态文本框_DragEnter(object sender, DragEventArgs e){e.Effect = (e.Data.GetDataPresent(typeof(System.String))) ? DragDropEffects.Copy : DragDropEffects.None;}private void 朗读文本单击(object sender, EventArgs e) { 朗读文本(录入框.Text); }private void 朗读文本(string text){DotNetSpeech.SpVoice sp = new DotNetSpeech.SpVoice();DotNetSpeech.SpeechVoiceSpeakFlags sFlags = DotNetSpeech.SpeechVoiceSpeakFlags.SVSFlagsAsync;sp.Speak(text, sFlags);//朗读效果不满意不复再编写}void 友情提示(string 内容) { MessageBox.Show(内容, "友情提示:"); }void 控件异步处理(Action 无返回事件){Parallel.Invoke(delegate(){this.BeginInvoke(new Action(delegate(){无返回事件();}));});}void 图标(){this.Invoke(new Action(() =>{int 循环 = 0;//ICOhttps://sc.chinaz.com/tubiao/180520455660.htmhttps://sc.chinaz.com/tubiao/948547132.htmhttps://sc.chinaz.com/tubiao/954045391.htmwhile (循环 < 11)图标集.Images.Add(Image.FromFile(@System.Environment.CurrentDirectory + "\\ICO\\BF" + 循环++.ToString() + ".ico"));}));}void 尺寸(){录入框.Size = new Size(this.Width - 24, this.Height - (状态栏.Height) - 68);}void 停靠(){状态栏.Parent = 录入框.Parent = this;按钮集.Select(按钮 => 按钮.Parent = this).ToArray();}void 跟随(){录入框.Anchor = (AnchorStyles.Top | AnchorStyles.Left);}void 布局(){录入框.Location = new Point(4, 24);按钮集.Select((按钮, 序号) => 按钮.Location = new Point(47 * 序号, 1)).ToArray();}void 注明(){控件说明.SetToolTip(录入框, "请输入数据文本以便进行朗读语音数据保存。");}void 初值(){this.BackColor = Color.Red;录入框.AllowDrop = true;录入框.Multiline = true;录入框.AcceptsReturn = true;录入框.ScrollBars = ScrollBars.Both;录入框.ImeMode = System.Windows.Forms.ImeMode.OnHalf;录入框.MaxLength = int.MaxValue;string[] 按钮名 = new string[] { "朗读", "暂停", "继续", "停止", "录制" };按钮集 = Array.ConvertAll(按钮名, 控件 => new Button()).ToArray();按钮集.Select((按钮, 序号) => 按钮.Text = 按钮名[序号]).ToArray();按钮集.Select(按钮 => 按钮.Size = new Size(47, 24)).ToArray();}void 事件(){按钮集[0].Click += new EventHandler(朗读文本单击);//按钮集[1].Click += new EventHandler(暂停单击);//按钮集[2].Click += new EventHandler(继续单击);//按钮集[3].Click += new EventHandler(停止单击);//按钮集[4].Click += new EventHandler(输出WAV单击);录入框.DragDrop += new DragEventHandler(动态文本框_DragDrop);录入框.DragEnter += new DragEventHandler(动态文本框_DragEnter);}}
}