> ## 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 natif : Song (synthèse vocale chantée) - VOICEVOX for Laravel

> Comment réaliser la synthèse chantée en mode natif de VOICEVOX for Laravel, en appelant VOICEVOX CORE directement via PHP FFI.

## Faire chanter en mode natif

En mode natif, la synthèse chantée appelle directement VOICEVOX CORE via PHP FFI.

La construction de `Score` et de `Note` est identique à celle du mode client.

## Prérequis

1. Avoir terminé [Installation et configuration](/fr/packages/laravel-voicevox/installation)
2. Avoir mis en place [VOICEVOX Core for PHP](/fr/packages/voicevox-core-php)
3. Avoir configuré `VOICEVOX_CORE_PATH` dans le `.env`

```dotenv theme={null}
VOICEVOX_CORE_PATH=/path/to/voicevox_core/
```

Pour utiliser le modèle de chant, vérifiez que `s0.vvm` figure bien dans `core.vvms` de `config/voicevox.php`.

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

## Utilisation de base

```php theme={null}
use Revolution\Voicevox\Song\Note;
use Revolution\Voicevox\Song\Score;
use function Revolution\Voicevox\song;

$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 = song($score, teacher: 6000)
    ->generate(id: 3001);

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

Avec le même `Score`, vous pouvez réutiliser une partition commune entre le mode client et le mode natif.

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

`tap()` est également utile pour Song natif. Après avoir ajusté le `SongAudioQuery`, vous pouvez le passer tel quel à `generate()`.

```php theme={null}
use Revolution\Voicevox\Song\SongAudioQuery;
use function Revolution\Voicevox\song;

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

Pour mettre à jour F0 et volume individuellement, exécutez impérativement dans l'ordre suivant.

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

## Différences avec le mode client

| Élément             | Client Song        | Native Song |
| ------------------- | ------------------ | ----------- |
| Démarrage du moteur | Requis             | Non requis  |
| FFI                 | Non requis         | Requis      |
| Point d'entrée API  | `Voicevox::song()` | `song()`    |
| `Score` / `Note`    | Commun             | Commun      |

<Info>
  Pour le fonctionnement de FFI, consultez [PHP FFI](/fr/advanced/ffi). Pour le flux avec la bibliothèque core seule, consultez [Utilisation de VOICEVOX Core for PHP](/fr/packages/voicevox-core-php/usage).
</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 la gestion pratique des données de partition Song.
  </Card>

  <Card title="Client Song" href="/fr/packages/laravel-voicevox/client-song" icon="music">
    Comparez avec la version client HTTP.
  </Card>

  <Card title="Vue d'ensemble VOICEVOX for Laravel" href="/fr/packages/laravel-voicevox" icon="book-open">
    Retrouvez tous les modes et pages associées.
  </Card>
</Columns>


## Related topics

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