• c# speech 文本转语言


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    using System.Speech;
    using System.Speech.Synthesis;
    using System.Threading;
    
    namespace VoiceTest
    {
        public partial class MainWind: Window
        {
            public MainWind()
            {
                InitializeComponent();
          
            }
            private SpeechSynthesizer synth = null;
            /// <summary>
            /// 返回一个SpeechSynthesizer对象
            /// </summary>
            /// <returns></returns>
            private SpeechSynthesizer GetSpeechSynthesizerInstance()
            {
                if (synth == null)
                {
                    synth = new SpeechSynthesizer();
                }
                return synth;
            }
            /// <summary>
            ///  播放
            /// </summary>
            public void Play(string text)
            {
                Thread thread = new Thread(new ParameterizedThreadStart(SaveAudio));
                thread.Start(text);
            }
            /// <summary>
            /// 保存语音文件
            /// </summary>
            /// <param name="text"></param>
            public void SaveAudio(object text)
            {
    speak(text); string outputFolderPath = "D:\voice"; if(! System.IO.Directory.Exists(outputFolderPath)){ System.IO.Directory.CreateDirectory(outputFolderPath); } synth = GetSpeechSynthesizerInstance(); string spText = text.ToString(); synth.Rate = -2; synth.Volume = 100; string filename = DateTime.Now.ToString("yyyyMMddHHmmss"); string strVoiceFile =System.IO.Path.Combine(outputFolderPath, filename + ".wav"); synth.SetOutputToWaveFile(strVoiceFile); synth.Speak(spText); synth.SetOutputToNull(); //调用语音转文字 //Thread threadVoice = new Thread(VoiceToText); //threadVoice.Start(str); }

    public void speak(string speechSounds)
    {
    SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
    SpVoice spVoice = new SpVoice();
    spVoice.Rate = spVoice.Rate - 5;
    if (spVoice.Volume < 100)
    {
    spVoice.Volume = spVoice.Volume + 10;
    }

    if (spVoice.Volume > 9)
    {
    spVoice.Volume = spVoice.Volume - 10;
    }
    spVoice.Speak(speechSounds, SpFlags);

    }

            private void button1_Click(object sender, RoutedEventArgs e)
            {
    //Play("hello swimming, today we will learn how to swimming")
                  Play("你好!今天我们将学习如何提高游泳技巧!不用太费力气哦,haha!");
            }
           
    
    
        }
    }
    

      

    参考:https://www.cnblogs.com/-maomao/p/6861447.html

  • 相关阅读:
    SVN客户端服务器搭建与使用(一)
    MyEclipse下XFire开发WebService实例
    SVN客户端服务器搭建与使用(三)
    MyEclipse中Svn插件
    Spring整合MyBatis
    MyEclipse中Properties文件中文编辑插件
    WebService的原理及概念
    字符集和字符编码(Charset & Encoding)(转)
    Android 4.0系统七大新功能(转)
    加密算法小知识
  • 原文地址:https://www.cnblogs.com/wgscd/p/9081690.html
Copyright © 2020-2023  润新知