Saltar al contenido principal

Cantar en modo nativo

En la síntesis de voz cantada del modo nativo se llama directamente a VOICEVOX CORE con PHP FFI. La forma de construir Score y Note es la misma que en modo cliente.

Preparación

  1. Haber completado Instalación y configuración
  2. Tener configurado VOICEVOX Core for PHP
  3. Tener configurado VOICEVOX_CORE_PATH en .env
VOICEVOX_CORE_PATH=/path/to/voicevox_core/
Para usar el modelo de voz cantada, comprueba que s0.vvm esté incluido en core.vvms de config/voicevox.php.

Crear Score y Note

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),
]);

Uso básico

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

$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 = song($score, teacher: 6000)
    ->generate(id: 3001);

$response->storeAs('native', 'song.wav');
Si usas el mismo Score, puedes reutilizar la misma partitura entre modo cliente y modo nativo.

Resincronizar F0 y volumen con tap()

En Song nativo también es útil tap(). Puedes ajustar el SongAudioQuery y pasarlo tal cual a generate().
use Revolution\Voicevox\Song\SongAudioQuery;
use function Revolution\Voicevox\song;

$response = song($score, teacher: 6000)
    ->tap(function (SongAudioQuery $song) {
        $song->sync();
    })
    ->generate(id: 3001);
Si actualizas F0 y volumen por separado, ejecútalos siempre en este orden.
->tap(function (SongAudioQuery $song) {
    $song->updateF0();
    $song->updateVolume();
})

Diferencias con el modo cliente

ElementoCliente SongNativo Song
Arranque del motorNecesarioNo necesario
FFINo requeridoRequerido
Entrada de la APIVoicevox::song()song()
Score / NoteComúnComún
Para el mecanismo de FFI consulta PHP FFI; para el flujo solo con la biblioteca core, consulta Uso de VOICEVOX Core for PHP.

Siguientes páginas

Detalle de Score y Note

Revisa cómo gestionar los datos de partitura de Song en la práctica.

Cliente Song

Compara las diferencias con la versión de cliente HTTP.

Resumen de VOICEVOX for Laravel

Revisa juntos todos los modos y las páginas relacionadas.
Última modificación el 13 de julio de 2026