Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow defining a command prefix #18

Open
TalAter opened this issue Aug 30, 2013 · 11 comments
Open

Allow defining a command prefix #18

TalAter opened this issue Aug 30, 2013 · 11 comments
Assignees
Milestone

Comments

@TalAter
Copy link
Owner

TalAter commented Aug 30, 2013

For example:

annyang.setPrefix('OK, glass');

Now only sentences beggining with "OK, glass" will be parsed.

@ghost ghost assigned TalAter Aug 30, 2013
@spacerobot5
Copy link

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?

@michaelrod77
Copy link

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!!!

@revett
Copy link

revett commented Apr 16, 2016

+1

1 similar comment
@dpmontero
Copy link

+1

@brendonexus
Copy link

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.

@ChronSyn
Copy link

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.

@codevenkat
Copy link

If no one is taken this up can I take it up? I am a beginner and would like to do it.

@quentin-sommer
Copy link

I did it a while back but author was not responding

@LukeMcLachlan
Copy link

LukeMcLachlan commented Jan 27, 2018

@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.

@phouthasak
Copy link

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.

@Siyamfahad
Copy link

@ChronSyn thank you so much it worked for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.