简体   繁体   中英

Can System.Speech.Recognition use voice files as grammar?

I'm making a speech based application in c# .NET Framework 4.0

I want to use Voice files (like .wav) as grammar instead of strings, because my app will be in a non-english language and it is hard to transfer it to english characters. For example, there will be expressions like Khorooj or Taghire 'onvan . And there will be many problems, like differences in phrase a letter, etc. So doing that will be much more easier by voice files as reference.

How do I get started? Thanx!

As a variant i suggest you to use Google Voice Search (GVS).
GVS uses flac as audio format of input audio so you should use something like Cuetools to convert wave stream to 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;
  }

You cannot use voice files as grammars. The Microsoft speech recognition engine expects grammars in a format specified by the W3C opens standards body . Grammars are not a listing of all of the words the speech recognition engine should understand. Grammars are a set of rules for an expected response to a specific dialog with the system. Another way of saying this is that grammars do not specify the language that the speech recognition system will understand. You need to get language packs and install them for the specific speech vendor you want to use. For Microsoft it can also be specific to the version of OS you are using. Here are the languages supported on Vista . You may have to go with another speech rec vendor to support the language you want, such as Nuance .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM