How to normalize audio volume in your Anki flashcards

This post describes how we can normalize the volume of audio files in Anki library. I want to make a note on it while I remember. I know this is a niche need, but if Google search led you here, I believe you might appreciate it 😉

Illustration by Karolina Grabowska

Statement of the problem

  • I am using Anki to learn languages with flashcards, specifically: I use AnkiDroid.
  • I have Anki decks (or, collections of flashcards) from various 3rd party sources. Those flashcards include MP3 recordings of words/sentences.
  • The volume level of MP3 files coming from different sources was significantly different.
  • During review of cards, they came in pretty much random order. I had to constantly increase/decrease volume to hear the audio sample. This is totally distracting during learning session and inconvenient.

Solution: how to normalize volume in Anki media collection

I’ll describe my solution in bullet points. This is not a step-by-step tutorial, but it shows that normalization is possible and hints where to start 🙂

  1. I assume you have Anki installed on your PC. Find where Anki stores the media for all your flashcards. In my case, it was:
    C:\Users\{myUserName}\AppData\Roaming\Anki2\User 1\collection.media\
  2. Please back up the collection first! You will make mistakes on the way, guaranteed.
  3. Optionally, but it might help limit the scope of your problem. If you used Anki for some time already, you might have a lot of unused media files (e.g. from courses you imported in the past and deleted). You can easily clean up them by clicking Tools -> Check Media in Anki and confirming that you want to delete obsolete media files.
  4. Normalize your audio files in the media collection folder to the same volume. You can do it any way you want, but here are the key points I learned:
    • ffmpeg is a popular, commonly used tool that allows to achieve that.
    • One of the ffmpeg’s filters allowing to normalize volume level is loudnorm. It worked well, the only issue I encountered was that it didn’t work for audio files shorter than 1 second (But you can find a workaround if you search. Mine was to add a small silent “padding” at the end to make the audio file longer).
    • You need to choose an arbitrary target for what you consider “the optimum volume” for all your media. I chose:
      • integrated loudness target = “-20.0”
      • true peak = “-4.0”
    • At this point, the job is to iterate over files in your collection and normalize them to the same volume level. I created a script (that I won’t be sharing), which for each audio file in the media collection:
      • Launches a small tool named ffmpeg-loudnorm-helper to detect what adjustments needed to made on a file.
      • Launches ffmpeg and passes the parameters output by the above tool.
  5. Now you already have your audio files normalized on your PC. However, Anki won’t sync them, so it won’t solve your problem if you learn on Android or some other machine. To sync the modified files, you additionally need to:
    • If you use Anki 2.0, you can just get the “Refresh media references” add-on
    • If you use Anki 2.1 or newer, you need to hack that add-on a bit and remove one unsupported API call, clearMemoryCaches(), from the add-on’s code. This was suggested in the comments from one of the other users and works. It sounds scary, but it’s just removal of a single line from a text file.
    • After installing the modified add-on, in Anki go to Tools -> Refresh Media.
    • At this point, you can sync and Anki will see and re-upload the changed media files. It can take a few minutes, esp. if you have a large collection of audio files.

Summary

I’d say that while it’s not a rocket science, it still requires a few hours of tinkering. It also requires ability to script/code a simple program and some patience for trial and errors. But if you are serious about learning with your flashcards, the effect is absolutely worth it 🙂

Leave a Comment