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 WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        SpeechSynthesizer speech = new SpeechSynthesizer();
        string words;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (textBox1.Text != "")
            {
                words = textBox1.Text;
            }
            else
            {
                words = "默认内容";
            }

            //同步读取
            speech.Speak(words);
        }
    }
}

***如 SpeechSynthesizer speech = new SpeechSynthesizer();报错时通过解决方案资源管理器 中找到引用 右键资源管理器 找到System.Speech再手动引入

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐