System.Speech.Recognition可以使用语音文件作为语法吗?

时间:2012-09-05 12:29:09

标签: c# speech-recognition

我正在c#.NET Framework 4.0中创建基于语音的应用程序

我想使用语音文件(如.wav)作为语法而不是字符串,因为我的应用程序将使用非英语语言,并且很难将其转换为英语字符。例如,会有像 Khorooj Taghire'onvan 这样的表达式。并且会出现许多问题,例如短语 a 字母等的差异。因此,通过语音文件作为参考,这样做会更容易。

我如何开始?感谢名单!

2 个答案:

答案 0 :(得分:2)

作为变体,我建议您使用Google语音搜索(GVS) GVS使用flac作为输入音频的音频格式,因此你应该使用像Cuetools这样的东西将波流转换为flac

    public static int Wav2Flac(String wavName, string flacName)
    {
        int sampleRate = 0;

        IAudioSource audioSource = new WAVReader(wavName, null);
        AudioBuffer buff = new AudioBuffer(audioSource, 0x10000);

        FlakeWriter flakewriter = new FlakeWriter(flacName, audioSource.PCM);
        sampleRate = audioSource.PCM.SampleRate;            
        FlakeWriter audioDest = flakewriter;
        while (audioSource.Read(buff, -1) != 0)
        {
            audioDest.Write(buff);                
        }
        audioDest.Close();

        audioDest.Close();
        return sampleRate;
  }
  public static String GoogleSpeechRequest(String flacName, int sampleRate)
  {

    WebRequest request = WebRequest.Create("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=ru-RU");

    request.Method = "POST";

    byte[] byteArray = File.ReadAllBytes(flacName);

    // Set the ContentType property of the WebRequest.
    request.ContentType = "audio/x-flac; rate=" + sampleRate; //"16000";        
    request.ContentLength = byteArray.Length;

    // Get the request stream.
    Stream dataStream = request.GetRequestStream();
    // Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length);

    dataStream.Close();

    // Get the response.
    WebResponse response = request.GetResponse();

    dataStream = response.GetResponseStream();
    // Open the stream using a StreamReader for easy access.
    StreamReader reader = new StreamReader(dataStream);
    // Read the content.
    string responseFromServer = reader.ReadToEnd();

    // Clean up the streams.
    reader.Close();
    dataStream.Close();
    response.Close();

    return responseFromServer;
  }

答案 1 :(得分:1)

您不能将语音文件用作语法。 Microsoft语音识别引擎需要format specified by the W3C opens standards body中的语法。语法不是语音识别引擎应该理解的所有单词的列表。语法是一组规则,用于对系统的特定对话的预期响应。另一种说法是语法不指定语音识别系统将理解的语言。您需要获取语言包并为要使用的特定语音供应商安装它们。对于Microsoft,它也可以特定于您使用的OS版本。这是languages supported on Vista。您可能需要与另一个语音录制供应商合作以支持您需要的语言,例如Nuance

相关问题