|
Lessons from BOB : PART THREE Making it Talk Let’s put some sound on our robot. There are many sound files preloaded in the FICE SD card. Please refer to ‘FIDE Language Reference’ for a detailed explanation. To play a certain sound, we make use of the command OS.Wave.Play. OS.Wave.Play takes 3 arguments. The first argument is Cluster, the second argument is StartSector and the third is EndSector. To understand how to use the OS.Wave.Play, we’ll go through an example. To play the sound “get”, we look up in the ‘FIDE Language Reference’ and find that it is the 95th word in the list of a Hundred Words. We also know that the Hundred Words are located in Cluster 11. | No. | VOCAB
| File/s
| BlockStart
| BlockEnd
| Block Length
| Last Pos. in Block | | 95 | get | W0095.wav | 2437 | 2454 | 18 | 0 | Cluster 8 = 2 songs Cluster 9 = Numbers Cluster 10 = Alphabets Cluster 11 = Hundred words (refer to APPENDIX A in the Language Ref) So to play the sound “get”, we use OS.Wave.Play(11, 2437, 2454). Let’s try it. Now let’s find the word “down” and play it. | No. | VOCAB | File/s | BlockStart | BlockEnd | Block Length | Last Pos. in Block | 92
| down | W0092.wav
| 2361 | 2395 | 35
| 0
|
CODE: OS.Wave.Play(11, 2361, 2395) |
To play both words, “get down”, we have to put a delay, so that there is time for the processor to finish saying the first word before starting on the second word. Your code should look something like the one below. CODE: | OS.Wave.Play(11, 2437, 2454) 'say 'get' Delay(500) OS.Wave.Play(11, 2361, 2395) 'say 'down' Delay(500) |
Having a delay is a necessity but if we need to do other stuff, like drawing a mouth on the GLCD, the delay will not do. Instead we can check if the processor has finished saying the word. Try the code below. CODE: | OS.Wave.Play(11, 2437, 2454) 'say 'get' Do Loop Until OS.Wave.State() = 0 OS.Wave.Play(11, 2361, 2395) 'say 'down' Do Loop Until OS.Wave.State() = 0 |
Notice that the next word is said immediately after the first word has been said. Now it’s time to add the talking GLCD program with the sound program.
| No. | VOCAB
| File/s
| BlockStart
| BlockEnd
| Block Length
| Last Pos. in Block | 9
| it | W0009.wav
| 241 | 257 | 17 | 0 | | 13 | on | W0013.wav | 329 | 350 | 22 | 0 | CODE: | OS.Wave.Play(11, 2437, 2454) 'say get Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) OS.Wave.Play(11, 2361, 2395) 'say down Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) OS.Wave.Play(11, 329, 350) 'say on Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) OS.Wave.Play(11, 241, 257) 'say it Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) |
Don’t forget that you need to include the initializing of the GLCD and also include DRAW_LIB into your project. CODE: 'Module1
Dim POS As Integer 'LESSON 2 Public Sub Main() OS.GLCD.Init() OS.GLCD.Fill(255) 'DRAW RIGHT EYE DRAW_EYE(25, 70, True) 'DRAW LEFT EYE DRAW_EYE(75, 70, True) 'DRAW MOUTH DRAW_MOUTH(32, 30, 1) Delay(1000) 'DELAY FOR 1 SEC 'CLOSE RIGHT EYE DRAW_EYE(25, 70, False) Delay(500) 'WAIT FOR A WHILE 'DRAW RIGHT EYE DRAW_EYE(25, 70, True) Delay(500) OS.Wave.Play(11, 2437, 2454) 'say get Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) OS.Wave.Play(11, 2361, 2395) 'say down Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) OS.Wave.Play(11, 329, 350) 'say on Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) OS.Wave.Play(11, 241, 257) 'say it Do Loop Until OS.Wave.State() = 0 POS = RND(3) + 3 'DRAW MOUTH DRAW_MOUTH(32, 30, POS) 'DRAW MOUTH - initial position DRAW_MOUTH(32, 30, 1) End Sub |
 Lost? Try backtracking to Part One and Part Two.
|