Using this code I've found on a youtube video (don't know if i'm able to post) :
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 ";
}
I was able to create a speech recognition based on google cloud api.
However, i can't find a way for creating a grammar this way, therefore i'm looking for suggestions.
How can i create a grammar filtering for google api?
Is there maybe a project somebody made, or some apis that are already doing that (for example : entering a main string of "one", "two", "three" and then if you input for example "tu" it'll output "two", if you input "today" it'll output that nothing fits etc, like microsoft's grammar)
I've read about SpeechContexts but it's read only in c# and i really couldn't get something to work.
Any suggestions?
Edit :
Also how can I use it offline? would be great... or at least make it faster.
I tried the streaming option but its not accurate at all.
Assuming that you just want to add SpeechContext
to your request, just add instances to the RecognitionConfig
's SpeechContexts
property:
var context = new SpeechContext { Phrases = { "first", "second" } };
var config = new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "iw",
SpeechContexts = { context }
};
(In general, the properties in protobuf representing maps and lists are read-only, but you can add to them - either calling Add
explicitly, or using collection initializers as above.)