- Introduction
- Features
- Prerequisites
- Installation
- Usage
- Configuration
- Project Structure
- Contributing
- License
- Acknowledgments
The MP3 to Anki Deck Converter is a Python-based tool designed to help language learners and music enthusiasts create interactive Anki decks from MP3 songs. It automates the process of downloading synchronized lyrics, translating them, splitting audio clips, and compiling everything into an Anki deck for effective memorization and learning.
- Download Lyrics: Automatically fetches
.lrc
files (synchronized lyrics) for your MP3 songs. - Anki Deck Creation: Splits MP3 files into individual clips and generates corresponding Anki flashcards with original lyrics and translations.
- Context File Generation: Creates context files containing all cards in a deck for easy reference and management.
- Environment Management: Utilizes environment variables for secure API key management.
- Media Handling: Manages audio clips and Anki deck packages efficiently.
Before using the scripts, ensure you have the following installed:
- Python 3.7+
- Anki (for managing decks)
- AnkiConnect Add-on: Install the AnkiConnect add-on in Anki (Add-on code:
2055492159
)
-
Clone the Repository:
git clone https://github.com/yourusername/AnkiGPT.git cd AnkiGPT
-
Create a Virtual Environment (Optional but Recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
Create a
.env
file in the project root with the following content:DEEPSEEK_API_KEY=your_deepseek_api_key OPENAI_API_KEY=your_openai_api_key
Replace
your_deepseek_api_key
andyour_openai_api_key
with your actual API keys.
The sync_lyrics.py
script automates the process of fetching synchronized .lrc
files for your MP3 songs.
Steps:
-
Prepare Your MP3 Files:
Ensure your MP3 files follow the naming convention:
Song Name - Artist Name.mp3
Example:
Again - Yui.mp3 Departure - Masatoshi Ono.mp3
-
Run the Script:
python sync_lyrics.py
Script Details:
The script scans the current directory for MP3 files, extracts the track and artist names, fetches the corresponding lyrics using the
syncedlyrics
library, and saves them as.lrc
files in the specified output directory.
The lyrics_to_anki.py
script takes an MP3 file and its corresponding .lrc
file to create an Anki deck with flashcards containing audio clips, original lyrics, and their English translations.
< 7972 strong>Steps:
-
Ensure
.lrc
Files are Available:Make sure you've downloaded the
.lrc
files using thesync_lyrics.py
script. -
Run the Script:
python lyrics_to_anki.py "Song Name - Artist Name"
Example:
python lyrics_to_anki.py "Again - Yui"
Script Details:
The script performs the following:
- Splits the MP3 file into individual audio clips based on the timestamps in the
.lrc
file. - Translates the original lyrics to English using the DeepSeek API.
- Generates an Anki deck (
.apkg
file) containing flashcards with audio, original lyrics, and translations.
- Splits the MP3 file into individual audio clips based on the timestamps in the
-
Locate the Generated Anki Deck:
The deck will be saved in the
assets/anki_decks/
directory with the nameSong Name - Artist Name.apkg
. -
Import the Deck into Anki:
Open Anki, go to
File
>Import
, and select the generated.apkg
file to add it to your Anki collection.
The anki_utils.py
script provides utilities to manage and create context files for your Anki decks.
Steps:
-
Run the Script:
python anki_utils.py
Script Details:
The script performs the following:
- Connects to Anki via the AnkiConnect API.
- Retrieves all cards from specified decks.
- Generates context files (
.txt
) containing detailed information about each card for reference.
-
Locate the Generated Context Files:
The context files will be saved in the
assets/anki_context_files/
directory with filenames based on the deck names.
-
Environment Variables:
The application relies on several API keys and directory configurations managed through environment variables. Ensure your
.env
file includes the necessary keys:DEEPSEEK_API_KEY=your_deepseek_api_key OPENAI_API_KEY=your_openai_api_key
-
Directory Structure:
assets/music/
- Contains your MP3 files.assets/audio_clips/
- Stores the split audio clips.assets/anki_decks/
- Stores the generated Anki deck packages.assets/anki_context_files/
- Stores the generated context files.
These directories are automatically created if they do not exist.
AnkiGPT/
├── assets/
│ ├── anki_decks/
│ ├── anki_context_files/
│ ├── audio_clips/
│ └── music/
├── .gitignore
├── anki_utils.py
├── lyrics_to_anki.py
├── sync_lyrics.py
├── README.md
├── requirements.txt
└── .env
Contributions are welcome! Please follow these steps:
- Fork the Repository
- Create a Feature Branch
git checkout -b feature/YourFeature
- Commit Your Changes
git commit -m "Add YourFeature"
- Push to the Branch
git push origin feature/YourFeature
- Open a Pull Request
Please ensure your code adheres to the project's coding standards and includes appropriate documentation.
This project is licensed under the MIT License.
- syncedlyrics for lyrics synchronization
- genanki for Anki deck generation
- AnkiConnect for Anki integration