Hacking Google’s Text To Speech “API”

When I was at my previous job, one task I had was localizing a large set of phrases to multiple languages, both in text and audio files. I did this by using the awesome Google Translate API.

The Google Translate website has features for translating text and playing audio of it in the translated language. There’s no official API for getting audio, though. Luckily, I’ve never let a lack of an official API stop me before.

I had read a few old blog posts about how Google’s undocumented TTS API could be used, albeit with a 100 character limit. Going over 100 characters would result in a truncated audio file. Some of the text I needed to output to audio was longer than that. It turns out that with a little bit of Chrome web inspector, I could replicate the functionality of the Google Translate site.

The first thing to check out is the url scheme of the audio files, which looks like this:

http://translate.google.com/translate_tts?ie=UTF-8&q=hello%20world&tl=en&total=1&idx=0&textlen=11&prev=input

Breaking down the parameters, “ie” is the text’s encoding, “q” is the text to convert to audio, “tl” is the text language, “total” is the total number of chunks (more on that later), “idx” is which chunk we’re on, “textlen” is the length of the text in that chunk and “prev” is not really important.

The Google Translate site itself gets around its own character limit by breaking big blocks of text into “chunks”. It seems to try and break along punctuation, but for super long sentences it will also break in the middle of a sentence, which ends up sounding pretty weird. Using the Gettysburg Address as an example, Google makes a request for the chunk “civil war”.

Gettysburg Address

In order to download audio files for longer chunks of text, I wrote up a python script that broke the text down and made separate requests to Google. The script would write all of the files to one file, and somehow, it worked! Just to be safe, I also set my script up to use Google’s Flash player as the referer (sic) and set the user agent to a version of Firefox.

At the time, I didn’t want to release the code as it was being used for some uber top secret stuff. But since I’m not working on that project anymore, I refactored the original code into a command line Python script. Along the way I had to learn how to use Python’s argparse, which is a pretty neat way of parsing command line arguments.

The project is available on Github right now, so go grab it and try it out. If you’re curious what the output sounds like, here’s a recording of female Abraham Lincoln reciting the Gettysburg Address (yes, she mispronounces some words). One fun thing to try out is outputting clashing input and output languages. Here’s Female Japanese Abraham Lincoln reciting the same speech (she just seems to be spelling words, slacker).

If you enjoyed this hack, let me know and I could post some other ones I’ve been working on. And if you find a way to improve the code (probably not difficult at all) go ahead and submit a pull request on Github. And if you’re from Google, please don’t shut down my Gmail and Adsense accounts.

Google Reader and Skating to Where The Puck Used To Be

I just wrote a couple of tweets about this, but maybe this is a better blog post subject.

Google Reader is shutting down, apparently because its user base is shrinking and Google wants to focus on fewer products. Because of the huge void this will leave, many startups are rushing to fill the space that Google Reader took up. So far I’ve heard of plans from Digg, Flipboard, Zite (whatever that is), Feedly, and maybe some others.

While this might be a good opportunity for those startups, it strikes me as odd. There’s a concept called being a “fast follower” where you copy some innovative company’s product immediately after they release it. Think of Facebook’s clone of that Snapchat app. What we’re seeing now is sort of the “slow(est) follow.”

I suppose it makes sense to go into a space that you know is going to swell up with demand, but honestly, how much longer does the classic Google Reader style app have left? How much of the original Google Reader market are you going to get? Will you be able to re-create the community that the sharebros loved so much? On top of that, do any of these new products have a solid plan on monetization?

To put it another way, what is the opportunity cost of rebuilding Google Reader (even if it’s a “reimagined” version) versus putting time into another product that might actually be new and useful? At this point, it’s probably not worth it considering how many others are eager to clone Reader.

Google Play Vs. iTunes Match

I signed up for the Google Music beta a while ago and promptly forgot about it. I was either too busy to check it out or unimpressed with the feature set. I recently took another look at it after it was renamed to “Google Play.” It’s suddenly making a bit more sense now that I’m trying it out again.

Google Play (I’m really just talking about the music part) lets you upload all of your music to Google’s servers. This step seems kind of dumb but I guess for legal reasons they can’t just recognize your music and use their own copies of songs. I’m sure they’ve got the technology to do it. Anyway, once your music is uploaded you can play it from “the cloud.” While this seems like something so simple that Dropbox could do it, it’s the details that matter. In this case, Google offers a pretty neat interface to listen to your music (and buy more, if desired).

I haven’t used iTunes Match personally, but from what I’ve read, it seems to do something similar. iTunes Match will scan your music library and “match” them up with songs in their database. If a song isn’t on your iPhone but is in your library, you can download and listen to it from your device. So far, it doesn’t seem like there’s a desktop component of iTunes Match besides iTunes (meaning you can’t listen from a website). Also, iTunes Match costs money.

What I like about Google Play is that there is a web interface, so I can listen to all of my music at work without having to download iTunes. I complained earlier on Twitter about how there isn’t a native app for iOS that lets you listen to your Google Play stuff, but there does happen to be a web based player that seems okay. iTunes integrates more easily with your library (no need to actually upload stuff) but seems more rigid about re-downloading music.

Overall, it seems like Google Play is the better service. If it had a native app for iOS it would be the clear winner. Eventually I would like to lower the amount of space on my phone that I’m using for music, which would allow me to have more apps, photos and videos. Hopefully the two services continue to develop and compete with each other to the point where they’re both improving.

Dropbox Referrals with Google Adwords

I read a tweet from someone a while back about how they used Google Adwords to max out their Dropbox referral disk space. I thought this was a clever hack and decided to try it for myself. I made a new Adwords account and entered a coupon code from Dreamhost for $75 in free Adwords money.

I ran into a few issues with my first ads. They were running okay in the beginning, but were getting shot down in the review process for trademark issues. I couldn’t figure out why this was the case, since I had seen multiple blog posts describing how to set up the ads with no mention of trademark issues. I tried a few tweaks, and removed “Mac” from the copy of my ads, thinking that the word might have triggered the trademark issue.

The first set of ads without “Mac” in them ended up getting approved, and I was on the fast track to Dropbox space gluttony. Here’s a screenshot of what my campaign looked like (until I stopped it because I maxed out on referrals):

Things looked like smooth sailing and I think I only used something like $20 worth of credit (though I could’ve easily optimized for spend, I kinda wanted to finish more quickly, so I set my cpcs aggressively). I was gonna change the ads and open it up for friends to get referral space, too.

Then yesterday, with no warning, I got an email that my account had been suspended. There wasn’t really any good explanation for this. When I look at my account, it says:

Your Google AdWords account has been permanently suspended for repeated violation of AdWords or Landing Page and Site policies in this or a related account.

and

Your Google AdWords account has been permanently suspended because your billing information in this or a related account could not be verified.

I’m not sure I could come up with a more vague message. So far, Google Adwords email support has been of no use at all. I first got an email saying they were “escalating” the matter, which probably just means they didn’t get around to it within 24 hours so they had to send something, then I got a generic form email saying that:

After reviewing your account, it has come to our attention that your Google AdWords accounts do not comply with our Terms and Conditions. As a result, your account, and any related accounts you may have created, have been suspended, and your ads will no longer run on Google.

Well no shit, that really doesn’t tell me anything new! The best tidbit of the email was that:

- For privacy reasons, AdWords Support is unable to provide any additional information regarding this account.

You know, in case I find something out about myself that I didn’t know… It’s my account!

If I did something wrong to get banned, I sure would like to know why. Since I don’t, I feel like I’m in the customer support limbo that is synonymous with “Google Support” which is already an oxymoron of sorts.

Anyway, TL;DR I used Adwords to max out my Dropbox referrals like many have before, got the banhammer from Google and now their customer support is atrocious (as expected).

Google, Bing, and SERP Copying: Additional Evidence?

In the beginning of February this year there was some mild uproar about Google setting up an elaborate sting operation against Bing to prove that Bing was copying search results pages directly from Google using the Bing Toolbar. I personally thought it was a bit childish of Google to do this. All’s fair in gathering user-generated data, right?

Fast forward to a few weeks ago. I put some code on Mapskrieg that would auto-detect a mobile device using the useragent string and show a mobile friendly site. I thought this was clever, but apparently Google thought it was cloaking. Oops! My bad. I took a hit on my Google search rankings. Once I fixed the issue my hits from Google have been coming back up slowly.

I looked at Google Analytics to see how the organic search referrals had changed, and I noticed something interesting. Not only had the referrals from Google gone down, the ones from Yahoo and Bing did as well. Perhaps Yahoo and Bing noticed the “cloaking” behavior, too (Yahoo is just using Bing results in their SERPs now). If so, then Bing was a bit slower than Google. See the charts below:

I started getting punished by Google around the 15th of March. Bing seems to have taken a few days to lower my rankings (and thus the # of clicks). My website’s recovery from punishment shows a similar upward trend, even though the site was no longer “cloaking” for about a week before that recovery. This suggests (at least, to me) that Bing really is copying Google’s search results pages. Otherwise they have a very similar method of cloaking detection, a similar policy for punishment, and a similar timeline for reducing the punishment for cloaking… At this point I feel that there are too many coincidences for this to be mere chance.

I was previously on Bing’s side because I figured that the Google data was just one data point out of many that they use. This example makes it seem like Google’s data is THE data point, or at least a major, major part of their “algorithm.”

Having stated all of this, my experience is only a sample size of 1, but I’m sure other webmasters have similar data sitting around. I’d be interested in seeing if there’s more evidence for Google’s stance. If I were Google, I’d be analyzing data from Google Analytics on other websites to see if they agree (I have a feeling they’re allowed to use this data anonymously).

Full Disclosure (because why not?): I used to work for Microsoft AdCenter, but I haven’t been involved with their operations for over a year now. I have a can of Bing soda water on my shelf but I mostly use Google (unless I want to use Bing ironically).

Edit: I’ve gotten some really great comments from Hacker News. I thought I’d paraphrase a few and write my comments on them. If you want to see the actual comments, go directly to my submission.

Comment: How could Bing get SERP info from just the toolbar?
My response: 1) My site drops from many SERP listings, Bing Toolbar stops getting click info for my site so the listings drop from Bing as well.

Comment: It might not be cloaking punishment. It could just be an outside factor, like people generally searching for the site’s keywords less or a competitor coming in and being better.
My response: The traffic to Mapskrieg is pretty darn regular and this was a significant drop for both search engines. Through trial and error the only thing that changed my rankings back was fixing the user agent thing.

Comment: Google suggested that the changes to SERPs took months to propagate and this data only took about a day.
My response: Okay, that’s a good point!

The response from Hacker News has been great and really made me think more about the issue. I’m not sure if Bing really is copying from Google, but I thought this was a worthwhile data point to look at. Maybe someone else has some data they’d like to share as well.