首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >System.Speech.Recognition可以使用语音文件作为语法吗?

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

Stack Overflow用户
提问于 2012-09-05 12:29:08
回答 2查看 1.8K关注 0票数 0

我正在c# .NET Framework4.0中创建一个基于演讲的应用程序

我想使用语音文件(如.wav)作为语法,而不是字符串,因为我的应用程序将是一种非英语语言,很难把它转换成英文字符。例如,会有像KhoroojTaghire 'onvan这样的表达方式。还有许多问题,比如短语a 等等。因此,通过语音文件作为参考,这样做会容易得多。

我该怎么开始?谢谢!

EN

回答 2

Stack Overflow用户

发布于 2012-09-05 12:49:33

作为一个变体,我建议你使用谷歌语音搜索(GVS)。

GVS使用flac作为输入音频的音频格式,因此您应该使用类似Cuetools的方法将波流转换为flac。

代码语言:javascript
运行
复制
    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;
  }
票数 2
EN

Stack Overflow用户

发布于 2012-09-05 13:37:28

您不能使用语音文件作为语法。微软语音识别引擎期望在W3C指定的格式打开标准主体中使用语法。语法并不是语音识别引擎应该理解的所有单词的列表。语法是一组规则,用于对系统特定对话框的预期响应。另一种说法是语法没有指定语音识别系统将理解的语言。您需要获得语言包,并为要使用的特定语音供应商安装它们。对于微软,它也可以特定于您正在使用的操作系统的版本。这是Vista支持的语言。为了支持您想要的语言(如细微差别 ),您可能必须与另一个语音评论供应商一起使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12281454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档