Windows Phone speech recognition - words that are not in grammar - windows-phone-8

consider a grammar like this ; speech.Recognizer.Grammars.AddGrammarFromList("answer",new string[] { "Go.","no" });
When I say something else that are not in grammar, she says "sorry didnt catch" and then tries to start it again. Same goes for null input.
What I want is that it should only recognize the words in grammar and for everything else it should just pass the recognition. I don't want to see anything like "sorry didnt catch" and second time recognotion. Any idea ? thanks.
Edit : with try-catch I can avoid from second time recognotion if the word is unknown but now it's waiting too long on "sorry didnt catch" part.
try
{
SpeechRecognizerUI speech = new SpeechRecognizerUI();
speech.Settings.ReadoutEnabled = false;
speech.Settings.ShowConfirmation = false;
speech.Recognizer.Settings.InitialSilenceTimeout = System.TimeSpan.FromSeconds(0.8);
speech.Recognizer.Grammars.AddGrammarFromList("answer", new string[] { "Go.", "no" });
SpeechRecognitionUIResult result = await speech.RecognizeWithUIAsync();
if (result.RecognitionResult.Text == "Go.") { .... }
}
catch
{
..... }

In my opinion, you must build your own UI to avoid this. So you should use SpeechRecognizer and then you can handle the input as you want.
In my case I even created two SpeechRecognizer, on with own Wordlist, the other one with default dictionary. It works like a charm, but I couldn't get it to work with SpeechRecognizerUI.

Related

Why is the "Add Note" button giving an exception and printing null on the console?

I am trying to add a note using Add Note Button but it is throwing an exception. I handled the error using try...catch block but the note written in Add Note Button is not added and printing null on console.
JSBin for my project:
This piece:
if(notes =='')
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
is the problem. If there's nothing in the local storage, notes will be null, which means notesObj == '' will be false, and the code will break. You need to change the test so it detects null (and other falsy values) as such:
if(!notes)
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
There's another problem. This line:
localStorage.setItem('notes', JSON.stringify(notes));
makes no sense. You're setting the item notes in the local storage as the converted json of the notes variable, which is already a JSON string, so it'll fail horribly. What you really want to do is stringify the notesObj variable, which is the array with the actual notes. Change that line to:
localStorage.setItem('notes', JSON.stringify(notesObj));
And that's it. Make those changes and your code will work.

How to dynamically add text to textarea while recording via webkitspeech with Angular 2?

Currently, I record my voice with this simple code in Angular Component
speechToText() {
const {webkitSpeechRecognition}: IWindow = <IWindow>window;
const recognition = new webkitSpeechRecognition();
recognition.lang = 'en-US';
recognition.continuous = true;
recognition.interimResults = true;
recognition.onresult = event => {
for (let i = event.resultIndex; i < event.results.length; ++i) {
this.interim_transcript = event.results[i][0].transcript;
}
};
recognition.onerror = event => {
console.log('Error occured', event);
};
recognition.start();
}
}
And in my HTML I have the value bind to the interim result
<textarea #description mdInput rows="5" placeholder="Short Story" name="description" [value]="interim_transcript"></textarea>
The problem, however, is that I can see the text being put into the textarea only after I click on the textarea or outside of it to trigger dom update. How to make it update textarea as soon as I begin saying words giving this live text update, same way as here https://www.google.com/intl/en/chrome/demos/speech.html
This happens because Angular is not aware of the update to interim_transcript since it happens outside of what the Zone is aware of.
I see two immediate ways to fix it:
Run the interim_transcript update in a zone.run call. See NgZone in the docs.
Make interim_transcript an Observable. Actually a Subject, but the point is that it needs to be observable.
I'd recommend the latter, and it basically involves this:
When you define interim_transcript, define it like this: interim_transcript: new Subject<string>()
When you update it in the onresult callback, replace
this.interim_transcript = event.results[i][0].transcript;
with
this.interim_transcript.next(event.results[i][0].transcript);
Change the value binding in your template, replace:
[value]="interim_transcript"
with
[value]="interim_transcript | async"
Observables are an incredibly powerful concept that can make your code more easy to reason about (even though it seems very odd at first). It can boost your performance significantly when you start using the OnPush change detection mechanism. Finally, however cheesy it sounds, can change the way you think about your programs, to a data stream mind model instead of state updates. This will likely sound confusing and weird, but I strongly recommend looking into it, I'm sure it will pay off.
Here are a few good resources to get started:
Using Observable from Rangle.io.
Understand and Utilize the Async Pipe in Angular 2 from Brian Troncone

Double arrows on js console log in chrome

I noticed a double arrow console log from the code below in the console. What does this mean? I'm worried that this is a bug and that the data traced is corrupted some how. Does some one know what the double arrow means and Why im getting it?
LoginDispatcher.register(function(payload){
var action = payload.action;
var text;
log.trace(action);
switch(action.actionType) {
case AppConstants.LOGIN:
setUser(action.data);
break;
default:
return true;
}
LoginStore.emitChange();
return true;
});
When inspecting the call it looks allright.
Opening the folding arrows I see the following info
I noticed that this is the default behaviour of the console.log.trace function. So there was nothing wrong.

try statement tripping debugger (as3)

Trying a try-catch sequence that works fine in release version, but running it in debugger causes errors to be displayed. Obviously there errors, that's why I'm using this stuff inside try, but I'm wondering if there's any way I can get debugger to stop stopping. While I don't even mind the error message, the app no longer executes properly.
I've got a this[$val] that I needs to return a null if there is no such variable inside the class.
try {
return this[$val]+"";
} catch(error:ArgumentError) {
// Do nothing
}
return "";
again, this works like it is supposed to, but it causes errors in debugger
any ideas for an alternative?
I think you are catchin an argument error in place of the real problem of handling a null object + string error.Try Using;:
try {
return this[$val]+"";
} catch(error:Error) {
// Do nothing
}
return "";

multiple tinyMce instances not working in chrome

As with the title in Chrome (v.4.1) multiple tinyMce (v2.08) instances do not work. To be exact the first two instances are ok, the others not, and chrome gives this error:
Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1
Has this happened before?
Unfortunately I can't show you any code because it's for an admin area, I just need some clue for the moment.
Yes, as user XP1 noted, at this link you can find resolution for a comprimed TinyMCE source:
http://my.opera.com/XP1/blog/2011/07/21/tinymce-javascript-error-in-opera-getrangeat-index-size-err
But if you want to work with original uncomprimed source (it's just a bit easier), here is the solution:
Look for code "setRng : function(r) {" (without quotes) and exchange the whole function with:
setRng : function(r) {
var s, t = this;
if (!t.tridentSel) {
s = t.getSel();
if (s) // this block fixed according to TinyMCE JavaScript error in Opera (getRangeAt, INDEX_SIZE_ERR); http://my.opera.com/XP1/blog/2011/07/21/tinymce-javascript-error-in-opera-getrangeat-index-size-err
{
if(s.anchorNode === null && s.focusNode === null)
{
t.explicitRange = r;
try {
s.removeAllRanges();
} catch (ex) {
// IE9 might throw errors here don't know why (NOW WE KNOW WHY DAMMIT!)
}
s.addRange(r);
}
if (s.rangeCount > 0)
t.selectedRange = s.getRangeAt(0);
}
} else {
// Is W3C Range
if (r.cloneRange) {
t.tridentSel.addRange(r);
return;
}
// Is IE specific range
try {
r.select();
} catch (ex) {
// Needed for some odd IE bug #1843306
}
}
},
ONE NOTE: please make sure variables match. I am not sure how it is between different TinyMCE versions BUT the variables are not the same between comprimed and src mutations of the script file.
Take Care and God Speed