Qué son los presets
Con la funcionalidad de presets puedes guardar combinaciones habituales de parámetros de síntesis de voz y reutilizarlas.
Al gestionar de forma conjunta velocidad, tono, entonación, etc., es más fácil mantener una calidad coherente aunque generes varios audios.
Resumen
La funcionalidad de presets de Laravel VOICEVOX es una implementación nativa que usa VOICEVOX Core. Los datos de los presets se persisten en formato JSON en storage/voicevox/presets.json.
Usa un almacenamiento independiente del motor oficial de VOICEVOX, así que los presets creados en Laravel no se reflejan en el motor oficial (y viceversa).
Configuración
Por defecto se guardan en storage/voicevox/presets.json. Si quieres usar otra ruta, puedes cambiarla en config/voicevox.php.
// config/voicevox.php
return [
'core' => [
'presets' => storage_path('voicevox/presets.json'),
],
];
Estructura del preset
Los presets tienen la siguiente estructura.
[
'id' => 1, // ID del preset (entero, autonumerado)
'name' => 'ゆっくり', // Nombre del preset
'speaker_uuid' => 'uuid', // UUID del speaker (string)
'style_id' => 1, // ID de estilo (entero)
'speedScale' => 0.8, // Velocidad (0.5 a 2.0)
'pitchScale' => 0.0, // Tono (-0.15 a 0.15)
'intonationScale' => 1.0, // Entonación (0.0 a 2.0)
'volumeScale' => 1.0, // Volumen (0.0 a 2.0)
'prePhonemeLength' => 0.1, // Silencio inicial (0.0 a 1.5)
'postPhonemeLength' => 0.1, // Silencio final (0.0 a 1.5)
]
Uso básico
Crear un preset
Puedes crear presets con add() del helper preset().
use function Revolution\Voicevox\preset;
$id = preset()->add([
'id' => 0, // Si indicas 0, se autonumera
'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,
]);
// Se devuelve el ID autonumerado
echo $id; // Ejemplo: 1
Obtener todos los presets
use function Revolution\Voicevox\preset;
$presets = preset()->all();
Buscar un preset
use function Revolution\Voicevox\preset;
$preset = preset()->find(1);
if ($preset !== null) {
echo $preset['name']; // "ゆっくり丁寧"
}
Actualizar un preset
use function Revolution\Voicevox\preset;
preset()->update([
'id' => 1,
'name' => 'ゆっくりはっきり',
'speaker_uuid' => '7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff',
'style_id' => 1,
'speedScale' => 0.7,
'pitchScale' => 0.0,
'intonationScale' => 1.5,
'volumeScale' => 1.0,
'prePhonemeLength' => 0.1,
'postPhonemeLength' => 0.1,
]);
Eliminar un preset
use function Revolution\Voicevox\preset;
preset()->delete(1);
Síntesis de voz con presets
Utiliza el helper talk() o el endpoint /audio_query_from_preset de la Engine API.
Helper talk()
Indica el ID del preset en talk(preset:). En ese caso se ignora el style ID habitual.
use function Revolution\Voicevox\talk;
$response = talk('プリセットを使うのだ', preset: 1)->generate(id: 1);
Con presets aplicados, el flujo normal de síntesis es el mismo. Solo se sustituyen los valores por defecto del AudioQuery con los del preset.
Acceso vía Engine API
Si tienes arrancada la Engine API de Laravel VOICEVOX, puedes manipular los presets por HTTP.
Obtener todos los presets
curl http://localhost:50513/presets
Añadir un preset
curl -X POST http://localhost:50513/add_preset \
-H "Content-Type: application/json" \
-d '{
"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
}'
Actualizar un preset
curl -X POST http://localhost:50513/update_preset \
-H "Content-Type: application/json" \
-d '{
"id": 1,
"name": "ゆっくりはっきり",
"speaker_uuid": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff",
"style_id": 1,
"speedScale": 0.7,
"pitchScale": 0.0,
"intonationScale": 1.5,
"volumeScale": 1.0,
"prePhonemeLength": 0.1,
"postPhonemeLength": 0.1
}'
Eliminar un preset
curl -X POST http://localhost:50513/delete_preset \
-H "Content-Type: application/json" \
-d '{"id": 1}'
Generar audio query con un preset
curl -X POST "http://localhost:50513/audio_query_from_preset?text=こんにちは&preset_id=1"
Detalle de parámetros
speedScale: 0.5 a 2.0 (velocidad)
pitchScale: -0.15 a 0.15 (tono)
intonationScale: 0.0 a 2.0 (entonación)
volumeScale: 0.0 a 2.0 (volumen)
prePhonemeLength: 0.0 a 1.5 (silencio inicial, en segundos)
postPhonemeLength: 0.0 a 1.5 (silencio final, en segundos)
Notas importantes
Los presets de la versión Laravel y los del motor oficial de VOICEVOX se gestionan por separado. Añadir, actualizar y eliminar se guarda inmediatamente en el archivo JSON.
- Si indicas
0 como ID del preset, se autonumera con un ID libre.
- Incluye tanto
speaker_uuid (UUID string) como style_id (entero) en el preset.
Solución de problemas
El preset no se guarda
- Comprueba los permisos de escritura del directorio de storage.
- Comprueba que
storage/voicevox/presets.json se ha creado correctamente.
No sé dónde está el archivo de presets
$path = config('voicevox.core.presets');
echo $path;
Quiero resetear los presets
rm storage/voicevox/presets.json
$path = config('voicevox.core.presets');
if (file_exists($path)) {
unlink($path);
}