Canada
Asked — Edited

Talk Servo And Numerals

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?


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

#1  

I thought I would throw this back up here to see if anyone had any thoughts on it. Hint hint wink wink, DJ,

#2  

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.

#4  

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.

#5  

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.

#6  

Ah, okay, only 2 digits. That makes it easy. Here is the code:


$Digits  ="zero,one,two,three,four,five,six,seven,eight,nine"
$Decades ="twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety"
$Teens   ="ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen"

$TheNumber ="25" #Whatever the lottery number is, set $TheNumber equal to it 
Goto(NumToWords)
Print($TheNumber)
Sayezb($TheNumber)

Goto(TheExit)

:NumToWords
if($TheNumber >=0 AND $TheNumber < 10)
  $NumPhrase =Split($Digits,",",$TheNumber)  
elseif($TheNumber > 9 AND $TheNumber < 20)
  $NumPhrase =Split($Teens,",",$TheNumber -10)
elseif($TheNumber >19 AND $TheNumber < 100)
  $TheDigit =GetCharAt($TheNumber,0)  #Get first character as a number
  $NumPhrase =Split($Decades,",",$TheDigit -2)
  $TheDigit =GetCharAt($TheNumber,1)  #Get second character as a number
  if($TheDigit >0)  #Don't need a second word if 0
    $NumPhrase =$NumPhrase+" "+Split($Digits,",",$TheDigit)
  endif  
endif
$TheNumber =$NumPhrase
Return()

:TheExit

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:


$Digits  ="zero,one,two,three,four,five,six,seven,eight,nine"
$Decades ="twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety"
$Teens   ="ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen"

if($TheNumber >=0 AND $TheNumber < 10)
  $NumPhrase =Split($Digits,",",$TheNumber)  
elseif($TheNumber > 9 AND $TheNumber < 20)
  $NumPhrase =Split($Teens,",",$TheNumber -10)
elseif($TheNumber >19 AND $TheNumber < 100)
  $TheDigit =GetCharAt($TheNumber,0) #Get first character as a number
  $NumPhrase =Split($Decades,",",$TheDigit -2)
  $TheDigit =GetCharAt($TheNumber,1) #Get second character as a number
  if($TheDigit >0) #Don't need a second word if 0
    $NumPhrase =$NumPhrase+" "+Split($Digits,",",$TheDigit)
  endif  
endif
$TheNumber =$NumPhrase

Then call it like this:


$TheNumber ="25" #Whatever the lottery number is, set $TheNumber equal to it
CC("NumToWords",ScriptStartWait)

Print($TheNumber)
Sayezb($TheNumber)

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).

#7  

Thanks WBS, I will play with that and let you know how it works.

#8  

@WBS, thanks for the time you spent on that code. DJ added something similar in the latest update - it works good too.

#9  

Yes, I noticed that. Guess I shoulda waited a couple more days before jumping in. :D 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?