annyang
annyang copied to clipboard
Allow defining a command prefix
For example:
annyang.setPrefix('OK, glass');
Now only sentences beggining with "OK, glass" will be parsed.
Hey there, I think this idea would really help the script to gain popularity. Do you think including a prefix option would be difficult to implement based on the current state of the code?
This would be a great feature to have. I'm currently using Aanyang to test an AI script and have circumvented not having this feature by using a command like 'OK computer (please) *term'. Unfortunately, it's missing that nice audio cue that it's actually listening like Google uses when you say "OK Google" with Google Now. Having this feature would allow a more robust use of Aanyang for situations like this. Great work overall by the way on this!!!
+1
+1
Any news on the implementation of this? This is exactly what I require since I am running Annyang continuously on a machine I keep on, currently its picking up everything but with this prefix it would stop random speech recognition playing through my speakers every time I get too close to the microphone.
It's possible to do this without needing a PR or any modification to the library using a key rename function. Simply add your commands in object format - e.g.;
var commands = {
"Where am I?" : myLocationFunction,
"What's the time?" : myTimeFunction,
};
Then, add the following rename
function;
var rename = function(obj, prefix){
if(typeof obj !== 'object' || !obj){
return false;
}
var keys = Object.keys(obj),
keysLen = keys.length,
prefix = prefix || '';
for(var i=0; i<keysLen ;i++){
obj[prefix+keys[i]] = obj[keys[i]];
if(typeof obj[keys[i]]=== 'object'){
rename(obj[prefix+keys[i]],prefix);
}
delete obj[keys[i]];
}
return obj;
};
Usage is as follows;
rename(commands, "Hello Annyang ");
I'd recommend adding a space on the end of your prefix (in this case, "Hello Annyang ". After that, simply call;
annyang.addCommands(commands);
annyang.start();
If you console.log(commands)
after calling rename
, you'll see it's prefixed all your commands with your specified prefix.
If no one is taken this up can I take it up? I am a beginner and would like to do it.
I did it a while back but author was not responding
@ChronSyn this worked for me but only when I removed the question mark from after the "I?" but thanks as it's a nice workaround for the hotword detection.
A work around I have implemented on my application for this is define a command to turn on a state (lets say the command was "Ok Tom" and the state is named "isListening") for 5 seconds. Then have other commands to check if "isListening" active, before actually executing the logic assigned to the given command.
@ChronSyn thank you so much it worked for me :)