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:
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?
I thought I would throw this back up here to see if anyone had any thoughts on it. Hint hint wink wink, DJ,
Since no one has jumped in, as a workaround, I would suggest making a script routine that breaks the numbers up and generates a string with the number words for use with Talk Servo. I'll see if I can whip one up for you if you like.
Great, thanks.
Thinking about a bit more, there are 2 basic ways to go here. The simplest is to just convert the numbers into their word counterparts like this: 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.
My script picks lottery numbers so there is only ever 2 digits numbers returned. The numbers are picked randomly by the script and them it says they in order. I don't have any idea what it takes to do what you are saying, It's up to you how much time you want to spend on it.
Ah, okay, only 2 digits. That makes it easy. Here is the 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:
Then call it like this:
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).
Thanks WBS, I will play with that and let you know how it works.
@WBS, thanks for the time you spent on that code. DJ added something similar in the latest update - it works good too.
Yes, I noticed that. Guess I shoulda waited a couple more days before jumping in. Ah well, wasn't much work on my part at least. Only about an hour or so. Better this way and it probably handles much larger numbers. Perhaps decimal fractions as well?