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

# 声音混音快速入门

本指南将介绍如何通过混音现有声音创建全新的声音。

## 使用声音设计 API

> **Note**
>
> 本指南假定你已[设置 API 密钥和 SDK](/docs/zh/eleven-api/quickstart)。如果尚未设置，请先完成
> 快速入门。要通过扬声器播放音频，可能还需要安装
> [MPV](https://mpv.io/) 和/或 [ffmpeg](https://ffmpeg.org/)。

#### 发起 API 请求

混音声音分为两个步骤：

1. 提供音色 ID 和提示词，生成新声音的预览。
2. 根据预览创建新声音。

先生成新声音的预览。

根据所选语言，新建名为 `example.py` 或 `example.mts` 的文件，然后添加以下代码：

> **Warning**
>
> 只能混音先前设计的声音、IVC 或 PVC 声音，以及声音库中通知期无限期的声音。

```python maxLines=0
# example.py
from dotenv import load_dotenv
from elevenlabs.client import ElevenLabs
from elevenlabs.play import play
import base64

load_dotenv()

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

voices = elevenlabs.text_to_voice.remix(
    voice_id="JBFqnCBsd6RMkjVDRZzb"
    voice_description="Use a higher pitch and change to a Boston accent.",
    text="Of course I'm a Bostonian, I've lived here all my life!",
)

for preview in voices.previews:
    # Convert base64 to audio buffer
    audio_buffer = base64.b64decode(preview.audio_base_64)

    print(f"Playing preview: {preview.generated_voice_id}")

    play(audio_buffer)
```

```typescript maxLines=0
// example.ts
import { ElevenLabsClient, play } from "@elevenlabs/elevenlabs-js";
import "dotenv/config";
import { Readable } from 'node:stream';
import { Buffer } from 'node:buffer';

const elevenlabs = new ElevenLabsClient();

const { previews } = await elevenlabs.textToVoice.remix("JBFqnCBsd6RMkjVDRZzb", {
    voiceDescription: "Use a higher pitch and change to a Boston accent.",
    text: "Of course I'm a Bostonian, I've lived here all my life!",
});

for (const preview of previews) {
    // Convert base64 to buffer and create a Readable stream
    const audioStream = Readable.from(Buffer.from(preview.audioBase64, 'base64'));

    console.log(`Playing preview: ${preview.generatedVoiceId}`);

    // Play the audio using the stream
    await play(audioStream);
}
```

#### 执行代码

```python
python example.py
```

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

应该会听到扬声器依次播放生成的声音预览。

#### 将生成的声音添加到声音库

生成预览并选出最喜欢的声音后，可通过生成的音色 ID 将其添加到声音库，以便与其他 API 配合使用。

```python
voice = elevenlabs.text_to_voice.create(
    voice_name="Bostonian",
    voice_description="A high pitched Bostonian accent.",
    # The generated voice ID of the preview you want to use,
    # using the first in the list for this example
    generated_voice_id=voices.previews[0].generated_voice_id
)

print(voice.voice_id)
```

```typescript
const voice = await elevenlabs.textToVoice.create({
    voiceName: "Bostonian",
    voiceDescription: "A high pitched Bostonian accent.",
    // The generated voice ID of the preview you want to use,
    // using the first in the list for this example
    generatedVoiceId: previews[0].generatedVoiceId
});

// The ID of the newly created voice, use this to reference the voice in other APIs
console.log(voice.voiceId);
```

## 后续步骤

#### [声音设计](/docs/zh/eleven-api/guides/how-to/voices/voice-design)

根据文本描述生成新声音，而非混音现有声音。

#### [API 参考文档](/docs/zh/api-reference/text-to-voice/remix)

完整的声音混音 API 参考文档和参数。