zoukankan      html  css  js  c++  java
  • .net core 文字转语音并实现语音播放

    
    
    通过NuGet程序包引用:System.Speech如果为.net core的项目引用:Unoffical.System.Speech程序包
    引用:using System.Speech.Synthesis;
    
            /// <summary>
            /// 文字转换mp3格式音频
            /// </summary>
            /// <param name="path">保存路径</param>
            /// <param name="input">输入文本</param>
            /// <returns></returns>
            public static bool TextVonvertToMP3(string path, string input)
            {
                input = input.Trim();
                if (!string.IsNullOrWhiteSpace(input))
                {
                    using (SpeechSynthesizer reader = new SpeechSynthesizer())
                    {
                        reader.SetOutputToWaveFile(path + input + ".mp3");
                        reader.Speak(input);
                        reader.SetOutputToDefaultAudioDevice();
                        reader.Dispose();
                    }
                    return true;
                }
                return false;
            }
            /// <summary>
            /// 文字在线音频朗读
            /// </summary>
            /// <param name="readText">朗读文本</param>
            /// <returns></returns>
            public static bool TextRead(string readText)
            {
                var flag = false;
                readText = readText.Trim();
                if (!string.IsNullOrWhiteSpace(readText))
                {
                    using (SpeechSynthesizer reader = new SpeechSynthesizer())
                    {
                        reader.Speak(readText);
                        reader.Dispose();
                        flag = true;
                    }
                    return flag;
                }
                else
                {
                    return flag;
                }
            }
    Unoffical.System.Speech程序包 亲测不支持跨平台

  • 相关阅读:
    【Linux】Apache服务配置
    【Linux】LAMP环境搭建(简易版)
    【Linux】网络应用
    【Linux】系统管理
    【Linux】Linux(一)Linux常用命令
    【php】PDO
    【php】COOKIE和SESSION
    【php】面向对象(五)
    【php】面向对象(四)
    【php】面向对象(三)
  • 原文地址:https://www.cnblogs.com/s666/p/15021548.html
Copyright © 2011-2022 走看看