VOICEVOX for Laravel est un package pour utiliser les fonctionnalités de synthèse vocale de VOICEVOX depuis Laravel. Il permet de générer de la voix en japonais à partir de texte.
Commencer par le mode client offre la mise en place la plus rapide. Dans un environnement où FFI est disponible, vous pourrez ensuite migrer progressivement vers le mode natif ou le mode API du moteur.
Trois modes d’utilisation
| Mode | Mode d’exécution | FFI | Cas d’usage | Guide |
|---|
| Mode client | Connexion HTTP au moteur officiel VOICEVOX | Non requis | Premier essai, environnement Docker, environnement sans FFI | Client Talk / Client Song |
| Mode natif | Appel direct de VOICEVOX CORE via PHP FFI | Requis | Performance, exécution hors ligne, intégration à des outils CLI | Native Talk / Native Song |
| Mode API du moteur | Laravel expose une API compatible VOICEVOX | Requis | Exposition d’une API, intégration multi-clients | Engine Talk / Engine Song |
Démarrage rapide
Procédure en mode client.
Démarrer le moteur officiel
docker pull voicevox/voicevox_engine:cpu-latest
docker run --rm -p '127.0.0.1:50021:50021' voicevox/voicevox_engine:cpu-latest
Essayer la synthèse vocale
use Revolution\Voicevox\Voicevox;
$response = Voicevox::talk('こんにちは、Laravel です。', id: 1)->generate(id: 1);
$response->storeAs('output.wav');
Fonctionnalités principales
Synthèse vocale (Talk)
use Revolution\Voicevox\Client\TalkAudioQuery;
use Revolution\Voicevox\Voicevox;
$response = Voicevox::talk('こんにちは', id: 1)
->tap(function (TalkAudioQuery $talk) {
$talk->audioQuery['speedScale'] = 1.2;
$talk->audioQuery['pitchScale'] = 0.05;
$talk->audioQuery['intonationScale'] = 1.5;
$talk->audioQuery['volumeScale'] = 1.0;
})
->generate(id: 1);
Synthèse chantée (Song)
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(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),
]);
$response = Voicevox::song($score)->generate(id: 3001);
Dictionnaire utilisateur et presets
En mode client, utilisez la Facade Voicevox pour manipuler le dictionnaire utilisateur et les presets côté moteur officiel.
use Revolution\Voicevox\Voicevox;
$uuid = Voicevox::addWord(
surface: 'Laravel',
pronunciation: 'ララベル',
accentType: 3,
);
$presetId = Voicevox::addPreset([
'id' => 0,
'name' => 'ゆっくり丁寧',
'speaker_uuid' => '7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff',
'style_id' => 1,
'speedScale' => 0.8,
'pitchScale' => 0.0,
'intonationScale' => 1.2,
'volumeScale' => 1.0,
'prePhonemeLength' => 0.1,
'postPhonemeLength' => 0.1,
]);
Intégration Laravel AI SDK
use Laravel\Ai\Audio;
$audio = Audio::of('こんにちは、Laravel です。')
->voice('ずんだもん')
->generate();
$audio->storeAs('output.wav');
Prochaines étapes