c# - 谷歌云 API 语法

标签 c# google-api speech-recognition speech-to-text

使用我在 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”它''ll output "two", if you input "today"it'll output that nothing fits etc, like microsoft's grammar)

我读过有关 SpeechContexts 的内容,但它只能在 C# 中读取,我真的无法使用它。

有什么建议吗?

编辑:

还有我如何离线使用它?会很棒……或者至少让它更快。

我尝试了流式传输选项,但它根本不准确。

最佳答案

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

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# - 谷歌云 API 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44279219/

相关文章:

c# - 从月份编号获取月份名称

python - PyDrive - Google 驱动器 API - 创建文件夹树

ruby-on-rails - 尝试获取 Google Analytics 数据时出现 403 Insufficient permissions 错误

android - Android 中的缅甸语语音到文本转换?

workflow - 有人成功使用CMU Sphinx进行语音识别编程吗

speech-recognition - Google Glass XE17 更新后 SpeechRecognizer 损坏——如何解决?

c# - 如何将 Unix 时间戳转换为 DateTime,反之亦然?

c#.Net : Execute two SQL statements at a time

c# Textchanged 事件在多行 TextBox 中触发两次

android - 少数设备未生成 FCM token