mcpField
G
google-tts

google-tts

github.com/sanjay3290创意与媒体447327 次安装7 周前更新
代码仓库

关于 google-tts

google-tts 是一款通过 Google Cloud TTS API 将文本和支持的文档转换为音频的 skill。它支持多种语音类型,并提供生成双人播客的工作流。

主要功能

  1. 01合成文本和文档
  2. 02使用 Neural2、WaveNet、Studio 和 Standard 语音
  3. 03调整语音、语速、音高和编码
  4. 04生成双人轮流播报的播客
  5. 05按语言和类型列出语音

适用场景

  1. 01将 PDF 或 DOCX 制作为旁白
  2. 02把书面文本生成 MP3
  3. 03将脚本制作成双人播客

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sanjay3290/ai-skills --skill google-tts

安装后在 Claude Code 中输入/google-tts确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

.gitignore
scripts/
extract.py
google_tts.py

详细介绍

Google Cloud Text-to-Speech

使用 Google Cloud TTS API 将文本和文档转换为音频。支持 40 多种语言的 Neural2、WaveNet、Studio 和 Standard 语音。

设置

通过 GOOGLE_TTS_API_KEY 环境变量或 skills/google-tts/config.json 中的 {"api_key": "..."} 配置 API 密钥。 处理多段文档需要 ffmpeg。可选:安装 pip install PyPDF2 python-docx,用于处理 PDF/DOCX。

命令

列出语音
python skills/google-tts/scripts/google_tts.py voices --language en-US --type Neural2
python skills/google-tts/scripts/google_tts.py voices --json
文本转语音
# From text or document (PDF, DOCX, MD, TXT)
python skills/google-tts/scripts/google_tts.py tts --text "Hello world" --output ~/Downloads/hello.mp3
python skills/google-tts/scripts/google_tts.py tts --file /path/to/doc.pdf --output ~/Downloads/narration.mp3

# With voice, rate, pitch, encoding options
python skills/google-tts/scripts/google_tts.py tts --file doc.md --voice en-US-Neural2-F --rate 0.9 --encoding MP3 --output ~/Downloads/out.mp3
播客生成

接收包含交替发言者的 JSON 脚本,并使用不同语音合成每位发言者的内容。

[
  {"speaker": "host1", "text": "Welcome to our podcast!"},
  {"speaker": "host2", "text": "Thanks for having me..."}
]
python skills/google-tts/scripts/google_tts.py podcast --script /tmp/script.json --output ~/Downloads/podcast.mp3
python skills/google-tts/scripts/google_tts.py podcast --script /tmp/script.json --voice1 en-US-Neural2-J --voice2 en-US-Neural2-H --rate 0.9 --output ~/Downloads/podcast.mp3

工作流

单人旁白
  1. 如果用户提供了文件路径,使用 --file。对于生成的内容,先将通顺的文本写入 /tmp/tts_input.md。
  2. 默认语音:en-US-Neural2-D(男声)或 en-US-Neural2-F(女声)。为兼顾质量和成本,优先使用 Neural2。
  3. 生成音频:python skills/google-tts/scripts/google_tts.py tts --file /tmp/tts_input.md --output ~/Downloads/recording.mp3
  4. 报告文件位置和大小。默认输出到 ~/Downloads/。
根据文档生成播客
  1. 提取文本:python skills/google-tts/scripts/extract.py /path/to/document.pdf
  2. 生成双主持人对话脚本,并保存为 JSON:
    • 采用自然对话,而非逐字朗读。主持人 1 主导对话,主持人 2 回应并分析。
    • 添加开场白和结束语。调整每轮发言的长度。每轮发言不超过 4000 个字符。
  3. 将脚本写入 /tmp/podcast_script.json
  4. 生成音频:python skills/google-tts/scripts/google_tts.py podcast --script /tmp/podcast_script.json --output ~/Downloads/podcast.mp3
  5. 清理临时文件。

参考

  • 推荐语音类型:Neural2(约 $4/100 万字符,质量高)
  • 语速:0.25-4.0(技术内容适合 0.85-0.95)
  • 音高:-20.0 到 20.0 个半音
  • 编码格式:MP3(默认)、LINEAR16(.wav)、OGG_OPUS(.ogg)
  • API 限制:每个请求 5000 字节。脚本会自动按句子边界分段。

评论

支持 Markdown