Google GenMedia Toolkit
一个统一的多模态生成工具包,基于 Google 原生多模态 Gemini 模型,支持生成式媒体创作和对话式编辑。
前提条件
该工具包中的所有脚本必须使用 uv run 执行。
uv run scripts/<script_name>.py "PROMPT" [OPTIONS]
工具与参考索引
| 工具 | 脚本 | 参考指南 | 描述 |
|---|---|---|---|
| 图像生成 | scripts/genimage.py | references/genimage.md | Nano Banana 系列(Gemini 3.1 Flash / Pro):文本到图像、4K、修复、风格迁移、14 张参考图像、搜索出发和多轮编辑。 |
| 视频生成 | scripts/genvideo.py | references/genvideo.md | Gemini Omni Flash(gemini-omni-1.1-flash):文本/图像到视频、帧插值、多轮视频编辑和时间扩展。 |
| 音乐生成 | scripts/genmusic.py | references/genmusic.md | Google Lyria 3(Clip & Pro):30 秒片段、带歌词的完整结构化歌曲以及图像到音乐配乐。 |
| 语音合成 | scripts/text2speech.py | references/text2speech.md | Gemini TTS:30 种预构建表现力语音、单说话人旁白和有脚本的多说话人对话。 |
1. 图像生成与编辑:genimage.py
使用 Nano Banana 模型系列(默认 gemini-3.1-flash-image、gemini-3-pro-image、gemini-3.1-flash-lite-image)生成和编辑图像。支持高达 4K 分辨率的 14 种宽高比、多图像合成(最多 14 张参考图像)、Google 搜索出发和多轮对话式编辑。
快速示例
# 文本到图像(2K 分辨率,16:9 宽屏)
uv run scripts/genimage.py "A futuristic cyberpunk city with neon lights and flying cars in rain, cinematic lighting" -a 16:9 -s 2K -o city.jpg
# 对象修复/元素修改
uv run scripts/genimage.py "Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably." -i cat.png -o cat_with_hat.png
# 多轮对话式编辑
uv run scripts/genimage.py "Update this infographic to be in Spanish. Do not change any other elements." --previous-id "v1_interaction_id..." -o infographic_spanish.png
👉 有关详细的提示工程模板(真实感、贴纸、排版、产品模型、风格迁移)和分辨率表,请参阅 references/genimage.md。
2. 视频生成与编辑:genvideo.py
使用 Gemini Omni Flash(gemini-omni-1.1-flash)创建、编辑和扩展带有集成音效设计的电影级视频。支持文本到视频、图像到视频、首尾帧插值、有状态多轮对话式编辑以及视频片段扩展。
快速示例
# 文本到视频(1080p 连续不间断镜头,带音效设计)
uv run scripts/genvideo.py "Continuous smooth drone shot gliding over misty pine forest mountains at sunrise. Sound design: gentle wind breeze, distant bird chirps. No dialogue." -a 16:9 -r 1080p -o sunrise.mp4
# 首尾帧插值
uv run scripts/genvideo.py "A smooth cinematic transition from a lush green summer forest at sunrise to a snowy forest under a starry night sky." -i summer.jpg -i winter.jpg -o season_transition.mp4
# 有状态视频编辑(多轮)
uv run scripts/genvideo.py "Make the violin invisible. Keep everything else the same." --previous-id "v1_video_id..." -o invisible_violin.mp4
# 视频扩展(在片段末尾追加 3-10 秒)
uv run scripts/genvideo.py "Continue the scene: the camera pans across the mountains as twilight sets in." -v clip.mp4 --task extend -o extended_clip.mp4
👉 有关镜头运动技术、音频设计策略以及大尺寸/4K 视频的 URI 交付选项,请参阅 references/genvideo.md。
3. 音乐与歌曲生成:genmusic.py
使用 Google Lyria 3(lyria-3-clip-preview 用于 30 秒片段/循环,lyria-3-pro-preview 用于完整多段落歌曲)合成高保真音乐曲目和配乐。
快速示例
# 器乐配乐主题
uv run scripts/genmusic.py "Uplifting cinematic orchestral soundtrack with energetic strings and inspiring brass crescendo, 120 BPM, instrumental only" -o epic_theme.mp3
# 带有结构化歌词和声乐的完整歌曲
uv run scripts/genmusic.py "Melodic synthwave track with nostalgic 80s analog synth leads, punchy drums, and vocoder vocals singing about neon dreams" -m lyria-3-pro-preview -l lyrics.txt -o synthwave_song.mp3
# 图像到音乐(视觉情绪配乐)
uv run scripts/genmusic.py "Compose ambient soundtrack that captures the mystical and tranquil atmosphere of this fantasy landscape." -i landscape.jpg -o ambient_bgm.mp3
👉 有关五维提示工程(风格、情绪、乐器、节奏、人声)和结构化歌词标签,请参阅 references/genmusic.md。
4. 文本转语音合成:text2speech.py
使用 Gemini TTS(gemini-3.1-flash-tts-preview)合成自然、富有表现力的语音音频。支持 30 种不同的预构建语音、内联情感提示([sighs]、[laughs]、[whispering]、[excitedly])、单说话人旁白和有脚本的多说话人对话。
快速示例
# 带声音提示的单说话人旁白
uv run scripts/text2speech.py "[sighs] Welcome back... [excitedly] Let's create something extraordinary today!" -v Puck -o welcome.wav
# 从文件读取文章
uv run scripts/text2speech.py -f article.txt -v Charon -o article_narration.wav
# 多说话人有脚本对话
uv run scripts/text2speech.py "Alice: [excitedly] Good morning Bob! Have you checked out the new Gemini image model?
Bob: [laughs] Absolutely Alice! The text rendering and thinking mode are mind-blowing." -s "Alice:Aoede" -s "Bob:Fenrir" -o podcast_dialogue.wav
👉 有关所有 30 种预构建语音的完整目录、情感标签目录([xxx])和对话脚本格式指南,请参阅 references/text2speech.md。