zoukankan      html  css  js  c++  java
  • C# 语音技术

    1、使用DotNetSpeech.dll。

     1 1、使用DotNetSpeech.dll。
     2 
     3 /// <summary>
     4 
     5 /// 朗读
     6 /// </summary>
     7 /// <param name="text">要朗读的文本</param>
     8 private void Read(string text)
     9 {
    10     SpVoice sv = new SpVoice();
    11     sv.Rate = 0;//设置朗读速度
    12     SpeechVoiceSpeakFlags SSF = SpeechVoiceSpeakFlags.SVSFlagsAsync;
    13     sv.Speak(text, SSF);
    14 }
    15 /// <summary>
    16 /// 生成声音文件
    17 /// </summary>
    18 /// <param name="text">要朗读的文本</param>
    19 /// <param name="filePath">生成声音文件的路径</param>
    20 /// <param name="fileName">生成声音文件的名称</param>
    21 private void CreateFile(string text, string filePath,string fileName)
    22 {
    23     if (!Directory.Exists(filePath))
    24         Directory.CreateDirectory(filePath);
    25     SpVoice sv = new SpVoice();
    26     SpeechVoiceSpeakFlags SVSF = SpeechVoiceSpeakFlags.SVSFlagsAsync;
    27     SpeechStreamFileMode SSFM = SpeechStreamFileMode.SSFMCreateForWrite;
    28     SpFileStream SFS = new SpFileStream();
    29     SFS.Open(filePath+fileName, SSFM, false);
    30     sv.AudioOutputStream = SFS;
    31     sv.Speak(text, SVSF);
    32     sv.WaitUntilDone(System.Threading.Timeout.Infinite);
    33     SFS.Close();
    34 }
    35 2、 使用System.Speech
    36 
    37 SpeechSynthesizer ss = new SpeechSynthesizer();
    38 //播放
    39 if (ss != null)
    40 {
    41     ss.Dispose();
    42     ss.SpeakAsync("朗读的文本");
    43 }
    44 //暂停
    45 if (ss.State == SynthesizerState.Speaking)
    46 {
    47     ss.Pause();
    48 }
    49 //继续
    50 if (reader.State == SynthesizerState.Paused)
    51 {
    52     ss.Resume();
    53 }
    54 //停止
    55 if (ss != null)
    56 {
    57     ss.Dispose();
    58 } 

      收集整理,非原创。转载:https://www.cnblogs.com/sydeveloper/archive/2013/05/29/3107090.html

  • 相关阅读:
    git中文输入显示问题
    how to write a DLL/SO in C/C++ for Python
    python,ctypes
    vc++,dll,lib文件百科
    c++ singleton
    build python on windows
    web前端后端
    动态链接库*.so的编译与使用
    qt,ui,QUiLoader
    qt,script
  • 原文地址:https://www.cnblogs.com/liuzz/p/14755616.html
Copyright © 2011-2022 走看看