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

# Mode client : Song (synthèse vocale chantée) - VOICEVOX for Laravel

> Comment réaliser la synthèse vocale chantée à partir d'un Score et de Notes en mode client de VOICEVOX for Laravel.

## Faire chanter en mode client

La synthèse chantée en mode client utilise les API `sing_frame_audio_query` et `frame_synthesis` du moteur officiel VOICEVOX.

Contrairement à Talk, il faut d'abord construire un `Score` et des `Note`.

## Prérequis

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

## Créer un `Score` et des `Note`

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

| Paramètre | Type        | Description                                               |
| --------- | ----------- | --------------------------------------------------------- |
| `length`  | `int`       | Longueur en frames                                        |
| `lyric`   | `string`    | Paroles. Une chaîne vide ou l'omission indique un silence |
| `key`     | `int\|null` | Numéro de note MIDI                                       |

<Tip>
  `Note::len($ticks, $bpm)` permet de calculer la longueur en frames à partir des ticks MIDI et du BPM. Il est plus clair de considérer la noire comme valant 480 ticks.
</Tip>

## Utilisation de base

```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` et `id`

* `teacher` : ID de style passé à `sing_frame_audio_query`. Actuellement, seul 6000 existe : c'est la valeur par défaut.
* `generate(id:)` : ID de style passé à `frame_synthesis`.

La liste des locuteurs chantants disponibles peut être obtenue via `singers()`.

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

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

## Ajuster F0 et volume avec `tap()`

En Song, l'utilité de `tap()` est particulièrement claire : vous pouvez ajuster le `SongAudioQuery` avant de le passer à `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);
```

Pour mettre à jour F0 et volume individuellement, exécutez dans l'ordre **F0 → volume**.

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

`tap()` est également pratique lorsque vous voulez modifier le Score puis resynchroniser.

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

<Info>
  L'idée derrière `tap()` est résumée dans [Le helper tap() et le trait Tappable](/fr/advanced/tap). VOICEVOX for Laravel est un cas typique où l'on veut « ajuster uniquement l'objet intermédiaire sans changer la valeur de retour ».
</Info>

## Pages suivantes

<Columns cols={3}>
  <Card title="Détails Score et Note" href="/fr/packages/laravel-voicevox/song-score-note" icon="list-music">
    Découvrez le calcul des longueurs en frames et les patterns de gestion via JSON.
  </Card>

  <Card title="Song natif" href="/fr/packages/laravel-voicevox/native-song" icon="music">
    Utilisez le même `Score` en mode natif via FFI.
  </Card>

  <Card title="Utilisation de VOICEVOX Core for PHP" href="/fr/packages/voicevox-core-php/usage" icon="library">
    Découvrez le flux de synthèse vocale avec la bibliothèque core seule.
  </Card>
</Columns>


## Related topics

- [Mode natif : Song (synthèse vocale chantée) - VOICEVOX for Laravel](/fr/packages/laravel-voicevox/native-song.md)
- [Mode API du moteur : Song (synthèse vocale chantée) - VOICEVOX for Laravel](/fr/packages/laravel-voicevox/engine-song.md)
- [Mode client : Talk (synthèse vocale de texte) - VOICEVOX for Laravel](/fr/packages/laravel-voicevox/client-talk.md)
- [Mode natif : Talk (synthèse vocale de texte) - VOICEVOX for Laravel](/fr/packages/laravel-voicevox/native-talk.md)
- [Mode API du moteur : Talk (synthèse vocale de texte) - VOICEVOX for Laravel](/fr/packages/laravel-voicevox/engine-talk.md)
