使用我在 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
添加到您的请求中,只需将实例添加到 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# - 谷歌云 API 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44279219/