This project is a Python application that automatically generates high-quality Japanese Anki flashcards from a simple word list using OpenAI's language models. It streamlines the process of creating comprehensive study materials for Japanese language learners.
- AI-Powered Content Generation: Uses OpenAI to create accurate and natural-sounding example sentences and definitions
- Complete Flashcard Information: Each card includes:
- Word in Japanese (kanji)
- Reading in hiragana with NHK standard pitch accent notation
- Two contextual example sentences
- English translation/definition
- Audio pronunciation for the word, examples, and definition
- Automatic Anki Integration: Directly imports generated cards into your Anki collection
- Batch Processing: Process multiple words at once efficiently
- Python 3.6+
- Anki desktop application
- AnkiConnect add-on installed in Anki
- Internet connection for OpenAI API and audio generation
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yourusername/Infinite-Flashcards.git cd Infinite-Flashcards -
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the root directory with your API keys:OPENAI_API_KEY=your_openai_api_key_here ANKI_CONNECT_URL=http://localhost:8765 ANKI_DECK_NAME=Japanese -
Ensure you have Anki installed and set up with the AnkiConnect add-on.
- Install Anki if you haven't already
- Install the AnkiConnect add-on in Anki:
- Open Anki
- Go to Tools > Add-ons > Get Add-ons
- Enter the code:
2055492159 - Restart Anki
-
Add your Japanese words to the
words.txtfile in thecard_generation_scriptsfolder:- One word per line or space-separated words
- Example:
食べ物 勉強 日本語
-
Make sure Anki is running with the AnkiConnect add-on active
-
Run the main script:
python main.py
When you first run the script, it will create an empty
words.txtfile if one doesn't exist. You can also refer to thewords-EXAMPLE.txtfile for reference. -
The script will:
- Generate detailed card content using OpenAI
- Create audio files for pronunciation
- Build an Anki package
- Import the cards into your specified Anki deck
Infinite-Flashcards/
├── .env # Environment variables (API keys, etc.)
├── .env_example # Example environment file
├── .gitignore # Git ignore file
├── README.md # This documentation file
├── requirements.txt # Python dependencies
├── main.py # Main script to run the application
├── utils.py # Utility functions
├── variables.py # Global variables and configurations
└── card_generation_scripts/ # Directory containing card generation scripts
├── generate_csv.py # Creates CSV with word data from OpenAI
├── generate_audio.py # Generates audio files using gTTS
├── make_anki_pkg.py # Creates Anki package from CSV and audio
├── import_to_anki.py # Imports the package into Anki
├── create_text_files.py # Creates necessary text files
├── words-EXAMPLE.txt # Example word file for reference
└── words.txt # Your list of Japanese words to process
- Model Selection: You can modify the OpenAI model in
generate_csv.py(default iso1-mini) - Card Format: Edit the template in
make_anki_pkg.pyto change card appearance - Audio Settings: Adjust settings in
generate_audio.pyfor different voices or audio quality. The application uses Google's Text-to-Speech (gTTS) service to generate audio pronunciations.
- Anki Connection Error: Ensure Anki is running and AnkiConnect add-on is properly installed
- API Key Issues: Verify your OpenAI API key is correct and has sufficient credits
- File Not Found Errors: Make sure the
words.txtfile exists and contains words to process - Python Environment Issues: If you encounter dependency errors, try creating a virtual environment before installing requirements
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
このプロジェクトは、OpenAI を使用して日本語の単語リストから Anki フラッシュカードを自動生成する Python アプリケーションです。日本語学習者が質の高い学習教材を簡単に作成できるようにします。
- AI 駆動コンテンツ生成: OpenAI を使用して正確で自然な例文と定義を作成
- 完全なフラッシュカード情報: 各カードには以下が含まれます:
- 日本語の単語(漢字)
- ひらがなでの読み方と NHK 標準のピッチアクセント表記
- 二つの文脈的な例文
- 英語での翻訳・定義
- 単語、例文、定義の音声発音
- Anki 自動連携: 生成されたカードを直接 Anki コレクションにインポート
- バッチ処理: 複数の単語を一度に効率的に処理
- Python 3.6 以上
- Anki デスクトップアプリケーション
- Anki の AnkiConnect アドオン
- OpenAI API とオーディオ生成のためのインターネット接続
- OpenAI API キー
-
リポジトリをクローンします:
git clone https://github.com/yourusername/Infinite-Flashcards.git cd Infinite-Flashcards -
必要な依存関係をインストールします:
pip install -r requirements.txt
-
ルートディレクトリに
.envファイルを作成し、API キーを設定します:OPENAI_API_KEY=あなたのOpenAI_APIキーをここに入力 ANKI_CONNECT_URL=http://localhost:8765 ANKI_DECK_NAME=Japanese -
Anki がインストールされ、AnkiConnect アドオンで設定されていることを確認します。
- まだインストールしていない場合は Anki をインストールします
- Anki に AnkiConnect アドオン をインストールします:
- Anki を開く
- ツール > アドオン > アドオンを取得する に進む
- コード「2055492159」を入力
- Anki を再起動
-
card_generation_scriptsフォルダ内のwords.txtファイルに日本語の単語を追加します:- 1 行に 1 単語、またはスペースで区切られた単語
- 例:
食べ物 勉強 日本語
-
AnkiConnect アドオンが有効な状態で Anki が実行されていることを確認します
-
メインスクリプトを実行します:
python main.py
初めてスクリプトを実行する場合、
words.txtファイルが存在しなければ空のファイルが作成されます。参考としてwords-EXAMPLE.txtファイルも確認できます。 -
スクリプトは以下を行います:
- OpenAI を使用して詳細なカードコンテンツを生成
- 発音のための音声ファイルを作成
- Anki パッケージを構築
- 指定した Anki デッキにカードをインポート
Infinite-Flashcards/
├── .env # 環境変数(APIキーなど)
├── .env_example # 環境ファイルの例
├── .gitignore # Gitの無視ファイル
├── README.md # このドキュメントファイル
├── requirements.txt # Python依存関係
├── main.py # アプリケーションを実行するメインスクリプト
├── utils.py # ユーティリティ関数
├── variables.py # グローバル変数と設定
└── card_generation_scripts/ # カード生成スクリプトを含むディレクトリ
├── generate_csv.py # OpenAIから単語データを含むCSVを作成
├── generate_audio.py # gTTSを使用して音声ファイルを生成
├── make_anki_pkg.py # CSVとオーディオからAnkiパッケージを作成
├── import_to_anki.py # パッケージをAnkiにインポート
├── create_text_files.py # 必要なテキストファイルを作成
├── words-EXAMPLE.txt # 参考用の単語ファイル例
└── words.txt # 処理する日本語単語のリスト
- モデル選択:
generate_csv.pyで OpenAI モデルを変更できます(デフォルトはo1-mini) - カードフォーマット:
make_anki_pkg.pyのテンプレートを編集してカードの外観を変更 - オーディオ設定:
generate_audio.pyの設定を調整して、異なる音声や音質を設定。このアプリケーションは Google の Text-to-Speech(gTTS)サービスを使用して音声発音を生成します。
- Anki 接続エラー: Anki が実行中で、AnkiConnect アドオンが適切にインストールされていることを確認
- API キーの問題: OpenAI API キーが正しく、十分なクレジットがあることを確認
- ファイルが見つからないエラー:
words.txtファイルが存在し、処理する単語が含まれていることを確認 - Python 環境の問題: 依存関係エラーが発生した場合は、要件をインストールする前に仮想環境を作成してみてください
貢献は大歓迎です!プルリクエストを自由に提出してください。
MIT