zaront / vector

C# API for the Anki Vector robot.
MIT License
13 stars 8 forks source link

Say_Text #1

Closed onlyspike closed 5 years ago

onlyspike commented 5 years ago

Hi, Do you have the Say_Text function implemented yet?

If so, Do you have an example?

zaront commented 5 years ago

yes. await robot.Audio.SayTextAsync("all done"); I've updated the read me to show it too.

onlyspike commented 5 years ago

Thank you for your quick response however when I tested it I for the below error.

image

onlyspike commented 5 years ago

I think this is due to the BehaviorControl that is needed before Say_Text based on Anki's latest SDK update. Im not to familiar with C#, so I tried to take a sample of the BehaviorControl that you used in the SuppressPersonality function, and tried to modify your Say_Text funtion but it didnt work out to great. Vector was saying my Text but in a loop so I dont think I didnt do it correctly.

zaront commented 5 years ago

I think I figured this out. Your right about the behavior control.

I've updated read me with info on how to do this below: (also the latest nuget package should work now) I'll re-open this bug until you confirm it fixed for you.

Text to speach

Saying something is as simple as robot.Audio.SayTextAsync("all done"). However some commands require suppressing the robots personality before you can have it accept your commands. Speaking is one of them. If you are trying to speak shortly after connecting to the robot, you will need to insure that its personality is suppress first.

var robot = new Robot();
await robot.ConnectAsync("A5A7");
robot.SuppressPersonalityAsync().ThrowFeedException(); //attempt to suppress its personality
await robot.WaitTillPersonalitySuppressedAsync(); //wait intil its personality is suppressed
await robot.Audio.SayTextAsync("all done");  //now you are free to talk
onlyspike commented 5 years ago

Hi Zaront,

I have just tried it and it works perfectly. Thank you for the update and the great project. Keep up the great work.

zaront commented 5 years ago

glad to hear it.

onlyspike commented 5 years ago

Maybe a dumb question. How do I release control of the robot after SayText. I just noticed that after he has said the text he then just sits there, only after I close my app then he goes back to normal.

zaront commented 5 years ago

not dumb at all. its kind of confusing and I'm trying to figure out the best way to make it work.

you have to call .StopSuppressingPersonality() if you have used the StartSuppressingPersonality() method, or cancel the passed in cancelationToken if you have used the .SuppressingPersonalityAsync() method.

the reason is because suppressing personality is an on going thing. if vector drives to an edge, or you pick him up, while his personality is suppressed, and the override safety flag is false, he wakes from zombie mode and does a few animation. then settles down again and goes back into having his personality suppressed. once you stop suppressing personality he snaps out of it.

I'm wondering if I should have calls, like .SayText() when not having his personality suppressed, to automatically request behavior control, wait for control, then say text, then release behavior control.

Strange thing is, I've noticed even without suppressing personality, sometimes, you can call SayText and it works (cause you happen to catch a moment when his personality code was idle) and other times where it returns an error basically saying "I'm doing something else right now, sorry."

so this may become incorporated into the API in the future. but for now, this is the easiest way:

var robot = new Robot();
await robot.ConnectAsync("A5A7");
robot.StartSuppressPersonality();
await robot.WaitTillPersonalitySuppressedAsync();
await robot.Audio.SayTextAsync("all done");
robot.StopSuppressingPersonality(); //he goes back to normal