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

# Modalità nativa - Preset - VOICEVOX for Laravel

> Come usare la funzionalità dei preset nella modalità nativa di VOICEVOX for Laravel per salvare e riutilizzare i parametri della sintesi vocale.

## Cos'è un preset

La funzionalità dei preset permette di salvare e riutilizzare combinazioni di parametri di sintesi vocale usate frequentemente.

<Info>
  Gestire insieme velocità di parlata, tono, intonazione, ecc. rende più facile mantenere una qualità coerente anche quando generi più audio.
</Info>

## Panoramica

La funzionalità dei preset di Laravel VOICEVOX è un'implementazione nativa che utilizza VOICEVOX Core. I dati dei preset vengono persistiti in formato JSON in `storage/voicevox/presets.json`.

Poiché usa uno storage indipendente dal VOICEVOX Engine ufficiale, i preset creati lato Laravel non si riflettono lato engine ufficiale (e viceversa).

## Configurazione

Per impostazione predefinita vengono salvati in `storage/voicevox/presets.json`. Se vuoi usare un percorso diverso, puoi cambiarlo in `config/voicevox.php`.

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

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

## Struttura di un preset

Un preset ha la seguente struttura.

```php theme={null}
[
    'id' => 1,                 // ID del preset (intero, numerato automaticamente)
    'name' => 'ゆっくり',       // Nome del preset
    'speaker_uuid' => 'uuid',  // UUID dello speaker (stringa)
    'style_id' => 1,           // ID dello stile (intero)
    'speedScale' => 0.8,       // Velocità (0.5 - 2.0)
    'pitchScale' => 0.0,       // Tono (-0.15 - 0.15)
    'intonationScale' => 1.0,  // Intonazione (0.0 - 2.0)
    'volumeScale' => 1.0,      // Volume (0.0 - 2.0)
    'prePhonemeLength' => 0.1, // Silenzio iniziale (0.0 - 1.5)
    'postPhonemeLength' => 0.1, // Silenzio finale (0.0 - 1.5)
]
```

## Uso di base

### Creazione di un preset

Puoi creare un preset con `add()` dell'helper `preset()`.

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

$id = preset()->add([
    'id' => 0, // se specifichi 0 viene assegnato automaticamente
    '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,
]);

// Restituisce l'ID assegnato automaticamente
echo $id; // esempio: 1
```

### Recupero di tutti i preset

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

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

### Ricerca di un preset

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

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

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

### Aggiornamento di 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,
]);
```

### Eliminazione di un preset

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

preset()->delete(1);
```

## Sintesi vocale con un preset

Usa l'helper `talk()` o l'endpoint `/audio_query_from_preset` dell'API Engine.

### Helper `talk()`

Specifica l'ID del preset in `talk(preset:)`. In tal caso il normale ID di stile viene ignorato.

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

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

<Tip>
  Anche quando applichi un preset, il flusso di sintesi vocale rimane lo stesso. Cambiano solo i valori dell'`AudioQuery` predefinito, sostituiti dal preset.
</Tip>

### Accesso tramite API Engine

Quando è avviata l'API Engine di Laravel VOICEVOX, puoi gestire i preset via HTTP.

#### Recupero di tutti i preset

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

#### Aggiunta di 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
  }'
```

#### Aggiornamento di 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
  }'
```

#### Eliminazione di un preset

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

#### Generare una query audio da un preset

```bash theme={null}
curl -X POST "http://localhost:50513/audio_query_from_preset?text=こんにちは&preset_id=1"
```

## Dettagli dei parametri

* `speedScale`: da 0.5 a 2.0 (velocità)
* `pitchScale`: da -0.15 a 0.15 (tono)
* `intonationScale`: da 0.0 a 2.0 (intonazione)
* `volumeScale`: da 0.0 a 2.0 (volume)
* `prePhonemeLength`: da 0.0 a 1.5 (silenzio iniziale, in secondi)
* `postPhonemeLength`: da 0.0 a 1.5 (silenzio finale, in secondi)

## Note

<Warning>
  I preset della versione Laravel e quelli del VOICEVOX Engine ufficiale sono gestiti separatamente. Le operazioni di aggiunta, aggiornamento ed eliminazione vengono salvate immediatamente nel file JSON.
</Warning>

* Se specifichi `0` come ID del preset, viene assegnato automaticamente un ID non usato.
* Il preset deve includere sia `speaker_uuid` (stringa UUID) sia `style_id` (intero).

## Risoluzione dei problemi

### Il preset non viene salvato

1. Controlla i permessi di scrittura sulla directory di storage
2. Verifica che `storage/voicevox/presets.json` sia stato creato correttamente

### Non trovi il percorso del file dei preset

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

### Reimpostare i preset

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

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


## Related topics

- [Modalità client - Preset - VOICEVOX for Laravel](/it/packages/laravel-voicevox/client-presets.md)
- [Modalità nativa - Dizionario utente - VOICEVOX for Laravel](/it/packages/laravel-voicevox/native-user-dict.md)
- [Modalità nativa: Song (sintesi vocale canora) - VOICEVOX for Laravel](/it/packages/laravel-voicevox/native-song.md)
- [Modalità nativa: Talk (sintesi vocale da testo) - VOICEVOX for Laravel](/it/packages/laravel-voicevox/native-talk.md)
- [Modalità client - Dizionario utente - VOICEVOX for Laravel](/it/packages/laravel-voicevox/client-user-dict.md)
