编程语言
首页 > 编程语言> > c# – Google Cloud API语法

c# – Google Cloud API语法

作者:互联网

使用此代码我在youtube视频上找到了(不知道我是否能够发布):

if (File.Exists("audio.raw"))
{
    var speech = SpeechClient.Create();
    var response = speech.Recognize(new RecognitionConfig()
    {
        Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
        SampleRateHertz = 16000,
        LanguageCode = "iw",
    }, RecognitionAudio.FromFile("audio.raw"));

    textBox1.Text = "";

    foreach (var result in response.Results)
    {
        foreach (var alternative in result.Alternatives)
        {
            textBox1.Text = textBox1.Text + " " + alternative.Transcript;
        }
    }

    if(textBox1.Text.Length == 0)
        textBox1.Text = "No Data ";
    StreamingMicRecognizeAsync(10);
}
else
{
    textBox1.Text = "Audio File Missing ";
}

我能够基于谷歌云api创建语音识别.

但是,我找不到以这种方式创建语法的方法,因此我正在寻找建议.

如何为google api创建语法过滤?

是否有人制作了一个项目,或者某些已经做过的api(例如:输入一个“one”,“two”,“three”的主字符串然后如果输入例如“tu”它将输出“两个”,如果你输入“今天”它将输出没有任何东西适合等,如微软的语法)

我已经阅读过有关SpeechContexts的内容,但它只能在c#中阅读,而且我真的无法使用它.

有什么建议?

编辑:

另外我如何离线使用它?会很棒……或者至少让它更快.

我尝试了流媒体选项,但它根本不准确.

解决方法:

假设您只想将SpeechContext添加到您的请求中,只需将实例添加到RecognitionConfig的SpeechContexts属性:

var context = new SpeechContext { Phrases = { "first", "second" } };
var config = new RecognitionConfig()
{
    Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
    SampleRateHertz = 16000,
    LanguageCode = "iw",
    SpeechContexts = { context }
};

(通常,表示地图和列表的protobuf中的属性是只读的,但您可以添加它们 – 显式调用Add或使用上面的集合初始值设定项.)

标签:c,google-api,speech-recognition,speech-to-text
来源: https://codeday.me/bug/20190622/1265025.html