zoukankan      html  css  js  c++  java
  • 微软SpeechRecognitionEngine

    API官网手册:http://msdn.microsoft.com/zh-cn/library/System.Speech.Recognition.SpeechRecognitionEngine(v=vs.110).aspx

    微软语音识别识别率比较低,尤其是话筒不清晰或者音量低的情况下,识别率几乎为0。慎用。

    微软、讯飞和google语音识别引擎的对比:

    http://fqctyj.blog.163.com/blog/static/70843455201361955322797/

    微软语音识别引擎

    C# sample代码:


    using System;
    using System.Speech.Recognition;
    using System.IO;

    namespace SynchronousRecognition
    {
    class Program
    {
    static void Main(string[] args)
    {

    String textFilePath = null;
    int audDevOrFile = -1;
    String waveFilePath = null;

    if (args.Length < 1)
    {
    Console.WriteLine("Too less Params: " + args.Length);
    return;
    }
    else if (args.Length > 1)
    {
    textFilePath = args[0];
    audDevOrFile = int.Parse(args[1]); //大于0,是音频文件;0是音频设备
    if (audDevOrFile > 0)
    {
    if (args.Length < 3)
    {
    Console.WriteLine("please check the param!");
    }
    else
    {
    waveFilePath = args[2];
    }
    }
    }
    waveFilePath = "F:\7_.wav";
    // Create an in-process speech recognizer for the en-US locale.
    using (SpeechRecognitionEngine recognizer =
    new SpeechRecognitionEngine(
    new System.Globalization.CultureInfo("zh-CN")))
    {

    // Create and load a dictation grammar.
    recognizer.LoadGrammar(new DictationGrammar());

    // Configure input to the speech recognizer.
    if (audDevOrFile > 0)
    {
    recognizer.SetInputToWaveFile(waveFilePath);
    }
    else
    {
    recognizer.SetInputToDefaultAudioDevice();
    }

    // Modify the initial silence time-out value.
    recognizer.InitialSilenceTimeout = TimeSpan.FromSeconds(500);

    // Start synchronous speech recognition.
    RecognitionResult result = recognizer.Recognize();

    if (result != null)
    {
    //FileStream fs = new FileStream(textFilePath, FileMode.Open, FileAccess.ReadWrite);
    StreamWriter sw = File.CreateText(textFilePath);
    //fs.SetLength(0);//首先把文件清空了。
    sw.Write(result.Text);//写你的字符串。
    sw.Close();
    Console.WriteLine("{0}", result.Text);
    Console.WriteLine("recognize done!");
    }
    else
    {
    Console.WriteLine("No recognition result available.");
    }
    }

    //Console.WriteLine();
    //Console.WriteLine("Press any key to continue...");
    //Console.ReadKey();
    }
    }
    }

  • 相关阅读:
    ES进阶--01
    JVM--02
    JVM--01
    ES--08
    ES--07
    ES--06
    python实现当前主机ip 主机名称的获取
    djang中的blank=True 和null = True的区别
    python中yield的用法详解
    python 编写古诗赤壁赋
  • 原文地址:https://www.cnblogs.com/freedesert/p/3939268.html
Copyright © 2011-2022 走看看