Between thoughts

Language Learning – Using Anki with GoogleTTS

October 17, 2011

Even though I mentioned Anki (first and later) back in 2008, but not until 2009 I first tried it out for learning French. At that time it was already a pretty good learning tool based on space repetition method. It provides cross-platform desktop and mobile softwares and AnkiWeb with synchronization between them , so that you can learn your topic anywhere.

I typed the French phrases or sentences I learned from Pimsleur so that I could practice later. From typing them, I could also check the spelling part. The only drawback was that I couldn’t practice listening and speaking. Anki does have option to let you add audio files to each card. If you have a phrase book that comes with mp3 files, then it is not a big issue. But what if you don’t have? What if you just want to learn whatever text you input (such as new words from a book or an article)?

Google Translator can translate the text from one language to another and it offers “text to speech” option below the text box. It’s very handy and I use that option sometimes. Mr. Fragoso wrote a small program (GoogleTTS, i.e. Google Text to Speech) to let you generate audio files (mp3) from the text in each card, or play it on the fly (connected to the internet).

This is exactly what I need. :D

However when I first tried it, it took me sometimes to get it work. Part of the reason is that the documentation is not very clear, especially difficult for the Anki newbies. Hopefully the following instruction can be useful for them.

Installation

After download the plugin, restart Anki and it’s ready to go. You can find the plugin shown in Settings\Plugins\Startup. Click at “Open Plugin Folder” to locate GoogleTTS.py file. Open the file using a text editor (like Notepad++), and read the information (usage) on the header.

In “Tools/GoogleTTS”, you can set the language used in Google TTS

The default setting is English. You can change the default setting in GoogleTTS.py ( TTS_language = ‘en’). In my case, I change it to French (fr).

How to Use GoogleTTS

1. Play over the Air

(a) Use hot keys

F3 – get the [GTTS::] tags in the Question pronounced

F4 – get the [GTTS::] tags in the Answer pronounced

F6 – get the whole Question pronounced

F7 – get the whole Answer pronounced

The easiest way is to use F6/F7 hot keys, provided that your card model is “Basic” and only use one language for each field. For instance, below is my French Test. Pressing F7 GoogleTTS will pronounce “l’eau minérale” in French.

However, if Question and Answer (Front/Back field) use different language, then you’ll need to change language every time when you switch field. That’s very inconvenient. You can solve this using the following method.

(b) Use [GTTS::] tag

In Card Layout (visible when you’re reading one of cards or through “Browser” from “Edit\Browse items…”), you can add “<!– [GTTS:en:{{Field Name}}] –>”. Currently I use this method for my French learning. You can download my example “French Numbers“.

Here I want it to pronounce the whole Answer in French. This way will also hide the [GTTS::] tag and everything inside it, as seen in the preview.

You can tells GoogleTTS which section of the text in one field to pronounce by using [GTTS:language_code:text].

Here beside the Arabic number I add English pronunciation in the Question (Front field). It will first pronounce “zero” in English, and then “zéro” in French when clicking “Show Answer”.

Notice that this tag will be visible when viewing the card. The only way to hide it is to set the font color as white.

You now can press F3 to play it again. If press F6 instead, you will hear the whole Question including the tag.

Decks using [GTTS] tags will not be pronounced when viewing them in mobile devices or in AnkiWeb. You’ll need the next method.

2. Generate MP3 Files

(a) Generate MP3 file(s) in one or multiple cards

Highlight the ones you want GoogleTTS to generate MP3 files and choose (A).

Then choose the language, and set the source and destination fields. If I want it automatically to generate MP3 files for the answer, this is how I should set. However, this way also replace the French word in the Answer with the sound file link. In other words, you won’t see the French word, when clicking at “Show Answer”. With [Sound] tag, it makes the file link invisible.

(b) Generate MP3 file(s) by entering the text

In Question or Answer text box, clicking (B) brings up this window.

Enter the text and choose the language you want. You can hear the pronunciation by clicking “Preview”. Clicking “OK”, it will generate the MP3 file and put the file link in place.

Some Notes

This covers the basic of GoogleTTS usage. But if you want the pronunciation working in your mobile devices or in AnkiWeb, you need to do few extra steps. Read this section “Syncing Media” before start generating audio files for your deck.

Like this:

LikeLoading...

Related

Great tute – it’s even easier if you have an android phone. Your can sync a deck to Ankidroid (manually or via a private deck stored on anki’s server). Then the first time you review that deck it will ask you if you want the question and/or answer field(s) read out automatically. All software should be so easy to use!

A short answer is yes, it can. I recently bought a smartphone so I had tried this feature in Ankidroid. Pretty good for the default text-speech engines provided in Android system. Maybe I can demo this in details later.

The better way to do this is to create a new field in card layout. Call the field sound and then when you use Mass generator just select sound as the destination field. Also your card layout will have to look like this:
{{Front}}
{{Back}}{{sound}}

you could put the {{sound}} field wherever you wish to hear the sound such as on the front card or on the back card or both

Hi, I’ve learned english using anki and it was really helpful. Now I’m thinking about learn French but I don’t know how to start. Because I don’t know no one word e so it’s very difficult get a phrase. And I’ve read that isn’t good leave words loose on your cards due the problem that one words can have differents meanings. I’m thinking to start with children’s stories, that usually have simple phrases, but I don’t know. How did you start?

Hi, Lauda. My French is still very limited. What you said is true, that one word can have many meanings. Using flashcard method like Anki is to help memorzing some things. It can be still useful even just to learn part of the meanings of one word or some phrases. To be frank, currently I use Anki to learn to sing some French songs. :P

Reading Children’s stories is a good idea too. You can start with some famous French children’s books. How about Titin’s? :-)

if you DON`T want to overwrite your source field (back of the card) you can simply go to card layout (while viewing any card) and ADD a field (let`s say….”sound”). Then you can go to browser, selct all, source field as back(or wherever the language you want pronounced is) and set the destination as SOUND. done!

I’m a pretty new Anki user learning Arabic vocab, and I’m using Forvo for pronunciations (it’s a great open-source pronunciation site that tells me what Arabic dialect I’m hearing when I download). The problem is, I’m not sure on which side of the card I should add the audio file. Should I do text + audio on one side of the card, and the picture on the other? Or should I do picture + audio on one side, with text on the other? Is there a way to do both?

I just found your post when I was looking for a solution for the exact problem (TTS to create sound files (so that they are also synced to mobile)). And there is a plugin called awesomeTTS (I guess it wasn’t available when you wrote the post). It can also use GoogleTTS and works really well for batch adding the sound files. Maybe you want to check it out. https://ankiweb.net/shared/info/301952613

True, it is not over the air, but if you simply batch add the mp3 files on your desktop once you have it on all your mobile devices. I don’t see any disadvantage in having them generated once instead of everytime again. But if it doesn’t work for you I wish you good luck for your further search :-)