The personal wiki of ...

Exercise: Talking to the User

The nice thing about Python is that you can make use of programs or scripts other people have written. In this exercise we are going to make use of the Android speech to text and speech recognizer interface.

You will need Internet access for this, which means connecting to our School network and entering a password. Test that you are on the network by starting the browser.

Saying Hello

Create a new script on the PC called cyber-speech.py. Type the following:

import android
droid = android.Android()
droid.ttsSpeak('Hey there')

There are some new commands here.

Line 1 tells Python that you are going to use some new commands it hasn't got built in (you save space and complexity by being able to choose what commands you want from a set).

Line 2 tells Python that you want access to the Android programs that are installed on the phone.

Line 3 tells Python that you want to speak the string between the brackets.

Try out the code. What do you think of the accent?

Things to Try

You can change the accent by going to Settings -> Text to Speech Settings -> Language.

Try changing the settings and running again.

Now change line 3 and make it say something you want to hear.

Add some new lines to say additional things.

Echo Chamber

Even better, the phone can recognise your voice. Its not powerful to do it by itself so it uses Google's massive number of servers. Try this program.

import android
droid = android.Android()
echo = droid.recognizeSpeech('Speak','','').result
droid.ttsSpeak(echo)

The key lines here are line 3 where it uses the Google speech recognition service and saves the result in echo and line 4 where the result is used to speak again.

How accurate is it at recognizing your voice?

Things to try

Test the same word with different people saying it.

Try taking one phone and making it speak to an another. How accurate is it?

Siri

Have you heard of Siri?

If you haven't have a look at this video (on your phone).

http://www.youtube.com/watch?v=MpjpVAB06O4

BTW you can watch this on your phone, ask for help if you want to do this.

Below is a cut price version of Siri. It is like echo except that when it recognizes a phrase it uses it to do a google search (line 4).

import android
droid = android.Android()
term = droid.recognizeSpeech('Speak','','').result
droid.startActivity('android.intent.action.VIEW', 'http://www.google.ca/search?q='+term)
Contact Us | Section Map | Disclaimer | RSS feed RSS FeedBack to top ^

Valid XHTML and CSS | Built on Foswiki

Page Updated: 24 Jan 2012 by ian. © Victoria University of Wellington, New Zealand, unless otherwise stated