-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Question: How to grab the last phrase captured while HOLDING a key #417
Comments
I believe the best way to do this would be to add a callback to annyang once that key's pressed event triggers, and then when that key is released, clear annyangs callback that you created. your event listener for a key being pressed would look something like this: if (e.keyCode === 84) {
globalArrayOfSpokenPhrases = []
annyang.addCallback('result', function(userSaid) {
globalArrayOfSpokenPhrases.push(userSaid);
}) and then a listener for when that key is released where you do something along these lines: if (e.keyCode === 84) {
console.log(globalArrayOfSpokenPhrases);
annyang.removeCallback('result') // removes all callbacks on the 'result' event. if you pass in a defined function instead of a lambda function, you can pass that function's name as a second parameter in the removeCallback function to remove just that callback
} I really don't think this is perfect and I haven't tried it, but the concept should stick. |
I will give it a try... stay safe |
Report back if you get a chance to try it before I do! As long as I remember I will give it a crack sometime tomorrow |
After a little bit of testing, this is probably easiest: var phrases = []
var keyDown = false;
if (annyang) {
annyang.start()
}
document.onkeydown = function(e) {
if (e.keyCode === 83) {
keyDown = true;
}
}
document.onkeyup = function(e) {
if (e.keyCode === 83) {
keyDown = false;
console.log(phrases);
}
}
annyang.addCallback('result', (userSaid) => {
console.log('Heard:', userSaid);
if (keyDown) {
phrases.push(userSaid[0])
}
}) |
How get I get a string value with the last phrase captured during the seconds, that I am holding certain key on my keyboard:
`
if (e.keyCode === 84) {
*** code to grab last spoken phrase ***
var capturedPhrase = ?????
`
Thanks
The text was updated successfully, but these errors were encountered: