> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Modo nativo - Presets - VOICEVOX for Laravel

> Explica cómo usar la funcionalidad de presets en modo nativo de VOICEVOX for Laravel para guardar y reutilizar parámetros de síntesis de voz.

## Qué son los presets

Con la funcionalidad de presets puedes guardar combinaciones habituales de parámetros de síntesis de voz y reutilizarlas.

<Info>
  Al gestionar de forma conjunta velocidad, tono, entonación, etc., es más fácil mantener una calidad coherente aunque generes varios audios.
</Info>

## 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`.

```php theme={null}
// config/voicevox.php

return [
    'core' => [
        'presets' => storage_path('voicevox/presets.json'),
    ],
];
```

## Estructura del preset

Los presets tienen la siguiente estructura.

```php theme={null}
[
    '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()`.

```php theme={null}
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

```php theme={null}
use function Revolution\Voicevox\preset;

$presets = preset()->all();
```

### Buscar un preset

```php theme={null}
use function Revolution\Voicevox\preset;

$preset = preset()->find(1);

if ($preset !== null) {
    echo $preset['name']; // "ゆっくり丁寧"
}
```

### Actualizar un preset

```php theme={null}
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

```php theme={null}
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.

```php theme={null}
use function Revolution\Voicevox\talk;

$response = talk('プリセットを使うのだ', preset: 1)->generate(id: 1);
```

<Tip>
  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.
</Tip>

### Acceso vía Engine API

Si tienes arrancada la Engine API de Laravel VOICEVOX, puedes manipular los presets por HTTP.

#### Obtener todos los presets

```bash theme={null}
curl http://localhost:50513/presets
```

#### Añadir un preset

```bash theme={null}
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

```bash theme={null}
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

```bash theme={null}
curl -X POST http://localhost:50513/delete_preset \
  -H "Content-Type: application/json" \
  -d '{"id": 1}'
```

#### Generar audio query con un preset

```bash theme={null}
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

<Warning>
  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.
</Warning>

* 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

1. Comprueba los permisos de escritura del directorio de storage.
2. Comprueba que `storage/voicevox/presets.json` se ha creado correctamente.

### No sé dónde está el archivo de presets

```php theme={null}
$path = config('voicevox.core.presets');
echo $path;
```

### Quiero resetear los presets

```bash theme={null}
rm storage/voicevox/presets.json
```

```php theme={null}
$path = config('voicevox.core.presets');
if (file_exists($path)) {
    unlink($path);
}
```


## Related topics

- [Modo cliente - Presets - VOICEVOX for Laravel](/es/packages/laravel-voicevox/client-presets.md)
- [Modo nativo - Diccionario de usuario - VOICEVOX for Laravel](/es/packages/laravel-voicevox/native-user-dict.md)
- [Modo nativo: Song (síntesis de voz cantada) - VOICEVOX for Laravel](/es/packages/laravel-voicevox/native-song.md)
- [Modo nativo: Talk (síntesis de voz desde texto) - VOICEVOX for Laravel](/es/packages/laravel-voicevox/native-talk.md)
- [Modo cliente - Diccionario de usuario - VOICEVOX for Laravel](/es/packages/laravel-voicevox/client-user-dict.md)
