Anki is the most popular flash card program out there. The public decks I've come across vary in quality and making your own is all the rage.
This script takes a list of English words and:
- Translates each one using Google Translate
- Generates an audio file of the word/phrase being pronounced in the target language
- Puts it all into an Anki deck (.apkg)
-
Google Cloud Setup:
- Enable the Google Cloud Translate API and Google Cloud Text-to-Speech API.
- Create a service account and download the JSON key file.
-
Install Required Libraries:
pip install -r requirements.txt
The generate_anki_deck.py
script automates the entire process.
python generate_anki_deck.py input_csv output_dir google_credentials_json output_apkg deck_name language_code [--voice_name VOICE_NAME] [--speaking_rate SPEAKING_RATE]
input_csv
: Path to the input CSV file with English text.google_credentials_json
: Path to the Google Cloud service account JSON key file.output_apkg
: Path to the output Anki package file (.apkg).deck_name
: Name of the Anki deck.language_code
: Target language code for translation and TTS (e.g., "ru" for Russian).--voice_name
: (Optional) Voice name for TTS (default:ru-RU-Standard-C
).--speaking_rate
: (Optional) Speaking rate for TTS (default:0.75
).
Example:
python generate_anki_deck.py examples/flashcards.csv google_credentials.json ru_food_beginner.apkg "[RU] Food - Beginner I" ru --voice_name ru-RU-Standard-C --speaking_rate 0.75
To customize for other languages:
- Change the
language_code
argument to the desired target language code (e.g.,es
for Spanish). - Adjust the
voice_name
andspeaking_rate
arguments as needed. Refer to the Google Cloud Text-to-Speech documentation for available voice names and language codes.
The input CSV should have the following format:
English
Hello
Thank you