Anki

Accessing the Anki database with Python: Working with a specific deck

I previously wrote about accessing the Anki database using Python on mac OS. Extending that post, I’ll show how to work with a specific deck in this short post.

To use a named deck you’ll need its deck ID. Fortunately there’s a built-in method for finding a deck ID by name:

col = Collection(COLLECTION_PATH)
dID = col.decks.id(DECK_NAME)

Now in queries against the cards and notes tables we can apply the deck ID to restrict them to a certain deck. For example, to find all of the cards currently in the learning stage:

Working with the Anki database on mac OS using Python

Not long ago I ran across this post detailing a method for opening and inspecting the Anki database using Python outside the Anki application environment. However, the approach requires linking to the Anki code base which is inaccessible on mac OS since the Python code is packaged into a Mac app on this platform.

The solution I’ve found is inelegant; but just involves downloading the Anki code base to a location on your file system where you can link to it in your code. You can find the Anki code here on github.

Process automation in building Anki vocabulary cards

For the last two years, I’ve been working through a 10,000 word Russian vocabulary ordered by frequency. I have a goal of finishing the list before the end of 2019. This requires not only stubborn persistence but an efficient process of collecting the information that goes onto my Anki flash cards.

My manual process has been to work from a Numbers spreadsheet. As I collect information about each word from several websites, I log it in this table.

More Javascript with Anki

I wrote a piece previously about using JavaScript in Anki cards. Although I haven’t found many uses for employing this idea, it does come up from time-to-time including a recent use-case I’m writing about now.

After downloading a popular French frequency list deck for my daughter to use, I noticed that it omits the gender of nouns in the French prompt. In school, I was always taught to memorize the gender along with the noun. For example, when you memorize the word for law, “loi” you should mermorize it with either the definite article “la” or the indefinite article “une” so that the feminine gender of the noun is inseparable from the noun itself. But this deck has only the noun prompt and I was afraid that my daughter would fail to memorize the noun’s gender. JavaScript to the rescue.

Serious audio processing on the command line

I’ve written previously about extracting and processing mp3 files from web pages. The use case that I described, obtaining Russian word pronunciations for Anki cards is basically the same although I’m now obtaining many of my words from Forvo. However, Forvo doesn’t seem to apply any audio dynamic range processing or normalization to the audio files. While many of the pronunciation mp3’s are excellent as-is, some need post-processing chiefly because the amplitude is too low. However, being lazy by nature, I set out to find a way of improving the audio quality automatically before I insert the mp3 file into my new vocabulary cards.

Using macOS NSSpeechSynthesizer to generate audio content for Anki cards

As I’ve written before, I use Anki for Russian language learning. One of the skills to master in learning a foreign language is to quickly speak and recognize numbers. With a little help from macOS, I’ve developed a way of rapidly creating audible content of spoken numbers for my Anki cards.

That’s the good news. The bad news is that as of right now, you’ll have to have Xcode and build the app yourself. Someday, I’ll deal with all the official certificate stuff again (I’ve not developed apps seriously for iOS or macOS for several years now.)

Introducing AnkiStats & AnkiStatsServer

The spaced repetition software system Anki is the de facto standard for foreign language vocabulary learning. Its algorithm requires lots of performance data to schedule flashcards in the most efficient way. Anki displays these statistics in a group of thorough and informative statistical graphs and descriptive text.

However, they aren’t easily available for the end-user to export. Thus, the reason behind the companion projects AnkiStats and AnkiStatsServer.

The premise is that you can run your own more extensive experiments and statistical tests on the data once you have it in hand. A bit of technical expertise is needed to get it operational but if you are up to it, clone the github repos above and go for it.

An easier way to automate synchronization of Anki profiles with AppleScript

After waking up this morning with my mouse locked onto the Anki icon in the dock and trying to figure out how to get Activity Monitor up and running so I could force quite my Automator application that I described yesterday I figured it was back-to-the-drawing board.

I’d like to have used the Accessibility Inspector to manipulate the PyQt objects in Anki’s windows, they aren’t exposed in a may that you can script them. But System Events rules all.

Scheduling synchronization of Anki databases on OS X

While working on a project to automatically collect statistics on my Anki databases (stay tuned…) I worked out a system for scheduling synchronization from my desktop OS X machine.

Prerequisites

  • LaunchControl is a GUI application that lets you create and manage user services on OS X
  • Anki is a spaced repetition memorization software system

The solution relies on Automator. Normally, I don’t care much for Automator. It has too many limits on what tasks I can accomplish and workflows created with it are often fragile. However, in this case, we take advantage of its workflow recording feature. We’re going to record the process of opening Anki, selecting the profile to sync, then quitting Anki. This sequence of events ensures that the database on the local system is synchronized with the remote version.

Resizing of images for Anki with Hazel and ImageMagick

I use Anki to study foreign language vocabulary. It’s the de facto spaced repetition software for memorization.^[Yes, I’m aware that others exist. I’ve tried many but always have come back to Anki.] When making flashcards for language learnings, I try to use imagery as much as possible. So a card may have a Russian word on one side and just an image on the opposite side. (Since I already know the English word that the image represents, why not try to engage a different part of the brain to help with memorization?)