zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    JDBC和Ibatis中的Date,Time,Timestamp处理
    Spring Boot 配置定时任务
    SpringBoot Caused by: java.lang.NoClassDefFoundError: org/apache/tomcat/util/descriptor/tld/TldParser
    spring boot 使用thymeleaf模版 报错:org.thymeleaf.exceptions.TemplateInputException
    mybatis 报错: Invalid bound statement (not found)
    spring boot
    通过枚举enum实现单例
    lucene Filter过滤器
    javaweb url
    mysql 报错:java.lang.OutOfMemoryError: Java heap space
  • 原文地址:https://www.cnblogs.com/wgscd/p/9081690.html
Copyright © 2011-2022 走看看