Monday, November 19, 2012

Fibospeak

espeak

Speaking (of) the Fibonacci numbers, did you figure it out?

It is actually quite simple to use espeak. On the Raspberry Pi, we cant use directly the espeak module in Python. We thus have to call the espeak application through the os module.

 import os  

 def say(something):  
   os.system('espeak -ven+f2 "{0}"'.format(something))

 a, b = 0, 1  
 say(a)  
 while b < 50:  
     say(b)  
     a, b = b, a+b  

And that is basically it!

Variations

If we wanted the numbers read in spanish:
   os.system('espeak -ves+f2 "{0}"'.format(something))  

Or in French, male, female and Portuguese, male female:
   os.system('espeak -vfr+m2 "{0}"'.format(something)) 
   os.system('espeak -vfr+f2 "{0}"'.format(something)) 
   os.system('espeak -vpt+m2 "{0}"'.format(something)) 
   os.system('espeak -vpt+f2 "{0}"'.format(something)) 

Under Linux, on a PC with a properly functioning espeak-python module, it would bea little different. After importing espeak, instead of using my function say(), we would use:

   espeak.synth(str(s))

Other options

On the raspberry pi forum, someone pointed to a different approach, which is to use the google translate web service.

Under Linux, but not on the Raspberry Pi (it just clicks instead of speaking), you could also use the Speech Dispatcher server (speechd, python-dispatcher).

Still unresolved

I'll follow up with the visual version tomorrow. There is still time to leave a solution in a comment.

See the next part: Fibovisual

No comments: