Skip to main content

add2anki — add language study cards to Anki

PyPI version Python Version License Code style: ruff CI Changelog

A CLI tool to add language learning cards to Anki, with automatic translation and audio generation.

Currently supports English to Mandarin Chinese translation with audio generation using two providers:

  • Google Translate TTS (default, no authentication required)
  • ElevenLabs (requires API key)

For related language learning resources, visit Oliver Steele's Language Learning Resources.

Features

  • 🔄 Translate English text to Mandarin Chinese using OpenAI's GPT models
  • 🗣️ Support for different translation styles:
    • conversational (default): Natural, everyday language
    • formal: More polite expressions appropriate for business or formal situations
    • written: Literary style suitable for written texts
  • 🔊 Generate high-quality audio for Chinese text using one of two providers:
    • Google Translate TTS (default, no authentication required)
    • ElevenLabs (requires API key)
  • 🃏 Add cards to Anki with translation and audio
  • 🏷️ Add custom tags to notes or use the default "add2anki" tag
  • 🧠 Context-aware language detection that automatically identifies languages
  • 🔍 Automatic detection of suitable note types and field mappings
  • 🔧 Support for custom note types with field name synonyms (Hanzi/Chinese, Pinyin/Pronunciation, English/Translation)
  • 💾 Configuration saved between sessions
  • 📚 Support for batch processing from text, CSV/TSV, or SRT subtitle files
  • 🎬 Parse SRT files to create cards from Mandarin subtitles
  • 🤔 Interactive mode for adding cards one by one

Prerequisites

  • Python 3.11 or higher
  • Anki with the AnkiConnect plugin installed
  • OpenAI API key
  • For audio generation (optional, as Google Translate is used by default):
    • ElevenLabs API key (for ElevenLabs)

Installation

You can install add2anki using either uv, or pipx, or pip:

Using uv

  1. Install uv if you don't have it already.

  2. Install add2anki:

uv tool install add2anki

Using pipx

  1. Install pipx if you don't have it already.

  2. Install add2anki

pipx install add2anki

Using pip (not recommended)

This method doesn't require a third-party tool, but it is not recommended as it will install add2anki in the current Python environment, which may cause conflicts with other packages.

pip install add2anki

Environment Variables

Set the following environment variables:

# Required for translation
export OPENAI_API_KEY=your_openai_api_key

# Required only if using ElevenLabs
export ELEVENLABS_API_KEY=your_elevenlabs_api_key

Quick Start

# Basic usage (uses Google Translate TTS by default)
add2anki "Hello, how are you?"

# Start interactive mode
add2anki

Documentation

Note Type and Deck Selection

add2anki will automatically detect suitable note types in your Anki collection. A suitable note type must have fields that match:

  • Hanzi/Chinese/Characters for the Chinese characters
  • Pinyin/Pronunciation/Reading for the pronunciation
  • English/Translation/Meaning for the English translation

If multiple suitable note types are found, you'll be prompted to select one.

Similarly, if no deck is specified via the --deck option and no previously selected deck is found in the configuration, add2anki will display a list of available decks and prompt you to select one.

Your selections for both note type and deck will be saved for future use.

Configuration

add2anki saves your preferences (deck name, note type, field mappings) in a configuration file:

  • On Windows: %APPDATA%\add2anki\config.json
  • On macOS/Linux: ~/.config/add2anki/config.json

Acknowledgements

This project relies on several excellent libraries:

  • click for building the command-line interface
  • rich for beautiful text formatting
  • pydantic for robust data validation
  • requests for making HTTP requests

Services:

Related Projects

  • audio2anki - Tool to extract foreign language vocabulary from audio transcriptions and add to Anki
  • fast-langdetect - Local language detection for multilingual text

License

MIT

Author

Oliver Steele (@osteele)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

add2anki-0.2.0.tar.gz (99.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

add2anki-0.2.0-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file add2anki-0.2.0.tar.gz.

File metadata

  • Download URL: add2anki-0.2.0.tar.gz
  • Upload date:
  • Size: 99.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for add2anki-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1bafbb8e0d83b1a0f6010b919c1ce227b08c42a320c5231f606dcaa90c144566
MD5 7aebf88235e52927c2bedb4e66258d92
BLAKE2b-256 ce6267cfd6e1e38e6490e0a898c972a39e6afe0f7e9c5a53730c27c622fe95eb

See more details on using hashes here.

File details

Details for the file add2anki-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: add2anki-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for add2anki-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16b762c3faf285ed30833397cfd08d4995fb17f29770c8408058993dce787d72
MD5 46f1159cf5d392622a0618d45c0d2482
BLAKE2b-256 b5e0ffa8a4e6082a718b810b07990400bee26d4f18ee864aca342402cd20cc29

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.2

2 files

0.1.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page