惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
GbyAI
GbyAI
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
博客园 - Franky
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
V
Visual Studio Blog
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 叶小钗
AWS News Blog
AWS News Blog
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
V
V2EX
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Latest news
Latest news
N
News and Events Feed by Topic
The Last Watchdog
The Last Watchdog
T
Threatpost
L
Lohrmann on Cybersecurity
小众软件
小众软件
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
爱范儿
爱范儿
Google Online Security Blog
Google Online Security Blog
Forbes - Security
Forbes - Security
Attack and Defense Labs
Attack and Defense Labs
The Register - Security
The Register - Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Help Net Security
Security Latest
Security Latest
Recent Announcements
Recent Announcements
C
Check Point Blog
B
Blog
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
I
InfoQ

博客园 - WmW

C#学习牛顿迭代法开方 mysql将一个表中指定时间之后的新数据导入到另一个表中 使用具体时间和DateTime.Now运算时需要注意DateTime.Now的毫秒数 简单搭建一个 ASP.NET Core Web API + Mysql + SqlSugar demo项目 C# 学习研究CRC校验 C# 学习逆变和协变 C# 标准的Dispose模式 C# 返回Task或者Task<T>的方法中如果没有异步方法,就没必要使用async修饰 关于字节序的概念加深 C# 基于ReadOnlySequence和ReadOnlySequenceSegment的简单封装 简单接触BCD码,以及使用C#简单实现BCD转换 C# ReadOnlySequence和ReadOnlySequenceSegment简单使用 C# 输出年龄和属相列表 C# 封装了一个用来对参数值进行范围限制的泛型方法 C# 为WindowsDefender防火墙已经存在的入站规则添加IP地址 C# 将Framework4.8控制台程序注册为windows服务 C# async void 方法中使用await时外部不会等待 C# Channel学习 C# 使用字符串分割字符串 C# 一个简单的连续心率血氧压缩算法 C# 将日期时间按照ISO 8601标准转成字符串 Dapper传递参数对象时,只支持属性,无法解析字段(出现Parameter '?id' must be defined)
C# 非常简单的文字转语音实现
WmW · 2025-03-27 · via 博客园 - WmW

之前废了老大劲实现了文本转语音功能,结果发现C#官方有个非常简单的实现,泪流满面,应该是用不上了,记录一下方便后来人吧

感谢 https://zhuanlan.zhihu.com/p/32960822565

需要先在nuget中引用System.Speech包,然后就是下面的使用方式

        public void Test() {
            string text = "测试123abc_@xyz";
            //Speak(text);
            GenerateAudioFile(text, "D:\\text.wav");
        }
        /// <summary>
        /// 播放语音
        /// </summary> 
        static void Speak(string text) {
            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer()) {
                synthesizer.Speak(text);
            }
        }
        /// <summary>
        /// 生成语音文件
        /// </summary> 
        static void GenerateAudioFile(string text, string path) {
            using (SpeechSynthesizer synthesizer = new SpeechSynthesizer()) {
                using (MemoryStream stream = new MemoryStream()) {
                    synthesizer.SetOutputToWaveStream(stream); // 设置语音合成的输出目标为内存流 
                    synthesizer.Speak(text);
                    using (FileStream fileStream = new FileStream(path, FileMode.Create)) {
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.CopyTo(fileStream);
                    }
                }
            }
        }