Skill: jlin53882/minimax-img (version 1.0.0)

--- name: minimax-image description: Use MiniMax image-01 model to generate images from text prompts. Supports high-quality PNG output, downloaded from Hailuo CDN. Install when needed. homepage: https://platform.minimax.io metadata: {"clawdbot":{"emoji":"🎨","requires":{"bins":["python"]}}} --- # MiniMax Image Generation Call via: `python scripts/minimax_media.py image "<prompt>"` ## Usage ```bash # Basic python scripts/minimax_media.py image "A cute cat" # Detailed prompt python scripts/minimax_media.py image "A futuristic city at sunset, cyberpunk style, highly detailed" ``` Returns: `{"image_path": "...", "url": "...", "size_bytes": ...}` - `image_path`: Local path to saved PNG file - `url`: Direct CDN URL to the generated image - `size_bytes`: File size in bytes ## Prompt Tips - Be specific and descriptive for best results - Include style keywords (e.g., "photorealistic", "anime", "watercolor") - Mention lighting, mood, and composition for more controlled output ## Environment - `MINIMAX_API_KEY` — required - `MINIMAX_BASE_URL` — optional (default: https://api.minimax.io) ## Example Response ```json { "image_path": "/tmp/tmp123.png", "url": "http://hailuo-image-algeng-data-us.oss-us-east-1.aliyuncs.com/...", "size_bytes": 245000 } ```

path: README.md
content: # MiniMax Image Generation Skill

Generate images from text prompts using MiniMax's `image-01` model.

## Setup

1. Install:
   ```bash
   clawhub install minimax-image
   ```

2. Set your API key:
   ```bash
   export MINIMAX_API_KEY=your_key_here
   ```

3. Get your API key at: https://platform.minimax.io

## Usage

```bash
python scripts/minimax_media.py image "A futuristic city at sunset"
```

Returns the local PNG file path and a URL to the generated image.

## Environment Variables

| Variable | Required | Default |
|----------|----------|---------|
| MINIMAX_API_KEY | Yes | - |
| MINIMAX_BASE_URL | No | https://api.minimax.io |

## License

MIT


path: scripts/minimax_media.py
content: #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MiniMax Media Tool - 圖片生成 + 文字轉語音
用法：
  python minimax_media.py image <prompt>
  python minimax_media.py tts <text> [--voice voice_id] [--speed speed] [--output path]
"""
import sys, os, codecs, argparse, json, tempfile, shutil

try:
    import requests
except ImportError:
    print(json.dumps({"error": "requests library not found. Install with: pip install requests"}))
    sys.exit(1)

[REDACTED_SECRET]'MINIMAX_API_KEY', '')
BASE_URL = os.environ.get('MINIMAX_BASE_URL', 'https://api.minimax.io').rstrip('/v1').rstrip('/')


def generate_image(prompt: str, output_path: str = None) -> dict:
    """使用 MiniMax image-01 生成圖片"""
    url = f"{BASE_URL}/v1/image_generation"
    headers = {
        'Authorization': f'Bearer {API_KEY}',
        'Content-Type': 'application/json'
    }
    payload = {
        'model': 'image-01',
        'prompt': prompt
    }
    resp = requests.post(url, headers=headers, json=payload, timeout=60)
    if resp.status_code != 200:
        return {"error": f"API error {resp.status_code}: {resp.text[:200]}"}
    
    data = resp.json()
    image_urls = data.get('data', {}).get('image_urls', [])
    if not image_urls:
        return {"error": "No image URL returned"}
    
    # 下載圖片
    img_resp = requests.get(image_urls[0], timeout=60)
    if img_resp.status_code != 200:
        return {"error": f"Failed to download image: {img_resp.status_code}"}
    
    if output_path is None:
        output_path = tempfile.mktemp(suffix='.png')
    
    with open(output_path, 'wb') as f:
        f.write(img_resp.content)
    
    return {
        "image_path": output_path,
        "url": image_urls[0],
        "size_bytes": len(img_resp.content)
    }


def text_to_speech(text: str, voice_id: str = 'female-tianmei', speed: float = 1.0, output_path: str = None) -> dict:
    """使用 MiniMax speech-2.8-hd 生成語音"""
    url = f"{BASE_URL}/v1/t2a_v2"
    headers = {
        'Authorization': f'Bearer {API_KEY}',
        'Content-Type': 'application/json'
    }
    payload = {
        'model': 'speech-2.8-hd',
        'text': text,
        'stream': False,
        'output_format': 'hex',
        'voice_setting': {
            'voice_id': voice_id,
            'speed': speed,
            'vol': 1,
            'pitch': 0
        },
        'language_boost': 'auto'
    }
    resp = requests.post(url, headers=headers, json=payload, timeout=60)
    if resp.status_code != 200:
        return {"error": f"HTTP error {resp.status_code}: {resp.text[:200]}"}
    
    rdata = resp.json()
    base = rdata.get('base_resp', {})
    if base.get('status_code', 0) != 0:
        return {"error": f"API error {base.get('status_code')}: {base.get('status_msg', '')}"}
    
    audio_hex = rdata.get('data', {}).get('audio', '')
    if not audio_hex:
        return {"error": "No audio data returned"}
    
    # ⚠️ MiniMax TTS V2 回傳的是 hex 字串（不是 base64！），千萬不要用 base64.b64decode()
    audio_bytes = codecs.decode(audio_hex, 'hex')
    
    if output_path is None:
        output_path = tempfile.mktemp(suffix='.mp3')
    
    with open(output_path, 'wb') as f:
        f.write(audio_bytes)
    
    extra = rdata.get('data', {})
    return {
        "audio_path": output_path,
        "size_bytes": len(audio_bytes),
        "duration_hint": f"~{len(audio_bytes)/16000:.1f}s"
    }


def main():
    if len(sys.argv) < 2:
        print(json.dumps({"error": "Usage: minimax_media.py <image|tts> <args...>"}))
        sys.exit(1)
    
    cmd = sys.argv[1].lower()
    
    if cmd == 'image':
        if len(sys.argv) < 3:
            print(json.dumps({"error": "Usage: minimax_media.py image <prompt>"}))
            sys.exit(1)
        prompt = ' '.join(sys.argv[2:])
        result = generate_image(prompt)
        print(json.dumps(result, ensure_ascii=False, indent=2))
        
    elif cmd == 'tts':
        parser = argparse.ArgumentParser(description='MiniMax TTS')
        parser.add_argument('text', help='文字內容')
        parser.add_argument('--voice', default='female-tianmei', help='voice_id')
        parser.add_argument('--speed', type=float, default=1.0, help='速度 0.5-2.0')
        parser.add_argument('--output', default=None, help='輸出檔案路徑')
        args, unknown = parser.parse_known_args(sys.argv[2:])
        result = text_to_speech(args.text, args.voice, args.speed, args.output)
        print(json.dumps(result, ensure_ascii=False, indent=2))
        
    else:
        print(json.dumps({"error": f"Unknown command: {cmd}"}))
        sys.exit(1)


if __name__ == '__main__':
    main()


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)