Monday, May 20, 2013

How to automatically add foreign-language audio to Anki

A few weeks back I explained how to get MP3 audio recordings of your target language from Google Translate. My goal was to add those to Anki so that I could hear the foreign-language pronunciation while reviewing words. I did it, but it was a pain. And I thought to myself, "There's got to be a better way to get audio into Anki…".

Well, wouldn't ya know it? There is. It's in a little Anki plugin called AwesomeTTS, which I concur is a pretty awesome add-on for adding text-to-speech audio to Anki.

AwesomeTTS supports Google Translate and several other text-to-speech services and can be used to automatically add MP3 audio files to your flashcards. As with doing it manually, it has the drawbacks of using text-to-speech (not completely natural, etc.), but if you want to add a large number of audio files quickly, I don't know of any better way.

Installing AwesomeTTS

Anki has a pretty convenient way to install add-ons; you get the add-on's code and paste it into Anki. More specifically:

  1. In Anki, from the "Tools" menu, select "Add-ons" > "Browse & Install...".

  2. In the "Install Add-on" window, copy and paste 301952613 into the "Code" field and click "OK".

  3. Once you've successfully downloaded the add-on, click OK and then quit and then reopen Anki.

Adding audio using AwesomeTTS

AwesomeTTS has a way to do add audio "on the fly" by adding a tag to the card template. My presumption was that this would mean that the audio would somehow be automatically added (AwesomeTTS's page doesn't really elaborate on how this feature works). I added the tag but wasn't able to get that to produce any audio.

However, AwesomeTTS has another way to add audio to your cards, which will actually add MP3 files, and this works just fine on both the desktop and my iPhone:

  1. Open Anki and, in the "Anki" window, click "Browse".

  2. In the "Browser" window, select the cards that you want to add audio to.

  3. From the "Edit" menu, select "AwesomeTTS MP3 Mass Generator".

  4. Set the "Service" to "Google". There are others that you can choose from here as well. I've found Google's text-to-speech to be pretty good and haven't really played with the other services yet.

  5. Set the "Language" to the language you want to generate audio for.

  6. Set the "Source Field" to the field in the card from which you'll get the text that will be converted to speech.

  7. Set the "Destination Field" to the field that, when displayed, will trigger the playing of the audio. If you're specifically trying to learn how a written word is pronounced, this will be different than what you set the "Source Field" to, e.g., if you're trying to learn the pronunciation of a word written with Chinese characters. In most other cases, the "Source Field" and "Destination Field" will be the same.

  8. Select "Write the [sound:] tag at the end of the Destination Field.". This will keep the text you have in that field and add the audio file to the field. Alternatively, if you want to get rid of the text in that field and only have the sound file, select "Overwrite the Destination Field with the sound file path.".

  9. Click OK and then click OK again when it tells you how many notes have been updated.

  10. Repeat steps 3 to 9 for each of the fields to which you want to add audio in those selected cards. That's usually two for me: the word in the foreign language (or the pronunciation of the word, in the case of Japanese or Chinese) and the sentence where I found the word.
You've now got text-to-speech audio in all the cards you selected. When editing the card, you'll see the audio included as a [sound:] tag that includes a named MP3 file after the colon.

34 comments:

  1. Way awesome! Thanks! (You're excel sheet was cool too, but this makes things even easier.) Thanks again!

    ReplyDelete
  2. Glad I could be of help!

    Your comment also made me realize I should probably direct to this page anyone who stumbles across those manual instructions for adding audio from Google Translate, so I added a little header to that post. So thank you!

    ReplyDelete
  3. Thanks a lot! It's so much more convenient now to add audio files to my Anki cards, learning Chinese will become a much faster and more enjoyable process for me since now! 非常感谢!Best greetings from Chengdu, Sichuan!

    ReplyDelete
  4. Thank you so much for this! I just added 1157 audio files to my Russian phrases Anki deck in about 15 minutes (most of it just waiting for the computer). This is fantastic!

    ReplyDelete
  5. You're the best! That's Awesome! Thank you so much!

    ReplyDelete
  6. I recommend text to speech software Panopreter Plus ( http://www.panopreter.com ), it reads any text aloud with natural sounding voices, and converts the text into MP3, so you can listen to the mp3 audio file later at your convenience. Moreover, it includes add-in for Office Word and IE web browser. It's useful for language learning.

    ReplyDelete
  7. Looks kind of crappy, and it definitely doesn't let you get anything into Anki automatically.

    ReplyDelete
  8. Thanks a million! To be honest, I have been searching for a guide article about adding audio to anki atomatically for a long time, this is the most clear one although I would like to use the audio which is from more official website or dictionary such as Duden. And there is a extremely good add-in Download audio:https://ankiweb.net/shared/info/3100585138. What a pity is that i don't know how it use it for atomatically download the audios for all the cards in one deck. Can you help me?

    ReplyDelete
  9. Is there for Thai audio?

    ReplyDelete
  10. The current version of AwesomeTTS doesn't seem to support Thai without modification, but a quick Google search led me to this suggestion, which explains one way that you may be able to make Thai work with AwesomeTTS. I haven't tried it, but if you do I'd be interested in hearing how it went.

    ReplyDelete
  11. that's a great tool !
    I followed every steps but there is no sound when hitting the flashcard in Anki. Only by adding manually a word (by clicking on the Awesome TTS icon, next to all editing tools icons) I am able to hear the word after I inserted it in the textbox.
    Can somebody help.
    Thankx

    ReplyDelete
  12. You have to edit the file 'Anki/addons/awesometts/services/Google.py'.

    After: ['sv', 'Swedish...

    Add: ['th', 'Thai', 'CP874'],



    Then save and restart Anki.

    ReplyDelete
  13. Hi, I've followed the instructions but get no sound, I get audio buttons but there is no sound associated with them. I have looked for the audio files and cannot find them either. Has anyone else had this problem and how did they fix it?

    ReplyDelete
  14. thank you very much, it's working..

    ReplyDelete
  15. Dude, this is beast. Thanks.

    ReplyDelete
  16. Seems like Anki has changed and this doesn't work anymore. I get a million choices in the "source field" and "destination field" and don't know what to pick. I tried "front" and it was all messed up. Any ideas what to do?

    ReplyDelete
  17. It's still working for me. Anki will list up any field names you've used on any note templates you have, and it doesn't get rid of duplicates, which is really annoying. Each note template is typically grouped up in the list, so you should be able to figure out which source and destination field you want through a little trial and error.

    ReplyDelete
  18. I am using Windows version, how could i remove audio files and audio tags added to my source fields? I have a database of 2 thousand words.

    ReplyDelete
  19. I'm having the same problem. I don't see a solution here.

    ReplyDelete
  20. i had to working great but now it simply doesn't work no matter what I do. I've deleted it and reinstalled several time. I loved it when it was working. I wonder if after serveral thousand hits to google translator if it doesn't black list a person at least for a while? I just don't understand why i up and stopped working. It acts as if it makes the mp3 but there is no mp3 of the name in the collection.media. Great great tool though if you get it working. Thanks for your post. Just wondered if you happend to know a work around for this... oh and the Espeak one errors out on me completely! And the windows Sam sounds horrible :/ but i did manage to replace SAMs voice with Isable and it's better not as good as googles

    ReplyDelete
  21. Or you can simply change the name of the specific source and destination fields that you have in mind! Just change it to [Whatever it what called before]-ForAwesomeTTS and it will be super easy to find!

    ReplyDelete
  22. I understand people are following the directions and it doesn't work! I had the exact same problem. Gave up. Then I thought, I would try to mess with the settings of the cards.


    WHAT YOU HAVE TO DO, is you have to change the card settings in the file format. In the image provided I got the cards to work, just with sound alone, and I also managed to get the sound, along with the "type-in" entries. I couldn't get the sound to work with a type in cloze. Again, I was playing around, if someone gets other features to work, please post them.


    Now, I ask that you please review the photo and the format I have for the card settings. Those settings will work for producing sound in a basic card format. You can add the "type in" format too, and that should work. However, as I said, the type in cloze format, I could not get to work.


    You can indicate where you want the sound, Front or Back. This is a great feature. However, what I've noticed is that TTS only records short lines of characters/words. If you go BEYOND this period (maybe 5-10 seconds of writing) the sound in the recording won't play properly if at all, although a file will be produced. You NEED to manually record the character/words with the red record button if it's a recording past 5-10 seconds. This is with Google only, I didn't try the other recording proxies. This should solve most people's (if everyone's) problem. Try it out! Good Luck!

    ReplyDelete
  23. I don't see the photo showing. Perhaps it has to be approved. Here is what you need to type in the FRONT:


    {{Recto}}




    Don't do anything with the Style. Unless you want to! I didn't.


    In the BACK entry, type:
    {{FrontSide}}






    {{Verso}}


    **You need to make sure all your cards have this setting in the cards in your deck to play the sounds of your information. Once your card settings are correct, you will have TTS work. You can records sound in each, the FRONT and BACK.

    ReplyDelete
  24. I tried this with my English to Portuguese cards, and it worked great for the cards up to the first words with an accent mark. Once it hits a word with an accent, it stop working. Any ideas?

    ReplyDelete
  25. Why not use audio tags? The templating engine of Anki is (now, a year later at least) able to interpret HTML5 and I have audio tags in all my cards, like this:







    where {{Front}} is the word in the language to be spoken and the parameter tl in the URL defines which language it is. (en for english, de for german, aso.)


    the only problem is that it's depending on a working internet connection.

    ReplyDelete
  26. the link got destroyed:
    translate.google.com /translate_tts?ie=UTF-8&tl=th&q={{Front}}

    ReplyDelete
  27. Thank you very much for this tutorial. The pictures made the process quick and self explanatory :)

    ReplyDelete
  28. Hi,
    Thank you so much for the detailed information on how to add audio to anki decks.
    I managed to complete the steps for a spanish deck and it seems that the audio is not working. I have the [sound:...] but it does not play. I added BACK for the source and destination for the mp3.
    Many thanks for any advice!!!!

    ReplyDelete
  29. Works like a charm! Thanks

    ReplyDelete
  30. I was able to create a new Field called "AwesomeTTS" audio, which eliminates the little "play" icon from the English card side I generated the audio for. But does anyone know how to have this field automatically play on the mobile apps?


    Also worth nothing... after every 10-15 cards are created, Google Translate seems to time AwesomeTTS out for 30 seconds every time.

    ReplyDelete
  31. Never saw that before. Might be a new thing they're doing.

    ReplyDelete
  32. It has nothing to do with Gogle Translate. It's the just the default configuration of AwesomeTTS. It also affects other services (ImTranslator, Howjsay, Yandex.translate etc.). You can change this behavior in the configuration menu of AwesomeTTS.
    1. On Anki2, click Tools->AwesomeTTS (or just CTRL+T)
    2. Select the MP3s tab menu
    3. Look for "Download Throttling during Batch Processing".
    4. And tweak how often you want AwesomeTTS to timeout.

    ReplyDelete
  33. You can configure this: https://ankiatts.appspot.com/config/mp3s

    ReplyDelete
  34. Just what I needed, thanks

    ReplyDelete