跳转到主要内容

通过引擎 API 让它唱歌

引擎 API 模式也提供与官方 VOICEVOX 引擎兼容的 Song 端点。
关于引擎 API 的基本配置,请先查看 引擎 API:Talk

前置准备

由于要使用歌声模型,请确认 config/voicevox.phpcore.vvms 中包含 s0.vvm(默认已包含)。
VOICEVOX_CORE_PATH=/path/to/voicevox_core/

启动 Laravel 版引擎

php artisan serve --port=50513

生成歌声

1. 创建 sing_frame_audio_query

curl -s -X POST "http://127.0.0.1:50513/sing_frame_audio_query?speaker=6000" \
  -H "Content-Type: application/json" \
  -d '{
    "notes": [
      {"id": "a", "key": null, "frame_length": 15, "lyric": ""},
      {"id": "b", "key": 60, "frame_length": 94, "lyric": "ド"},
      {"id": "c", "key": 62, "frame_length": 94, "lyric": "レ"},
      {"id": "d", "key": 64, "frame_length": 187, "lyric": "ミ"},
      {"id": "e", "key": null, "frame_length": 2, "lyric": ""}
    ]
  }' \
  > frame_audio_query.json
speaker 请指定 singsinging_teacher 类型的 Style ID(例如 6000)。

2. 通过 frame_synthesis 合成音频

curl -s -X POST "http://127.0.0.1:50513/frame_synthesis?speaker=3001" \
  -H "Content-Type: application/json" \
  -d @frame_audio_query.json \
  > song.wav
speaker 请指定 singframe_decode 类型的 Style ID(例如 3001)。

从 Laravel 客户端使用

可以将 Voicevox::song() 指向 Laravel 版引擎。
// config/voicevox.php
'client' => [
    'url' => env('VOICEVOX_URL', 'http://127.0.0.1:50513'),
],
use Revolution\Voicevox\Song\Note;
use Revolution\Voicevox\Song\Score;
use Revolution\Voicevox\Voicevox;

$score = Score::make([
    Note::make(length: 15),
    Note::make(length: Note::len(480, 120), lyric: 'ド', key: 60),
    Note::make(length: Note::len(480, 120), lyric: 'レ', key: 62),
    Note::make(length: Note::len(960, 120), lyric: 'ミ', key: 64),
    Note::make(length: 2),
]);

$response = Voicevox::song($score, teacher: 6000)->generate(id: 3001);

$response->storeAs('engine', 'song.wav');

F0/音量调整端点

curl -s -X POST "http://127.0.0.1:50513/sing_frame_f0?speaker=6000" \
  -H "Content-Type: application/json" \
  -d '{"score": {...}, "frame_audio_query": {...}}' \
  > f0.json

curl -s -X POST "http://127.0.0.1:50513/sing_frame_volume?speaker=6000" \
  -H "Content-Type: application/json" \
  -d '{"score": {...}, "frame_audio_query": {...}}' \
  > volume.json
分别更新 F0 和音量时,请务必按 F0 → 音量 的顺序执行。

Song 相关端点的支持情况

端点Laravel 版Fallback备注
POST /sing_frame_audio_query
POST /frame_synthesis
POST /sing_frame_f0
POST /sing_frame_volume按 f0 → volume 顺序更新
GET /singers
GET /singer_info需要安装资源

下一步阅读

Score 与 Note 详解

了解 Song API 中使用的 Score / Note 详情。

引擎 API:Talk

了解文本语音合成端点的用法。

客户端:Song

了解将相同乐谱直接发给官方引擎的模式。
最后修改于 2026年7月13日