Little Robot Friends
Arduino Library Reference  version 1.1
MyLRF02: Say

Creating Custom Sounds for the Speaker Mouth

This tutorial uses example code found in:MyLRF02_Say.cpp

Congratulations, you’ve made the eyes on your Little Robot Friend blink, wink and change colours. Next step is to give your Little Robot Friend a voice. Let’s make some sounds!

Making unique sounds is very similar to making light patterns. Sounds are created using a similar ‘struct’, however this time we’ve got a couple more options that will need to be included. We tried to make Little Robot Friend sounds in a way that mimics how we say words. We can control and customize your Little Robot Friend’s voice using the LRFSound object.

Each LRFSound is comprised of the following LRFSound values: LRFNote, LRFOctave, LRFIntonation and LRFDuration. If you play an instrument or study music theory, you’ll be familiar with these terms already. If not, don’t worry - here’s a quick explanation of each value:

  • LRFNote and LRFOctave combine to give us our frequency, which determines if we’re making a high-pitched or low-pitched sound.
  • LRFIntonation code allows us to bend that pitch while it’s speaking, which gives the sound a lot of character.
  • Finally we need to define how long we want that sound to be spoken, and whether or not we want to pause after we’ve spoken this sound, which is determined by two LRFDuration codes (the first one is for duration of the note, the second one is for the pause).

Check out the links below to learn more about the LRFSound and its options: LRFNote, LRFOctave, LRFIntonation and LRFDuration

Let’s start by making our robot play a single note, in this case, a C.

LRFSound mySound = {
LRFNote_C, // note
LRFOctave_4, // octave
LRFIntonation_Rising, // intonation (see LRFUtils.h for more info)
LRFDuration_Long, // note length
LRFDuration_None // pause length (after note has played)
};

Once we've created our pattern, we can call it using the API function lrf.say(mySound). This function takes our pattern variable mySound and plays it. Your robot should play a single note that lasts about (1) second(s) and rises slightly as if it were asking a question. Let's put this in our setup() function so it happens when the robot starts up:

void setup(void) // Arduino setup routine that gets called ONCE when the robot turns on
{
lrf.setup(); // lrf library should be set up before anything else
delay(1000);
lrf.say(mySound); // let's try saying a sound
delay(1000);
}

Cool! Now let’s see if we can make our robot sing a little tune. We can do this by adding more values to mySound, thus creating an array. Be sure to indicate the number of lines in your array next to the name of your variable. In this example, it’s 3. (You’ll notice that the structure of the code is a bit different than in Tutorial 1. This is to make the code cleaner and easier to read so you don’t get all your values mixed up. )

Now, plug your variable mySound into your setup() function and you should get something that looks like this:

void setup(void)
{
lrf.setup();
delay(1000);
lrf.say(mySound, 3); // Remember to indicate the number of lines in your array!
delay(1000);
}

Your robot will play a sequence of 3, (1) second(s) notes. Notice that this time, we used LRFIntonation_Flat value. How did that change the sound? Play around with the values and see what happens.

All Done? Why Not Try This...

  • Make your robot play a long and low pitched sound
  • Make your robot play a short and high pitched sound
  • Make a custom sound by changing the LRFIntonation value