合成语音 TTS

 

弄了一天的合成语音 感觉好难受,明明这么简单的事情非弄得要这么复杂....

引入命名空间

或者

导入命名空间

代码:

复制代码
using System;
using System.Collections.Generic;
using System.Speech.Synthesis;
namespace TheSpeeCh
{
    class Program
    {
        private static SpeechSynthesizer speech;

        static List<VoiceInfo> voiceList = new List<VoiceInfo>();

        /// <summary>
        /// 音量
        /// </summary>
        private static int Volumevalue = 100;
        static void Main(string[] args)
        {
            speech = new SpeechSynthesizer();
            getVoiceInfos();
            Speak($@"朕统六国,天下归一,筑长城以镇九州龙脉,卫我大秦、护我社稷。朕以始皇之名在此立誓!朕在,当守土开疆,扫平四夷,定我大秦万世之基!朕亡,亦将身化龙魂,佑我华夏永世不衰!此誓,日月为证,天地共鉴,仙魔鬼神共听之!");
            Console.Read();
        }
        public static List<VoiceInfo> getVoiceInfos()
        {
           

            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {
                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    voiceList.Add(voice.VoiceInfo);
                }
            }
            return voiceList;
        }
        public static void Speak(string Content) {
           
            speech.Rate = 1;//语速
            string Name;
            if (!voiceList[0].AdditionalInfo.TryGetValue("Name",out Name))
                return;
            speech.SelectVoice(Name);//设置播音员
            speech.Volume = Volumevalue;//音量
            speech.SpeakAsync(Content);//语音阅读方法
        }
    }
}
复制代码

 

如果包这个错误  表示没有安装语音包

语音包下载地址

http://www.443w.com/tts/?post=2

真是一个好网站

 

同时也支持导出语音到文件流

表示可以做出C/S形式

 

微软 API

https://msdn.microsoft.com/en-us/library/ms723627%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

 

posted @   AnAng  阅读(342)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示