C#文字播放语音功能System.Speech类库的使用

本文介绍了如何利用.NET框架中的System.Speech类库,在C#项目中实现文字到语音的功能。通过下载dll文件,创建WinForm项目并引用System.Speech库,调用Synthesis.SpeechSynthesizer()方法,即可完成文字播放为语音的转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.Net里面自带了一个语音类库:System.Speech,调用系统的语音功能,就能实现string到语音的转换。

首先呢,我们要下载System.Speech的dll

然后新建项目SpeechDome,这里我用的是WinForm,当然你也可以用其他的。

引用System.Speech

调用程序集下面的Synthesis.SpeechSynthesizer();

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;
using System.Speech.Synthesis;

namespace SpeechDome
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //实例化SpeechSynthesizer类
            var reader = new System.Speech.Synthesis.SpeechSynthesizer();
           
            //要播放的语音
            var yuying = "我,是一个,菜鸟……程序员!";

            
            //异步使用字符串内容的语言,播放
            reader.SpeakAsync(yuying);
        }

    }
}

打完收工。

我是云中小生,代码之外,诗和远方

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.NET修仙日记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值