Thumbnail

Speech Script

Execute a script when speech is created.

+ How To Add This Control To Your Project (Click to Expand)
  1. Make sure you have the latest version of ARC installed.
  2. Select the Get button in this page to download the archive file.
  3. Double click the downloaded archive file to execute installer.
  4. The installer will add this control to ARC.
  5. Load ARC and press the Project -> Add Control button from the menu.
  6. Choose the Audio category tab.
  7. Press the Speech Script icon to add the control to your project.

Manual

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

#1  
Okay...wicked! Gotta try this out!