C#基础:使用System.Speech.Synthesis离线播放/朗读文字内容

一、Nuget包

注意版本号,例如你的是NET6,那就要安装NET6版本的Nuget

二、源代码

cs 复制代码
using System.Speech.Synthesis;

class Program
{
    static void Main()
    {
        string txt = "你好世界!这里是C#文字转语音";
        PlayTxt(txt);
    }

    private static void PlayTxt(string txt)
    {

        using (var synth = new SpeechSynthesizer())
        {
            // 设置中文语音(Windows 内置)
            synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult, 0, new System.Globalization.CultureInfo("zh-CN"));
            synth.Volume = 100;    // 0-100
            synth.Rate = 0;        // -10 到 10
            synth.Speak(txt);      // 同步朗读,直到结束
        }
    }
}
相关推荐
lsswear5 小时前
Python 并发 线程
开发语言·python
郑州光合科技余经理5 小时前
国际版外卖系统:税率字段怎么和订单主流程解耦
android·java·开发语言·前端·后端·php·ai编程
软件课代表CiCi5 小时前
运行库是什么?电脑缺运行库怎么办?c++运行库缺失修复全攻略
开发语言·c++·windows·电脑·dll修复·dll丢失·运行库
Ivanqhz5 小时前
MLIR OpBuilder
开发语言·python·mlir
zxy28472253016 小时前
C# 音频倍速播放
c#·音频·naudio·soundtouch·倍速
红宝村村长7 小时前
windows笔记本双系统ubuntu设置
开发语言
菜鸟~noob2338 小时前
【电子战】第15篇:混合定位——TDOA/FDOA/AOA 联合【含matlab代码】
开发语言·matlab
Dreams_l9 小时前
死信队列和延迟队列介绍
java·开发语言
Water_Sunzhipeng10 小时前
HandyControl Demo 设置特定框架记录
c#
Zenova EdgeOS10 小时前
Python 工业边缘 redis-py 异步实战
开发语言·redis·python