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

# Clientmodus: song (zangsynthese) - VOICEVOX for Laravel

> Leer hoe je in de clientmodus van VOICEVOX for Laravel zang synthetiseert op basis van een Score en Notes.

## Laten zingen in de clientmodus

Voor zangsynthese in de clientmodus gebruik je de API's `sing_frame_audio_query` en `frame_synthesis` van de officiële VOICEVOX-engine.

Anders dan bij talk moet je eerst een `Score` en `Note`s opbouwen.

## Voorbereiding

```shell theme={null}
docker pull voicevox/voicevox_engine:cpu-latest
docker run --rm -p '127.0.0.1:50021:50021' voicevox/voicevox_engine:cpu-latest
```

## Een `Score` en `Note`s maken

```php theme={null}
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),
]);
```

| Parameter | Type | Beschrijving |
| - | - | - |
| `length` | `int` | Framelengte |
| `lyric` | `string` | Songtekst. Een lege string of weglaten betekent een rust |
| `key` | `int\|null` | MIDI-nootnummer |

> [!TIP]
>
> Met `Note::len($ticks, $bpm)` kun je de framelengte berekenen uit MIDI-ticks en BPM. Het is overzichtelijk om een kwartnoot als 480 ticks te behandelen.

## Basisgebruik

```php theme={null}
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(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 = Voicevox::song($score, teacher: 6000)
    ->generate(id: 3001);

$response->storeAs('client', 'song.wav');
```

### `teacher` en `id`

* `teacher`: het stijl-ID dat aan `sing_frame_audio_query` wordt doorgegeven. Op dit moment bestaat er maar één, namelijk 6000, dus de standaardwaarde is 6000.
* `generate(id:)`: het stijl-ID dat aan `frame_synthesis` wordt doorgegeven

Je kunt de lijst met beschikbare zangstemmen ophalen met `singers()`.

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

$singers = Voicevox::singers();
```

## F0 en volume aanpassen met `tap()`

Bij song is de meerwaarde van `tap()` bijzonder duidelijk: je kunt de `SongAudioQuery` aanpassen voordat je hem doorgeeft aan `generate()`.

```php theme={null}
use Revolution\Voicevox\Client\SongAudioQuery;
use Revolution\Voicevox\Voicevox;

$response = Voicevox::song($score, teacher: 6000)
    ->tap(function (SongAudioQuery $song) {
        $song->sync();
    })
    ->generate(id: 3001);
```

Als je F0 en volume afzonderlijk bijwerkt, doe dat dan in de volgorde **F0 → volume**.

```php theme={null}
->tap(function (SongAudioQuery $song) {
    $song->updateF0();
    $song->updateVolume();
})
```

`tap()` is ook handig wanneer je de Score hebt gewijzigd en opnieuw wilt synchroniseren.

```php theme={null}
->tap(function (SongAudioQuery $song) {
    $song->score->notes[2] = Note::make(length: Note::len(480, 120), lyric: 'ファ', key: 65);
    $song->sync();
})
```

> [!NOTE]
>
> De gedachte achter `tap()` staat samengevat in [De tap()-helper en de Tappable-trait](https://kawax.biz/nl/advanced/tap.md). VOICEVOX for Laravel is een typisch voorbeeld van "alleen het tussenobject aanpassen zonder de returnwaarde te veranderen".

## Volgende pagina's

> [card] [Score en Note in detail](https://kawax.biz/nl/packages/laravel-voicevox/song-score-note.md)
>
> Bekijk de framelengteberekening en patronen voor JSON-beheer.

> [card] [Native song](https://kawax.biz/nl/packages/laravel-voicevox/native-song.md)
>
> Gebruik dezelfde `Score` in de native modus via FFI.

> [card] [VOICEVOX Core for PHP gebruiken](https://kawax.biz/nl/packages/voicevox-core-php/usage.md)
>
> Bekijk de spraaksyntheseflow met alleen de corebibliotheek.


## Related topics

- [Native modus: song (zangsynthese) - VOICEVOX for Laravel](https://kawax.biz/nl/packages/laravel-voicevox/native-song.md)
- [Clientmodus: talk (tekst-naar-spraak) - VOICEVOX for Laravel](https://kawax.biz/nl/packages/laravel-voicevox/client-talk.md)
- [Engine-API-modus: song (zangsynthese) - VOICEVOX for Laravel](https://kawax.biz/nl/packages/laravel-voicevox/engine-song.md)
- [Clientmodus - presets - VOICEVOX for Laravel](https://kawax.biz/nl/packages/laravel-voicevox/client-presets.md)
- [Clientmodus - gebruikerswoordenboek - VOICEVOX for Laravel](https://kawax.biz/nl/packages/laravel-voicevox/client-user-dict.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.