Gemini图像音频生成工具

基于Google Gemini AI模型,提供文本生成图像和音频的多媒体内容生成服务。

  • by ServiceStack
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 ServiceStack/gemini-gen-mcp

使用说明

Gemini Gen MCP

MCP服务器,用于使用谷歌的Gemini AI模型生成Gemini图像和音频。

特性

此MCP服务器提供以下工具:

  • 从文本生成图像 使用Gemini的Flash图像模型
  • 从文本生成音频 使用Gemini 2.5 Flash预览TTS模型

安装

来自PyPI

pip install gemini-gen-mcp

来源

git clone https://github.com/ServiceStack/gemini-gen-mcp.git
cd gemini-gen-mcp
pip install -e .

先决条件

您需要一个Google Gemini API密钥才能使用此服务器。从以下位置获取一个 谷歌AI工作室.

环境变量

变量 必填 默认 描述
GEMINI_API_KEY 是 - 您的Google Gemini API密钥
GEMINI_DOWNLOAD_PATH 没有 /tmp/gemini_gen_mcp 保存生成文件的目录

设置环境变量:

export GEMINI_API_KEY='your-api-key-here'
export GEMINI_DOWNLOAD_PATH='/path/to/downloads'  # optional

生成的文件按类型和日期组织:

  • 图像: $GEMINI_DOWNLOAD_PATH/images/YYYY-MM-DD/
  • 音频: $GEMINI_DOWNLOAD_PATH/audios/YYYY-MM-DD/

每个生成的文件都包含一个伴随文件 .info.json 包含生成元数据的文件。

用法

运行服务器

直接运行MCP服务器:

gemini-gen-mcp

或者作为Python模块:

python -m gemini_gen_mcp.server

与Claude Desktop一起使用

看 CLAUDE_CONFIG.md 详细说明。

将此添加到您的或 claude_desktop_config.json:

{
  "mcpServers": {
    "gemini-gen": {
      "description": "Gemini Image and Audio TTS generation",
      "command": "uvx",
      "args": [
        "gemini-gen-mcp"
      ],
      "env": {
        "GEMINI_API_KEY": "$GEMINI_API_KEY"
      }
    }
  }
}

在llms.py中使用

或将服务器配置粘贴到 llms.py MCP服务器:

姓名: gemini-gen

{
  "description": "Gemini Image and Audio TTS generation",
  "command": "uvx",
  "args": [
    "gemini-gen-mcp"
  ],
  "env": {
    "GEMINI_API_KEY": "$GEMINI_API_KEY"
  }
}

开发服务器

对于开发,您可以使用以下命令运行此服务器 uv:

{
  "mcpServers": {
    {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/path/to/ServiceStack/gemini-gen-mcp",
        "gemini-gen-mcp"
      ],
      "env": {
        "GEMINI_API_KEY": "$GEMINI_API_KEY"
      }
    }
  }
}

可用工具

text_to_image

使用Gemini的图像生成模型从文本描述生成图像。

参数:

  • prompt (string,必填):要生成的图像的文本描述
  • model (字符串,可选):使用Gemini模型
    • gemini-2.5-flash-image (默认)
    • gemini-3-pro-image-preview
  • aspect_ratio (字符串,可选):生成图像的纵横比(默认值:“1:1”)
    • 支持: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
  • temperature (浮动,可选):图像生成的采样温度(默认值:1.0)
  • top_p (浮点数,可选):Nucleus采样参数(可选)

例子:

{
  "prompt": "A serene mountain landscape at sunset with a lake",
  "model": "gemini-2.5-flash-image",
  "aspect_ratio": "16:9",
  "temperature": 1.0
}

text_to_audio

使用Gemini的TTS模型从文本生成音频/语音。输出保存为WAV格式。

参数:

  • text (字符串,必填):要转换为语音的文本
  • model (字符串,可选):要使用的Gemini TTS模型
    • gemini-2.5-flash-preview-tts (默认)
    • gemini-2.5-pro-preview-tts
  • voice (字符串,可选):用于语音生成的语音(默认值:“Kore”)

可用声音:

声音 风格 声音 风格 声音 风格
Zephyr 明亮 Puck 乐观 Charon 信息丰富
Kore 坚定 Fenrir 令人兴奋 Leda 年轻
Orus 坚定 Aoede 微风 卡利罗 随和
Autonoe 明亮 土卫二 透气 土卫八 清澈
雨伞 轻便 阿尔吉巴 光滑 绝望 光滑
Erinome Clear Algenib Gravelly Rasalgethi 资料性
拉俄墨迪亚 乐观 Achernar 软弱 阿尼拉姆 坚定
Schedar 偶数 Gacrux 成熟 Pulcherrima 前锋
Achird 友善 Zubenelgenubi 休闲 Vindemiatrix 温柔
Sadachbia 活泼 Sadaltager 知识渊博 Sulafat 温暖

例子:

{
  "text": "Hello, this is a test of the Gemini text to speech system.",
  "model": "gemini-2.5-flash-preview-tts",
  "voice": "Kore"
}

发展

设置开发环境

# Clone the repository
git clone https://github.com/ServiceStack/gemini-gen-mcp.git
cd gemini-gen-mcp

# Install in editable mode with dependencies
pip install -e .

运行测试

# Install test dependencies
pip install pytest pytest-asyncio

# Run tests
```bash
# uv run pytest tests -v
npm test

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

贡献

欢迎投稿!请随时提交拉取请求。

支持

有关问题和疑问,请使用 GitHub 问题 页面。

致谢

链接