generate command processes your MDX documentation files, extracts text content, generates text-to-speech audio using Fish Audio, uploads the audio to S3-compatible storage, and automatically injects audio player components into your documentation.
Usage
Arguments
Directory containing MDX files to process. Defaults to current directory.
Options
Voice Configuration
Comma-separated list of Fish Audio voice IDs. You can specify multiple voices to generate audio in different styles or languages.Example:
--voices "voice-id-1,voice-id-2"Alternative: Define voices in speaker-config.yaml instead of CLI.Comma-separated list of human-readable voice names. Must match the number of voice IDs provided.Example:
--voice-names "English,Spanish"These names appear in the audio player UI to help users select voices.Fish Audio API
Your Fish Audio API key for generating TTS audio.Alternative: Set
FISH_API_KEY environment variable.S3 Storage Configuration
S3 bucket name where audio files will be stored.Alternative: Set
S3_BUCKET environment variable.AWS region for your S3 bucket.Alternative: Set
S3_REGION environment variable.Custom S3 endpoint URL. Required for S3-compatible services like Cloudflare R2, MinIO, or DigitalOcean Spaces.Example:
--s3-endpoint "https://account-id.r2.cloudflarestorage.com"Alternative: Set S3_ENDPOINT environment variable.S3 access key ID for authentication.Alternative: Set
S3_ACCESS_KEY_ID environment variable.S3 secret access key for authentication.Alternative: Set
S3_SECRET_ACCESS_KEY environment variable.Public CDN URL for accessing uploaded audio files. This URL is embedded in your documentation.Example:
--s3-public-url "https://cdn.example.com"Alternative: Set S3_PUBLIC_URL environment variable.Directory prefix for organizing audio files in S3.Example: With prefix
audio, files are stored as audio/page-slug/voice-id.mp3Component Configuration
Import path for the audio player component. This is the path used in MDX imports.Example:
--component-import "/components/AudioPlayer.jsx"Name of the audio player component to inject into MDX files.Example:
--component-name "AudioPlayer"File Selection
Glob pattern for selecting MDX files to process.Examples:
**/*.mdx- All MDX files recursivelydocs/**/*.mdx- Only files in docs directoryguides/*.mdx- Only top-level guides
Execution Options
Simulate the generation process without making actual changes. Shows a diff preview of what would be modified.Useful for:
- Testing configuration before committing
- Previewing component injection
- Verifying file selection
Show detailed processing information including:
- Extracted text content for each file
- Content hashes
- Full processing results
- File-by-file status
Examples
Basic Usage
Generate audio for all MDX files in current directory:Specify Directory
Process files in a specific directory:Multiple Voices
Generate audio with multiple voices (e.g., different languages):Complete Configuration
Full command with all S3 options:Using Cloudflare R2
Dry Run Preview
Preview changes without modifying files:Specific File Pattern
Process only files in a specific subdirectory:How It Works
- File Discovery: Scans for MDX files matching the specified pattern
- Text Extraction: Extracts clean, readable text from each MDX file (removes code blocks, frontmatter, JSX)
- Hash Generation: Creates a content hash to track changes
- Change Detection: Skips files where content and voices haven’t changed
- TTS Generation: Calls Fish Audio API to generate audio for each voice
- S3 Upload: Uploads generated MP3 files to your S3 bucket
- Component Injection: Adds or updates the audio player component in MDX files
- File Update: Writes modified MDX files back to disk
Smart Caching
The generate command intelligently skips files that haven’t changed:- Each file stores a hash of its text content in the audio component
- On subsequent runs, if the hash matches and voice IDs are the same, generation is skipped
- This saves API costs and processing time
- Forces regeneration by modifying text content or changing voice IDs
Output
Successful execution shows progress for each file:Error Handling
Common errors and solutions:- Missing API key: Set
FISH_API_KEYor use--api-key - S3 authentication failed: Verify access key ID and secret access key
- Bucket not found: Check bucket name and region
- No files found: Verify directory path and glob pattern
- Invalid voice ID: Check voice ID exists in your Fish Audio account
Environment Variables
For convenience, set environment variables instead of CLI options:Configuration File
Createspeaker-config.yaml in your project root:
--voices and --voice-names:
