Thumbnail

Speech Script

by Synthiam

Execute a script when speech is created.

How to add the Speech Script robot skill

  1. Load the most recent release of ARC (Get ARC).
  2. Press the Project tab from the top menu bar in ARC.
  3. Press Add Robot Skill from the button ribbon bar in ARC.
  4. Choose the Audio category tab.
  5. 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 when the speech has completed. 

Variable
The variable containing the speech 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...

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 end of the sentence. These would be tweaked based on the speed of speaking.

Code:


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;
}
}

ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates with ARC Pro edition. You'll have everything that's needed to unleash your robot's potential!

PRO
Canada
#1  
Okay...wicked! Gotta try this out!
PRO
Canada
#2  
Ha ha, so I never did try this out but will give it a go now. It is so great when you add example code to try out and modify. I can think of many uses of this skill, thanks.