Yujing (语境): AI Example Sentence and Audio Generator
Yujing (语境) is an Anki add-on designed to provide dynamic context for language learners. It utilizes the OpenAI API to generate new example sentences and corresponding audio for specific cards during the review process. This prevents the "stagnation" of seeing the same example sentence repeatedly, ensuring that each time a word is reviewed, it is presented in a fresh context.
Functionality
- Background Generation: Sentence and audio generation occurs in a background thread triggered when you answer "Good" or "Easy" (Ease score 3 or 4). This allows you to continue your review session without interruption.
- i+1 Principle: The system is designed to generate sentences using simple vocabulary that a learner would already know, ensuring the target word is the only "new" element.
- Text-to-Speech (TTS): Uses OpenAI’s
audio/speech endpoint to generate high-fidelity MP3 files, saved directly to your Anki media folder.
- Automatic Highlighting: The add-on identifies the target word within the new sentence and applies
<b> tags for visual clarity automatically.
Configuration & Setup
To enable Yujing, you must configure your Note Type and the add-on settings via Tools > Yujing Settings.
1. Required Note Fields
The Note Type you are using must include these three specific fields for the add-on to write data:
Generated Sentence: The AI-generated example.
Generated Translation: The translation of the new example.
Generated Audio: The [sound:...] tag for the generated speech.
2. Settings Overview
- API Key: Your OpenAI secret key.
- Target Word Field: The name of the field containing the word you are learning (e.g., "Word" or "Expression").
- Model: Supports models like
gpt-4o-mini (optimized for speed/cost) or gpt-4o.
- Audio Voice: Choose from OpenAI's neural voices: alloy, echo, fable, onyx, nova, shimmer.
3. Prompt Placeholders
The Prompt Template allows you to customize the AI's instructions. You must use the following placeholders to map card data correctly:
{Target}: The word from your target field.
{Generated Sentence}: The existing sentence on the card (helps the AI provide a different context).
{Generated Translation}: The existing translation.
Card Template Example
Paste the following logic into your Back Template. This logic displays the AI-generated content if it exists, otherwise it falls back to your original deck content.
<!-- AI-Generated Section -->
{{#Generated Sentence}}
<div class="ai-sentence">{{Generated Sentence}}</div>
<div class="ai-translation">{{Generated Translation}}</div>
<hr />
{{/Generated Sentence}}
<!-- Original Content Fallback -->
{{^Generated Sentence}}
<div class="original-sentence">{{Sentence}}</div>
<div class="original-translation">{{Translation}}</div>
<hr />
{{/Generated Sentence}}
<!-- Audio Handling -->
<div class="media">
{{#Generated Audio}}
{{Generated Audio}}
{{/Generated Audio}}
{{^Generated Audio}}
{{SentenceAudio}}
{{/Generated Audio}}
</div>
Development and Support
Note: Accuracy of translations and sentences is dependent on the AI model selected. Users are responsible for their own OpenAI API usage costs.