Execute a script when speech is created.
How to add the Speech Script robot skill
- Load the most recent release of ARC (Get ARC).
- Press the Project tab from the top menu bar in ARC.
- Press Add Robot Skill from the button ribbon bar in ARC.
- Choose the Audio category tab.
- Press the Speech Script icon to add the robot skill to your project.
Don't have a robot yet?
Follow the Getting Started Guide to build a robot and use the Speech Script robot skill.
How to use the Speech Script robot skill
Execute a script when speech is created. With this skill, you can create a function that will move servos or LEDs based on spoken speech. The code can be a loop because the script will be canceled after the speech is completed.
Variable The variable containing the speech that is currently speaking is set as $SpeechTxt.
*Note: to avoid a recursive never-ending loop, do not speak text in the script of this skill. If you do, the text will call this script, which will call this script, which will call this script, which will call this script...
Main Screen
Stop Script Button A button on the main screen can be pushed to stop the currently running script. If the script begins to run out of control, you can press the button to stop it. This will not stop the current audio from playing the speech; it only stops the script.
Log Window The log window displays the output of scripts, the execution of scripts, and what audio is being spoken.
Configuration Window
There are two scripts that can be configured in the configuration window of this robot skill. One script will execute when speaking begins, and the other runs when speaking ends.Script Start Speaking This is the script that executes when any robot skill or script begins speaking within ARC. You can run a loop in this script which will execute as the speech is speaking. This script is stopped when the speaking stops, or when the End Speaking script starts.
Script End Speaking This script will execute when the speech is completed. You can use this script to restore your mouth and facial expression of the robot into a default position when speaking is completed. This script stops the Start Speaking script when it is executed.
Examples
Example Script (Talk Servo) This example script will move a servo on port D0 as a jaw. Position 10 is the closed mouth, and 100 is an open mouth. There is a delay set for vowels, constants, and the end of the sentence. These would be tweaked based on the speed of speaking.
var words = getVar("$SpeechTxt").split(" ");
for (var wi = 0; wi < words.length; wi++)
for (var i = 0; i < words[wi].length; i++) {
var c = words[wi][i];
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
// open mouth vowels
Servo.setPosition(d0, 100);
sleep(100);
break;
case '.':
case ',':
case '?':
case '!':
// close mouth for end of sentence
Servo.setPosition(d0, 10);
sleep(500);
break;
default:
// close mouth for constants
Servo.setPosition(d0, 10);
sleep(100);
break;
}
}
@Athena, $SpeechTxt is written with quotation marks, opening and closing, like here: ("$SpeechTxt")
I made a video where everything seems fine at first, but towards the end, the text finishes, yet the movements continue. If the text is short, just one line, it stops on time; the longer the text, the more delayed the stop.
Video Test
If the movement continues, you can reference the manual above to use the speech end script.
@athena explain to fantamos how to use the robot skill.
To address the issue of the servo movements continuing after the speech has finished, you can utilize the "Script End Speaking" feature in the Speech Script robot skill. This feature allows you to define a script that will be executed once the speech has completed, which can be used to stop the servo movements and return the servos to their default positions.
Here's how you can use the "Script End Speaking" feature:
Open the configuration menu of the Speech Script robot skill by clicking on the gear icon in the title bar of the skill.
In the configuration menu, you will find two script areas: "Script Start Speaking" and "Script End Speaking."
In the "Script End Speaking" script area, enter the script commands to stop the servo movements. For example, if you want to return a servo to a default position, you can use the
Servo.setPosition()
command:Now, when the speech finishes, the script you defined in the "Script End Speaking" area will be executed, which should stop the servo movements and return the servos to their default positions.
Please test this solution with your setup and adjust the servo positions and ports as necessary. If you encounter any further issues or have additional questions, feel free to ask for assistance.
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
The feature of ending the conversation is very useful. Now, at the end of the conversation, the robot remains with its eyes open. However, it didn't solve the issue of stopping the movement in time. The video demonstrates the conversation-ending settings. Here's a screenshot of the settings:
Of course, I deleted everything and left only one team to close. The effect is the same.
Something very strange happened: when I tried sending the sound to the computer (PC Speaker), a long text worked correctly. At the end of the conversation, the servo movements stopped. Certainly, there was a mismatch between the movements and the voice in the middle, but the most important thing was that it ended on time.
However, when I sent the same text again, this time using the Say (EZ-B v4 Speaker) button, the desynchronization reappeared. The voice ended, but the servo continued moving as shown in the video.
Hardware issue? No parallel operation? Are commands executed sequentially? First, signal for sound, then signal for servo drive, then sound again, followed by servo drive once more, and so on, executing in sequence. Hardware: EZ-B v4, EZ-B IoTiny