• 语音识别WAV To String


    由于项目需要在网上找了好多,修改下,下面是个样例,大家看下

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using DotNetSpeech;
     5 using System.Threading;
     6 
     7 namespace TestSpRecognize
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             WavToCaption obj = new WavToCaption();
    14             obj.openWAV();
    15         }
    16     }
    17     class WavToCaption
    18     {
    19         private SpInProcRecoContext m_wavRecoContext;
    20         private ISpeechRecoGrammar m_Grammar;
    21         private SpFileStream m_infile;
    22 
    23         public WavToCaption()
    24         {
    25             SpInprocRecognizer recognizer = new SpInprocRecognizer();
    26             m_wavRecoContext = (SpInProcRecoContext)recognizer.CreateRecoContext();
    27             m_wavRecoContext.RetainedAudio = SpeechRetainedAudioOptions.SRAORetainAudio;
    28             m_infile = new SpFileStreamClass();
    29             m_infile.Format.GetWaveFormatEx();
    30         }
    31 
    32         public void openWAV()
    33         {
    34             m_Grammar = m_wavRecoContext.CreateGrammar(0);
    35             m_Grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
    36 
    37             //register an event handler everytime the engine recognizes something from teh file
    38             m_wavRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
    39 
    40 
    41             //register an event handler when the engine is done reading the  file
    42             m_wavRecoContext.EndStream += new _ISpeechRecoContextEvents_EndStreamEventHandler(RecoContext_EndRecognition);
    43 
    44             //try to open the file
    45             try
    46             {
    47                 m_infile.Open(@"c:\1.wav",
    48                 SpeechStreamFileMode.SSFMOpenForRead, false);
    49                 Console.Out.WriteLine("Succesfully opened file");
    50             }
    51             catch (Exception e)
    52             {
    53                 Console.Out.Write("Could not find file");
    54                 return;
    55             }
    56 
    57             //this makes it so the engine recognizes we're reading in from a  wav, vs. a microphone
    58             m_wavRecoContext.Recognizer.AudioInputStream = m_infile;
    59 
    60             //starts reading the file here
    61             m_Grammar.DictationSetState(SpeechRuleState.SGDSActive);
    62             Console.ReadKey();
    63 
    64         }
    65 
    66         void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
    67         {
    68             //Result.PhraseInfo.GetText(0, -1, true);
    69             Console.Out.Write("recognized something");
    70             Console.ReadKey();
    71         }
    72 
    73         void RecoContext_EndRecognition(int StreamNumber, object StreamPosition, bool f)
    74         {
    75             m_infile.Close();
    76             m_Grammar.DictationSetState(SpeechRuleState.SGDSInactive);
    77 
    78         }
    79 
    80 
    81     }

    这个是测试可用的

  • 相关阅读:
    海尔大数据精准营销平台(内部资料)
    马化腾做的PPT:产品设计与用户体验
    网站上线后,第一次完成线上线下整个环节
    灵感不断
    redis命令
    Redis持久化实践及灾难恢复模拟
    [转]创业公司常见的25个法律问题
    用python语言编写网络爬虫
    Python3常用网络编程模块介绍
    Python3数据库模块(sqlite3,SQLite3)
  • 原文地址:https://www.cnblogs.com/bfyx/p/2855015.html
Copyright © 2020-2023  润新知