> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/audio-and-stimme/xtts-coqui.md).

# XTTS (Coqui)

Natürliche Sprachgenerierung mit Stimmklonung mithilfe von Coqui XTTS

Erzeugen Sie natürliche Sprache mit Stimmklonung mit Coqui XTTS.

{% hint style="success" %}
Alle Beispiele können auf GPU-Servern ausgeführt werden, die gemietet wurden über [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Mieten auf CLORE.AI

1. Besuchen [CLORE.AI-Marktplatz](https://clore.ai/marketplace)
2. Filtern nach GPU-Typ, VRAM und Preis
3. Wähle **On-Demand** (Festpreis) oder **Spot** (Gebotspreis)
4. Konfiguriere deine Bestellung:
   * Docker-Image auswählen
   * Ports festlegen (TCP für SSH, HTTP für Web-UIs)
   * Bei Bedarf Umgebungsvariablen hinzufügen
   * Startbefehl eingeben
5. Zahlung auswählen: **CLORE**, **BTC**, oder **USDT/USDC**
6. Bestellung erstellen und auf die Bereitstellung warten

### Greife auf deinen Server zu

* Verbindungsdetails finden in **Meine Bestellungen**
* Web-Oberflächen: Verwende die HTTP-Port-URL
* SSH: `ssh -p <port> root@<proxy-address>`

## Was ist XTTS?

XTTS (von Coqui) bietet:

* Hochwertige Text-zu-Sprache
* Stimmklonung aus 6 Sekunden Audio
* 17 unterstützte Sprachen
* Emotionale Steuerung
* Streaming-Unterstützung

## Anforderungen

| Modus             | VRAM | Empfohlen |
| ----------------- | ---- | --------- |
| Inferenz          | 4 GB | RTX 3060  |
| Schnelle Inferenz | 6 GB | RTX 3080  |
| Streaming         | 4 GB | RTX 3060  |

## Schnell bereitstellen

**Docker-Image:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-runtime
```

**Ports:**

```
22/tcp
8000/http
```

**Befehl:**

```bash
pip install TTS && \\
tts-server --model_name tts_models/multilingual/multi-dataset/xtts_v2
```

## Auf deinen Dienst zugreifen

Nach der Bereitstellung findest du deine `http_pub` URL in **Meine Bestellungen**:

1. Gehe zu **Meine Bestellungen** Seite
2. Klicke auf deine Bestellung
3. Finde die `http_pub` URL (z. B. `abc123.clorecloud.net`)

Verwende `https://YOUR_HTTP_PUB_URL` anstelle von `localhost` in den folgenden Beispielen.

## Installation

```bash
pip install TTS
```

## Grundlegende Verwendung

### Einfaches TTS

```python
from TTS.api import TTS

# XTTS v2 laden
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")

# Sprache erzeugen
tts.tts_to_file(
    text="Hallo, dies ist ein Test des XTTS-Text-zu-Sprache-Systems.",
    file_path="output.wav",
    language="en"
)
```

### Stimmenklonierung

```python
from TTS.api import TTS

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")

# Stimme aus Referenzaudio klonen (6+ Sekunden)
tts.tts_to_file(
    text="Dies ist meine geklonte Stimme, die neuen Text spricht.",
    file_path="cloned_output.wav",
    speaker_wav="reference_voice.wav",
    language="en"
)
```

## Mehrere Sprachen

```python
from TTS.api import TTS

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")

# Englisch
tts.tts_to_file(
    text="Hallo, wie geht es Ihnen heute?",
    file_path="english.wav",
    speaker_wav="voice.wav",
    language="en"
)

# Spanisch
tts.tts_to_file(
    text="Hallo, wie geht es dir heute?",
    file_path="spanish.wav",
    speaker_wav="voice.wav",
    language="es"
)

# Deutsch
tts.tts_to_file(
    text="Hallo, wie geht es dir heute?",
    file_path="german.wav",
    speaker_wav="voice.wav",
    language="de"
)

# Russisch
tts.tts_to_file(
    text="Hallo, wie geht es dir?",
    file_path="russian.wav",
    speaker_wav="voice.wav",
    language="ru"
)
```

### Unterstützte Sprachen

| Code  | Sprache        |
| ----- | -------------- |
| en    | Englisch       |
| es    | Spanisch       |
| fr    | Französisch    |
| de    | Deutsch        |
| it    | Italienisch    |
| pt    | Portugiesisch  |
| pl    | Polnisch       |
| tr    | Türkisch       |
| ru    | Russisch       |
| nl    | Niederländisch |
| cs    | Tschechisch    |
| ar    | Arabisch       |
| zh-cn | Chinesisch     |
| ja    | Japanisch      |
| hu    | Ungarisch      |
| ko    | Koreanisch     |
| it    | Hindi          |

## Streaming-Text-zu-Sprache

```python
from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts
import torch
import sounddevice as sd

# Modell laden
config = XttsConfig()
config.load_json("path/to/config.json")
model = Xtts.init_from_config(config)
model.load_checkpoint(config, checkpoint_dir="path/to/model")
model.cuda()

# Sprecher-Embedding abrufen
gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(
    audio_path="reference.wav"
)

# Streaming-Generierung
chunks = model.inference_stream(
    text="Dies ist ein Streaming-Test des XTTS-Systems.",
    language="en",
    gpt_cond_latent=gpt_cond_latent,
    speaker_embedding=speaker_embedding,
    stream_chunk_size=20
)

# In Echtzeit abspielen
for chunk in chunks:
    audio = chunk.cpu().numpy()
    sd.play(audio, samplerate=24000)
    sd.wait()
```

## Gradio-Oberfläche

```python
import gradio as gr
from TTS.api import TTS
import tempfile

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")

def generate_speech(text, reference_audio, language):
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
        if reference_audio:
            tts.tts_to_file(
                text=text,
                file_path=f.name,
                speaker_wav=reference_audio,
                language=language
            )
        else:
            tts.tts_to_file(
                text=text,
                file_path=f.name,
                language=language
            )
        return f.name

demo = gr.Interface(
    fn=generate_speech,
    inputs=[
        gr.Textbox(label="Zu sprechender Text", lines=5),
        gr.Audio(type="filepath", label="Referenzstimme (optional)"),
        gr.Dropdown(
            ["en", "es", "fr", "de", "it", "pt", "ru", "zh-cn", "ja"],
            value="en",
            label="Sprache"
        )
    ],
    outputs=gr.Audio(label="Generierte Sprache"),
    title="XTTS-Stimmklonung"
)

demo.launch(server_name="0.0.0.0", server_port=7860)
```

## API-Server

```python
from fastapi import FastAPI, UploadFile, File, Form
from fastapi.responses import FileResponse
from TTS.api import TTS
import tempfile
import os

app = FastAPI()
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")

@app.post("/synthesize")
async def synthesize(
    text: str = Form(...),
    language: str = Form(default="en"),
    speaker: UploadFile = File(default=None)
):
    with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as out_file:
        if speaker:
            # Hochgeladene Referenz speichern
            with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as ref_file:
                ref_file.write(await speaker.read())
                ref_path = ref_file.name

            tts.tts_to_file(
                text=text,
                file_path=out_file.name,
                speaker_wav=ref_path,
                language=language
            )
            os.unlink(ref_path)
        else:
            tts.tts_to_file(
                text=text,
                file_path=out_file.name,
                language=language
            )

        return FileResponse(out_file.name, media_type="audio/wav")

# Ausführen: uvicorn server:app --host 0.0.0.0 --port 8000
```

## Batch-Verarbeitung

```python
from TTS.api import TTS
import os

tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")

texts = [
    "Willkommen auf unserer Plattform.",
    "Bitte überprüfen Sie die folgenden Informationen.",
    "Vielen Dank für Ihre Aufmerksamkeit.",
    "Ich wünsche Ihnen einen schönen Tag!"
]

reference_voice = "speaker.wav"
output_dir = "./audio_files"
os.makedirs(output_dir, exist_ok=True)

for i, text in enumerate(texts):
    output_path = f"{output_dir}/audio_{i:03d}.wav"

    tts.tts_to_file(
        text=text,
        file_path=output_path,
        speaker_wav=reference_voice,
        language="en"
    )

    print(f"Generiert: {output_path}")
```

## Stimm-Finetuning

Für besseres Stimmklonen:

```python
from TTS.tts.configs.xtts_config import XttsConfig
from TTS.tts.models.xtts import Xtts

config = XttsConfig()
model = Xtts.init_from_config(config)

# Mehrere Referenzbeispiele für bessere Qualität verwenden
reference_files = [
    "sample1.wav",
    "sample2.wav",
    "sample3.wav"
]

# Sprecher-Embedding aus mehreren Beispielen extrahieren
gpt_cond_latent, speaker_embedding = model.get_conditioning_latents(
    audio_path=reference_files
)

# Mit gemitteltem Embedding generieren
output = model.inference(
    text="Hochwertige geklonte Sprache.",
    language="en",
    gpt_cond_latent=gpt_cond_latent,
    speaker_embedding=speaker_embedding
)
```

## Audio-Vorverarbeitung

```python
import librosa
import soundfile as sf

def prepare_reference(input_path, output_path, target_sr=22050):
    # Laden und neu abtasten
    audio, sr = librosa.load(input_path, sr=target_sr)

    # Stille kürzen
    audio, _ = librosa.effects.trim(audio, top_db=20)

    # Normalisieren
    audio = librosa.util.normalize(audio)

    # Speichern
    sf.write(output_path, audio, target_sr)

# Referenzaudio vorbereiten
prepare_reference("raw_voice.wav", "clean_voice.wav")
```

## Leistung

| Modus     | GPU      | Geschwindigkeit |
| --------- | -------- | --------------- |
| Standard  | RTX 3060 | \~0.5x Echtzeit |
| Standard  | RTX 4090 | \~2x Echtzeit   |
| Streaming | RTX 3060 | \~1x Echtzeit   |
| Streaming | RTX 4090 | \~3x Echtzeit   |

## Qualitätstipps

* Verwenden Sie 6–15 Sekunden sauberes Referenzaudio
* Vermeiden Sie Hintergrundgeräusche in der Referenz
* Stimmen Sie die Sprache des Textes und der Referenz ab
* Verwenden Sie mehrere Referenzbeispiele für bessere Ergebnisse

## Fehlerbehebung

### Schlechte Stimmqualität

* Sauberes Referenzaudio
* Längere Referenz (10+ Sekunden)
* Sprechstil anpassen

### Falsche Aussprache der Sprache

* Stellen Sie sicher, dass der richtige Sprachcode verwendet wird
* Verwenden Sie eine Referenz eines Muttersprachlers

### Langsame Generierung

* GPU-Inferenz aktivieren
* Streaming-Modus verwenden
* Textlänge pro Aufruf reduzieren

## Kostenschätzung

Übliche CLORE.AI-Marktplatzpreise (Stand 2024):

| GPU       | Stundensatz | Tagessatz | 4-Stunden-Sitzung |
| --------- | ----------- | --------- | ----------------- |
| RTX 3060  | \~$0.03     | \~$0.70   | \~$0.12           |
| RTX 3090  | \~$0.06     | \~$1.50   | \~$0.25           |
| RTX 4090  | \~$0.10     | \~$2.30   | \~$0.40           |
| A100 40GB | \~$0.17     | \~$4.00   | \~$0.70           |
| A100 80GB | \~$0.25     | \~$6.00   | \~$1.00           |

*Die Preise variieren je nach Anbieter und Nachfrage. Prüfen Sie* [*CLORE.AI-Marktplatz*](https://clore.ai/marketplace) *für aktuelle Preise.*

**Geld sparen:**

* Nutzen Sie den **Spot** Markt für unterbrechbare Arbeit — etwa ein Drittel der Server bietet Spot-Preise unter dem On-Demand-Preis (Median ca. 13 % Rabatt), der Rest ist gleichauf
* Bezahlen Sie mit **CLORE** Tokens
* Vergleichen Sie Preise zwischen verschiedenen Anbietern

## Nächste Schritte

* [Bark TTS](/guides/guides_v2-de/audio-and-stimme/bark-tts.md) - Expressives TTS
* [SadTalker](/guides/guides_v2-de/sprechende-kopfe/sadtalker.md) - Sprechende Köpfe
* [RVC-Sprachklon](/guides/guides_v2-de/audio-and-stimme/rvc-voice-clone.md) - Stimmumwandlung


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/audio-and-stimme/xtts-coqui.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
