> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# Diffusion de musique

> **Note**
>
> **Guide pratique** · Suppose que vous avez terminé le [démarrage rapide de Music](/docs/fr/eleven-api/guides/cookbooks/music).

> **Info**
>
> L’API Music est réservée aux utilisateurs payants.

## Utiliser l’API Music

> **Note**
>
> Ce guide suppose que vous avez [configuré votre clé API et votre SDK](/docs/fr/eleven-api/quickstart). Terminez
> d’abord le démarrage rapide si ce n’est pas le cas.

#### Effectuer la requête API

Créez un fichier nommé `example.py` ou `example.mts`, selon le langage choisi, puis ajoutez le code suivant :

```python
# example.py
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import os
from io import BytesIO
from dotenv import load_dotenv
load_dotenv()

elevenlabs = ElevenLabs(
    api_key=os.getenv("ELEVENLABS_API_KEY"),
)

stream = elevenlabs.music.stream(
    prompt="Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
    music_length_ms=10000,
    model_id="music_v2_5",
)

# Create a BytesIO object to hold the audio data in memory
audio_stream = BytesIO()

# Write each chunk of audio data to the stream
for chunk in stream:
    if chunk:
        audio_stream.write(chunk)

# Reset stream position to the beginning
audio_stream.seek(0)

play(audio_stream)
```

```typescript
// example.mts
import { ElevenLabsClient, play } from "@elevenlabs/elevenlabs-js";
import "dotenv/config";

const elevenlabs = new ElevenLabsClient();

const stream = await elevenlabs.music.stream({
  prompt: "Create an intense, fast-paced electronic track for a high-adrenaline video game scene. Use driving synth arpeggios, punchy drums, distorted bass, glitch effects, and aggressive rhythmic textures. The tempo should be fast, 130–150 bpm, with rising tension, quick transitions, and dynamic energy bursts.",
  musicLengthMs: 10000,
  modelId: "music_v2_5",
});

const chunks: Buffer[] = [];

for await (const chunk of stream) {
    chunks.push(chunk);
}

const audioStream = Buffer.concat(chunks);

await play(audioStream);
```

#### Exécuter le code

```python
python example.py
```

```typescript
npx tsx example.mts
```

Vous devriez entendre la musique générée.

## Étapes suivantes

#### [Plans de composition](/docs/fr/eleven-api/guides/how-to/music/composition-plans)

Utilisez des plans de composition pour structurer et contrôler la génération musicale.

#### [Inpainting musical](/docs/fr/eleven-api/guides/how-to/music/inpainting)

Modifiez et mélangez des sections de morceaux existants avec de nouvelles générations.