I want to use wb_speaker_speak(WbDeviceTag tag, const char *text, double volume)
in my webots project (in C). Here is my try (for simplicity I've avoid main and other related functions):
1 #include <webots/speaker.h>
2 static WbDeviceTag Speaker;
3 Speaker = wb_robot_get_device("Speaker");
4 wb_speaker_speak(Speaker, "Hi", 1);
But I get the error:
Warning: "Speaker" device not found.
Error: wb_speaker_speak(): invalid device tag.
I think the problem is in the line 3! How can I see the list of available devices to be able to define the speaker correctly? And is it necessary to add a real speaker device to the environment? If so, then how? Because I didn't see an speaker object.
Thank you.
Your code looks correct.
And the error is exactly that the name argument you are passing to the wb_robot_get_device()
function doesn't exists.
By default the Speaker device name is "speaker" in lower case.
Unfortunately there is no quick way to see all the devices names at once from the UI but you should check in the node definition.
You can do it in from the Webots Scene Tree or, if your robot is a PROTO, you should open the PROTO file and search for the Speaker device.
If the name
field is not specified in the Speaker node, then it is using the default value "speaker".
To make it work it is sufficient to add the Speaker device as a child of your robot node but the world and you don't have to add any real speaker. You can run a sample simulation using the Speaker device by opening the sample named "speaker.wbt" in from the Webots menu "File > Open Sample World.." and selecting the section "samples > devices."
Disclaimer: I am a Webots developer working at Cyberbotics.