This script fetches pronunciation audio for words in Anki flashcards from forvo.com. It processes Anki flashcard export files in plain text format and adds pronunciation audio links to each flashcard. Anki will automatically play those audio.
- Node.js installed on your system.
- Anki app installed on your system.
- Your cards' front side must include only the word you want to fetch pronunciation for. Articles are allowed (see usage for details).
- A Forvo API key is required. The key costs $2/month, with a minimum duration of 6 months.
-
Export your Anki flashcards using the following options:
- Ensure all card fronts are in the target language (the one for which you want to fetch pronunciations).
- Select "Notes as in Plain text" format.
- Uncheck all boxes except for "Include unique identifier."
-
Run the script using the following command:
npx your-script-name \<path-to-file\> \<lang\> --articles \<list\> --key \<forvo-api-key\>
Replace:
<path-to-file>
with the path to your exported Anki file.<lang>
with the ISO 639-1 language code.<list>
with a comma-separated list of articles for the language (optional).<forvo-api-key>
with your Forvo API key.
Example:
npx your-script-name /tmp/Spanish.txt es --articles "el,la" --key your-api-key
- Now audio file are downloaded and notes are updated to include audio. Use Anki
File -> Import
to import notes back. First time you do this I recommend to try it on deck copy. Make sure settings are correct:
If no articles are provided, the script will attempt to fetch pronunciations while ignoring articles if necessary. 3. After processing, a new file with pronunciation links will be generated in the same directory as your original file. See script output for details. 4. Import the new file back into Anki using the "Import" feature. You can either use a new deck or import into an existing deck (existing cards will be updated).
- Forvo API Key: The Forvo API key is mandatory. It costs $2/month with a minimum subscription duration of 6 months. Learn more about pricing on the Forvo API plans page.
- Directory Structure: The script automatically checks for the required directory to save audio files based on your Anki setup. If the directory does not exist, you will need to create it manually.
- axios: For making HTTP requests.
- cheerio: For parsing HTML and extracting data.
- fast-csv: For reading and writing deck files.
- fs: For handling file system operations.
- path: For handling file paths.
- ISO-639-1: For validating ISO 639-1 language codes.
- os: For handling OS-specific operations.
- chalk: For colored console output.
- commander: For command-line interface options.