Text To Speech (TTS)

I found two options for TTS: espeak (from Debian) or using the Google TTS.

First I tried using espeak, which was easy to get going. However it suffers from a drawback that when it speaks long sentence it slows down and sounds like a Dalek (documented here). Since I would be saying things that are >100 words this was not a good solution, but maybe useful for you.

Google TTS works great and is easy to get going, however it suffers from a drawback that you can only say 100 characters at a time. However the speech clarity is nice so I decided to go with this. It is fairly simple to use, the main command is just:

mpg123 -a hw:YOURALSANUMBER -q 'http://translate.google.com/translate_tts?tl=en&q=WORD1%20WORD2%ETC'

You’ll have to install and configure mpg123 to work (there are other places to figure that out, let me know if you need help). Essentially the next part was to write some code that would split the sentences into 100 character sentences. This is accomplished below:

def saySomething(txt,language):
        print "speaking " + language
        words = txt.split()
        numWords = len(words)
        sentences = ""
        curSentence = 0
        curCharacters = 0
        curWord = 0
        for word in words:
                if curCharacters+len(word)+1<100:
                        sentences = sentences+'%20'+word
                        curSentence = curSentence + 1
                        sentences = sentences + "111" + word
                        curCharacters = 0
                curCharacters = curCharacters + len(word)+1
                curWord = curWord + 1

        feedTxt = sentences.split("111")
        for sentence in feedTxt:
                sentence = sentence.replace("'","%27")
                print sentence
                os.system("mpg123 -a hw:1 -q 'http://translate.google.com/translate_tts?tl="+language+"&q=" + sentence + "'")

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: