메인 콘텐츠로 건너뛰기

클라이언트 모드에서 노래 부르게 하기

클라이언트 모드의 노래 합성에서는 공식 VOICEVOX 엔진의 sing_frame_audio_queryframe_synthesis API를 사용합니다. 토크와 달리, 먼저 ScoreNote를 조립할 필요가 있습니다.

사전 준비

docker pull voicevox/voicevox_engine:cpu-latest
docker run --rm -p '127.0.0.1:50021:50021' voicevox/voicevox_engine:cpu-latest

ScoreNote 만들기

use Revolution\Voicevox\Song\Note;
use Revolution\Voicevox\Song\Score;

$score = Score::make([
    Note::make(length: 15),
    Note::make(length: Note::len(ticks: 480, bpm: 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),
]);
파라미터타입설명
lengthint프레임 길이
lyricstring가사. 빈 문자열 또는 생략 시 쉼표
keyint|nullMIDI 노트 번호
Note::len($ticks, $bpm)을 사용하면 MIDI의 ticks와 BPM에서 프레임 길이를 계산할 수 있습니다. 4분음표를 480 ticks로 취급하면 이해하기 쉽습니다.

기본적인 사용법

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('client', 'song.wav');

teacherid

  • teacher: sing_frame_audio_query에 전달할 스타일 ID. 현재는 6000 하나만 존재하므로 기본값이 6000.
  • generate(id:): frame_synthesis에 전달할 스타일 ID
사용 가능한 노래 스피커 목록은 singers()에서 획득할 수 있습니다.
use Revolution\Voicevox\Voicevox;

$singers = Voicevox::singers();

tap()으로 F0와 볼륨 조정

Song에서는 tap()의 활용처가 특히 명확하며, SongAudioQuery를 조정한 뒤 generate()로 흘려보낼 수 있습니다.
use Revolution\Voicevox\Client\SongAudioQuery;
use Revolution\Voicevox\Voicevox;

$response = Voicevox::song($score, teacher: 6000)
    ->tap(function (SongAudioQuery $song) {
        $song->sync();
    })
    ->generate(id: 3001);
F0와 볼륨을 개별적으로 업데이트할 경우는 F0 → 볼륨 순서로 실행합니다.
->tap(function (SongAudioQuery $song) {
    $song->updateF0();
    $song->updateVolume();
})
Score를 변경한 뒤 재동기화할 때도 tap()이 편리합니다.
->tap(function (SongAudioQuery $song) {
    $song->score->notes[2] = Note::make(length: Note::len(480, 120), lyric: 'ファ', key: 65);
    $song->sync();
})
tap()의 발상은 tap() 헬퍼와 Tappable 트레이트에 정리되어 있습니다. VOICEVOX for Laravel은 “반환값을 바꾸지 않고 중간 오브젝트만 조정하고 싶다”의 전형적인 예입니다.

다음에 읽어볼 페이지

Score와 Note 상세

프레임 길이 계산과 JSON 관리 패턴을 확인합니다.

네이티브 Song

같은 Score를 FFI 경유의 네이티브 모드에서 사용합니다.

VOICEVOX Core for PHP 사용법

코어 라이브러리 단독 음성 합성 흐름을 확인합니다.
마지막 수정일 2026년 7월 13일