欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > C# >内容正文

C#

C#实现语音合成功能

发布时间:2024/3/24 C# 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 C#实现语音合成功能 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1、添加winfrom应用程序

2、添加语音合成引用 System.Speech

3、在winfrom窗体中添加控件,此处用了Button和textbox控件。

4、在代码中添加引用using System.Speech.Synthesis;

4、执行代码

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; using System.Speech.Synthesis;namespace WindowsFormsApplication1 {public partial class FrmVoiceSynthesis : Form{public FrmVoiceSynthesis(){InitializeComponent();}//实例化语音合成SpeechSynthesizer speech = new SpeechSynthesizer();//添加接收文本字段string text;private void button1_Click(object sender, EventArgs e){if (textBox1.Text != ""){text = textBox1.Text;}else{text = "请输入文字";}speech.Speak(text);}} }

 

总结

以上是生活随笔为你收集整理的C#实现语音合成功能的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。