Asked
— Edited
I have been developing a script that generates a series of numerals and I've noticed that the Talk servo Control does not move when it receives a numeral in the Say command. For example:Code:
Sayezb(" two hundred and fourty eight") # the servo moves and the audio plays
Sayezb("248") #the servo does not move but the audio plays
Is there any way to get the Talk servo to move when it is fed numerals?
567 =Five Six Seven. That will be a snap.
The harder way is to convert the number to properly spoken words like this:
567 =Five Hundred and Sixty Seven.
The first I can do quickly. The second will take a few days.
I was thinking I could do the first right now so you would have something, and work on the second, delivering it as I can. Or you can simply wait for a week or so for the second. I've done the second method years ago and have the code already. The thing that will take a while is translating it to a script. There are always a myriad of problems to overcome when translating code from one language to another. Especially from a full blown language with a host of functions and data types with which to work to a very limited one ike the script language. Still, I think this could be helpful to others as well.
Let me know what you prefer.
Code:
Now, how you implement it is up to you. In this script, the number to be converted is put in the variable $TheNumber. It is assumed to be a string and not an integer. Then the Goto sends the script execution to NumToWords. When the Return() statement is executed and the script goes back to the Print instruction, the $TheNumber variable is printed and spoken. It now contains the words instead of the number. If you would rather use a separate variable to contain the words, delete the line just above the return() statement ($TheNumber =$NumPhrase) and use the variable $NumPhrase instead.
Another way to do this would be to use a Command Control. To do that you would place another script in your project and call it NumToWords. Then put the following script in it:
Code:
Then call it like this:
Code:
Again, if you want to use $NumPhrase and keep $TheNumber as it is, take out the line that reads $TheNumber =$NumPhrase.
Finally. the first 3 lines in the code don't really need to be executed every time it is run so you could move those lines to whatever Init script you run at the start. It won't hurt anything if they are run every time, just that it's not necessary. Enjoy.
Questions?
EDIT: PS, if I'm wrong and your number is actually an integer and not a string, I can easily modify the script to work for that (or both for that matter).