---
name: make-music
description: Generate music using Google Lyria 3 (FREE with Gemini API key). 30-second clips or full 2-3 minute songs from text prompts. Genre, BPM, instruments, mood - all controlled via prompt.
argument-hint: <prompt describing the music you want>
allowed-tools: Bash, Read, Write
---

# Music Generation with Google Lyria 3 (FREE)

Generate 30-second music clips or full 2-3 minute songs using Google's Lyria 3 model via the Gemini API. Free tier — no cost.

## Setup

1. Get a free Gemini API key from [Google AI Studio](https://aistudio.google.com/apikey)
2. Set it as an environment variable:
   ```bash
   export GEMINI_API_KEY="your-key-here"
   ```
3. Install the Google GenAI SDK:
   ```bash
   pip install google-genai
   ```

## API Details
- **Model (clips):** `lyria-3-clip-preview` — 30-second clips
- **Model (full songs):** `lyria-3-pro-preview` — 2-3 minute complete songs
- **Output:** MP3, 48kHz stereo, SynthID watermarked
- **Cost:** FREE on Gemini free tier (rate limits apply)

## Prompt Tips

Control everything through the text prompt:
- **Genre:** "lo-fi hip hop", "synthwave", "jazz", "EDM", "acoustic folk"
- **BPM:** "85 BPM", "120 BPM", "140 BPM"
- **Key:** "C minor", "G major", "D minor pentatonic"
- **Instruments:** "Rhodes piano", "TR-808 drums", "acoustic guitar", "analog synths"
- **Mood:** "chill", "energetic", "melancholic", "triumphant", "dreamy"
- **Structure:** `[Intro]`, `[Verse]`, `[Chorus]`, `[Bridge]`, `[Outro]`
- **Vocals:** say "instrumental only" or "no vocals" to skip vocals
- **Timestamps:** `[0:00 - 0:10] Soft piano intro [0:10 - 0:25] Drums kick in`

## Usage

Run this inline Python script to generate music. The prompt is passed via the
`PROMPT` env var and the Python body is a single-quoted heredoc — so the user's
text can't break out of the Python string or inject code.

```bash
PROMPT='$ARGUMENTS' python3 - <<'PYEOF'
import os, time
from google import genai
from google.genai import types

key = os.environ.get('GEMINI_API_KEY')
if not key:
    print('ERROR: Set GEMINI_API_KEY environment variable first')
    print('Get a free key at: https://aistudio.google.com/apikey')
    exit(1)

client = genai.Client(api_key=key)
prompt = os.environ.get('PROMPT', '')
out_dir = os.path.join(os.path.expanduser('~'), '.claude-music-gen')
os.makedirs(out_dir, exist_ok=True)

response = client.models.generate_content(
    model='lyria-3-clip-preview',
    contents=prompt,
    config=types.GenerateContentConfig(response_modalities=['AUDIO', 'TEXT']),
)

ts = int(time.time())
for part in response.candidates[0].content.parts:
    if part.text:
        print(f'INFO: {part.text[:200]}')
    if part.inline_data:
        out = os.path.join(out_dir, f'music_{ts}.mp3')
        with open(out, 'wb') as f:
            f.write(part.inline_data.data)
        print(f'MUSIC: {out} ({len(part.inline_data.data) / 1024:.0f} KB)')
PYEOF
```

## Full-Length Songs

For full 2-3 minute songs with verses/choruses, change the model to `lyria-3-pro-preview`:

```bash
PROMPT='$ARGUMENTS' python3 - <<'PYEOF'
import os, time
from google import genai
from google.genai import types

key = os.environ.get('GEMINI_API_KEY')
if not key:
    print('ERROR: Set GEMINI_API_KEY environment variable first')
    exit(1)

client = genai.Client(api_key=key)
prompt = os.environ.get('PROMPT', '')
out_dir = os.path.join(os.path.expanduser('~'), '.claude-music-gen')
os.makedirs(out_dir, exist_ok=True)

response = client.models.generate_content(
    model='lyria-3-pro-preview',
    contents=prompt,
    config=types.GenerateContentConfig(response_modalities=['AUDIO', 'TEXT']),
)

ts = int(time.time())
for part in response.candidates[0].content.parts:
    if part.text:
        print(f'INFO: {part.text[:200]}')
    if part.inline_data:
        out = os.path.join(out_dir, f'song_{ts}.mp3')
        with open(out, 'wb') as f:
            f.write(part.inline_data.data)
        print(f'SONG: {out} ({len(part.inline_data.data) / 1024:.0f} KB)')
PYEOF
```

> **Note:** If your prompt contains a single quote (`'`), quote-escape it or
> use the Write tool to drop the prompt into a temp file first, then read
> that file in Python. The single-quoted heredoc protects the Python body
> but can't protect the outer `PROMPT='...'` assignment.

## Rate Limits
- Free tier has rate limits (be reasonable — add 30s between calls if generating multiple)
- Clip model: always 30 seconds
- Pro model: 2-3 minutes, full songs

## Limitations
- Non-deterministic (same prompt = different output each time)
- Safety filters block copyrighted content or specific artist voice requests
- Single-turn only (can't iteratively edit a track)

## Requirements
- Python 3.10+
- `google-genai` SDK (`pip install google-genai`)
- Free Gemini API key from [Google AI Studio](https://aistudio.google.com/apikey)
