> 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/melotts.md).

# MeloTTS

Führe MeloTTS mit hochwertigem mehrsprachigem TTS und schneller Inferenz auf Clore.ai-GPUs aus

MeloTTS ist eine hochwertige, mehrsprachige Text-zu-Sprache-Bibliothek, entwickelt von **MyShell AI**. Es liefert schnelle, natürlich klingende Sprachsynthese in mehreren Sprachen und englischen Akzenten, ausgelegt für Forschung und Produktionsbereitstellung. MeloTTS ist auf Geschwindigkeit optimiert — es kann Sprache selbst auf der CPU deutlich schneller als in Echtzeit erzeugen — und behält dabei eine hohe Audioqualität bei, die sich für den kommerziellen Einsatz eignet.

MeloTTS unterstützt derzeit:

* **Englisch** (Amerikanisch, Britisch, Indisch, Australisch, Standard)
* **Chinesisch (Vereinfachtes & gemischtes Chinesisch-Englisch)**
* **Japanisch**
* **Koreanisch**
* **Spanisch**
* **Französisch**

Wichtige Highlights:

* ⚡ **Schnelle Inferenz** — auf der CPU schneller als in Echtzeit, auf der GPU blitzschnell
* 🌍 **Mehrsprachig** — 6 Sprachen mit Akzentvarianten für Englisch
* 🐳 **Docker-fähig** — offizielles Docker-Image verfügbar
* 🔌 **REST-API** — HTTP-API zur Integration in jede Anwendung
* 📱 **Produktionsreif** — verwendet in den Consumer-Produkten von MyShell

{% 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 %}

***

## Serveranforderungen

| Parameter      | Minimum                | Empfohlen               |
| -------------- | ---------------------- | ----------------------- |
| GPU            | NVIDIA GTX 1080 (8 GB) | NVIDIA RTX 3090 (24 GB) |
| VRAM           | 4 GB                   | 8–16 GB                 |
| RAM            | 8 GB                   | 16 GB                   |
| CPU            | 4 Kerne                | 8 Kerne                 |
| Festplatte     | 10 GB                  | 20 GB                   |
| Betriebssystem | Ubuntu 20.04+          | Ubuntu 22.04            |
| CUDA           | 11.7+ (optional)       | 12.1+                   |
| Python         | 3.8+                   | 3.10                    |
| Ports          | 22, 8888               | 22, 8888                |

{% hint style="info" %}
MeloTTS ist außergewöhnlich effizient — es läuft auf der CPU gut für Einzelanfragen und profitiert stark von der GPU für die Stapelverarbeitung. Selbst eine günstige GPU verdoppelt den Durchsatz deutlich.
{% endhint %}

***

## Schnellbereitstellung auf CLORE.AI

{% hint style="warning" %}
**Hinweis:** MeloTTS hat kein offizielles vorgefertigtes Docker-Image auf Docker Hub (`myshell-ai/melotts` existiert nicht). Der empfohlene Ansatz ist, ein NVIDIA-CUDA-Basis-Image zu verwenden und MeloTTS per pip aus dem offiziellen GitHub-Repository zu installieren.
{% endhint %}

### 1. Finden Sie einen geeigneten Server

Gehe zu [CLORE.AI-Marktplatz](https://clore.ai/marketplace) und filtern nach:

* **VRAM**: ≥ 4 GB (oder nur CPU für geringes Volumen)
* **GPU**: Jede NVIDIA-GPU (GTX 1080+, RTX-Serie, A100)
* **Festplatte**: ≥ 10 GB

### 2. Konfigurieren Sie Ihre Bereitstellung

**Docker-Image:**

```
nvidia/cuda:12.8.1-devel-ubuntu22.04
```

**Port-Zuordnungen:**

```
22 → SSH-Zugriff
8888 → MeloTTS-API-Server
```

**Umgebungsvariablen:**

```
NVIDIA_VISIBLE_DEVICES=all
```

**Startbefehl** (ausführen nach SSH auf den Server):

```bash
apt-get update && apt-get install -y python3-pip ffmpeg espeak-ng git && \
git clone https://github.com/myshell-ai/MeloTTS.git && \
cd MeloTTS && pip install -e . && \
python -m unidic download && \
python3 -c "import nltk; nltk.download('averaged_perceptron_tagger_eng')" && \
python -m melo.api_server --host 0.0.0.0 --port 8888
```

### 3. Auf die API zugreifen

```
http://<your-clore-server-ip>:8888
```

Testen mit:

```bash
curl -X POST http://<server-ip>:8888/synthesize \
  -H "Content-Type: application/json" \\
  -d '{"text": "Hallo von Clore.ai!", "language": "EN", "speaker_id": "EN-Default"}'
```

***

## Schritt-für-Schritt-Einrichtung

### Schritt 1: Per SSH auf Ihren Server verbinden

```bash
ssh root@<your-clore-server-ip> -p <ssh-port>
```

### Schritt 2: Den Container bauen und ausführen

Da MeloTTS kein vorgefertigtes Docker-Hub-Image hat, verwende eine NVIDIA-CUDA-Basis und installiere MeloTTS aus dem Quellcode:

```bash
# Einen CUDA-Container ausführen und MeloTTS darin installieren
docker run -d \
  --name melotts \
  --gpus all \
  -p 8888:8888 \
  -v /workspace/melotts/outputs:/app/outputs \
  -e NVIDIA_VISIBLE_DEVICES=all \
  nvidia/cuda:12.8.1-devel-ubuntu22.04 \
  bash -c "apt-get update && apt-get install -y python3-pip ffmpeg espeak-ng git && \
    git clone https://github.com/myshell-ai/MeloTTS.git /app/MeloTTS && \
    cd /app/MeloTTS && pip install -e . && \
    python -m unidic download && \
    python3 -c \"import nltk; nltk.download('averaged_perceptron_tagger_eng')\" && \
    python -m melo.api_server --host 0.0.0.0 --port 8888"
```

Alternativ: Ein eigenes Docker-Image aus dem Quellcode erstellen:

```bash
git clone https://github.com/myshell-ai/MeloTTS.git
cd MeloTTS
docker build -t melotts:local .
docker run -d \
  --name melotts \
  --gpus all \
  -p 8888:8888 \
  melotts:local
```

### Schritt 3: Prüfen, ob der Dienst läuft

```bash
# Container-Logs prüfen
docker logs -f melotts

# Auf den Start warten, dann testen
curl http://localhost:8888/health
```

### Schritt 4: Alternative — Jupyter-Notebook-Oberfläche

```bash
docker run -d \
  --name melotts-jupyter \
  --gpus all \
  -p 8888:8888 \
  nvidia/cuda:12.8.1-devel-ubuntu22.04 \
  bash -c "pip install jupyter melo-tts && \
    jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root"
```

Aufrufen unter: `http://<server-ip>:8888`

### Schritt 5: Installation per pip (ohne Docker)

```bash
# Systemabhängigkeiten installieren
apt-get install -y python3-pip ffmpeg espeak-ng

# MeloTTS installieren
pip install melo-tts

# Erforderliche NLTK-Daten herunterladen
python3 -c "import nltk; nltk.download('averaged_perceptron_tagger_eng')"
```

***

## Anwendungsbeispiele

### Beispiel 1: Einfache englische TTS (Python)

```python
from melo.api import TTS

# Englische TTS initialisieren
speed = 1.0  # Sprechgeschwindigkeit anpassen (0.5 = langsam, 2.0 = schnell)
device = 'cuda'  # 'cpu' verwenden, falls keine GPU verfügbar ist

tts = TTS(language='EN', device=device)

# Verfügbare Sprecher-IDs abrufen
speakers = tts.hps.data.spk2id
print("Verfügbare Sprecher:", list(speakers.keys()))
# Ausgabe: ['EN-Default', 'EN-US', 'EN-GB', 'EN-India', 'EN-Australia', 'EN-Brazil']

# Sprache erzeugen
speaker_ids = tts.hps.data.spk2id
output_path = "output_english.wav"

tts.tts_to_file(
    text="Willkommen bei Clore.ai, Ihrem GPU-Cloud-Marktplatz für KI-Workloads. Mieten Sie leistungsstarke GPUs in Minuten.",
    speaker_id=speaker_ids['EN-Default'],
    output_path=output_path,
    speed=speed
)

print(f"Gespeichert unter: {output_path}")
```

***

### Beispiel 2: Mehrsprachige TTS

```python
from melo.api import TTS

device = 'cuda'

# Sprach-Text-Paare definieren
language_texts = [
    ('EN', 'EN-US', "GPU-Computing hat die Forschung und Entwicklung im Bereich der künstlichen Intelligenz verändert."),
    ('EN', 'EN-GB', "Das Vereinigte Königreich führt Europa bei KI-Investitionen und Innovation an."),
    ('ZH', 'ZH', "Clore.ai是一个去中心化的GPU云计算市场，为AI开发者提供算力服务。"),
    ('JP', 'JP', "人工知能の発展には大規模な計算資源が必要です。"),
    ('KR', 'KR', "Clore.ai는 AI 연구자를 위한 GPU 클라우드 마켓플레이스입니다."),
    ('SP', 'SP', "Künstliche Intelligenz verändert alle Branchen der Welt."),
    ('FR', 'FR', "Künstliche Intelligenz revolutioniert die Art und Weise, wie wir arbeiten und leben."),
]

for lang, speaker, text in language_texts:
    try:
        tts = TTS(language=lang, device=device)
        speaker_id = tts.hps.data.spk2id[speaker]

        output_file = f"output_{lang}_{speaker}.wav"
        tts.tts_to_file(text=text, speaker_id=speaker_id, output_path=output_file)
        print(f"✓ Generiert [{lang}]: {output_file}")
    except Exception as e:
        print(f"✗ Fehler [{lang}]: {e}")
```

***

### Beispiel 3: REST-API-Verwendung

```python
import requests
import json

API_BASE = "http://<your-clore-server-ip>:8888"

# Verfügbare Stimmen prüfen
response = requests.get(f"{API_BASE}/voices")
print("Verfügbare Stimmen:", json.dumps(response.json(), indent=2))

# Sprache synthetisieren
def synthesize(text, language="EN", speaker="EN-Default", speed=1.0):
    payload = {
        "text": text,
        "language": language,
        "speaker_id": speaker,
        "speed": speed,
        "format": "wav"
    }

    response = requests.post(
        f"{API_BASE}/synthesize",
        json=payload,
        timeout=30
    )

    if response.status_code == 200:
        return response.content
    else:
        raise Exception(f"API-Fehler: {response.status_code} - {response.text}")

# Beispielsamples generieren
samples = [
    ("Hallo, hier ist MeloTTS, das auf Clore.ai-GPU-Servern läuft.", "EN", "EN-US"),
    ("Dies ist die britische englische Akzentvariante.", "EN", "EN-GB"),
    ("Lassen Sie mich den indischen englischen Akzent demonstrieren.", "EN", "EN-India"),
]

for text, lang, speaker in samples:
    audio_bytes = synthesize(text, lang, speaker)
    filename = f"api_output_{speaker.replace('-', '_')}.wav"
    with open(filename, "wb") as f:
        f.write(audio_bytes)
    print(f"Gespeichert: {filename}")
```

***

### Beispiel 4: Hochgeschwindigkeits-Stapelverarbeitung

```python
from melo.api import TTS
from concurrent.futures import ThreadPoolExecutor
import soundfile as sf
import time
import numpy as np
from pathlib import Path

device = 'cuda'
tts = TTS(language='EN', device=device)
speaker_id = tts.hps.data.spk2id['EN-US']

# Große Textmenge
texts = [
    f"Dies ist Satz Nummer {i}. Er demonstriert die schnelle Stapelverarbeitung mit MeloTTS auf der GPU-Infrastruktur von Clore.ai."
    for i in range(1, 51)  # 50 Sätze
]

output_dir = Path("batch_output")
output_dir.mkdir(exist_ok=True)

start_time = time.time()

# Stapelverarbeitung
for i, text in enumerate(texts):
    output_path = str(output_dir / f"batch_{i+1:03d}.wav")
    tts.tts_to_file(
        text=text,
        speaker_id=speaker_id,
        output_path=output_path,
        speed=1.0,
        quiet=True
    )
    if (i + 1) % 10 == 0:
        elapsed = time.time() - start_time
        print(f"Fortschritt: {i+1}/50 | Zeit: {elapsed:.1f}s | Rate: {(i+1)/elapsed:.1f} Sätze/Sek.")

total_time = time.time() - start_time
print(f"\nStapelverarbeitung abgeschlossen: {len(texts)} Sätze in {total_time:.1f}s")
print(f"Durchschnitt: {total_time/len(texts)*1000:.0f}ms pro Satz")
```

***

### Beispiel 5: Gemischte Chinesisch-Englisch-TTS

```python
from melo.api import TTS

device = 'cuda'
tts = TTS(language='ZH', device=device)
speaker_id = tts.hps.data.spk2id['ZH']

# Gemischter Sprachtext (Chinesisch + Englisch)
mixed_texts = [
    "我们使用Clore.ai的GPU服务器来运行machine learning workloads。",
    "今天的AI conference讨论了large language models和speech synthesis技术。",
    "我的startup需要GPU资源来训练我们的deep learning模型。",
    "Clore.ai bietet sehr wettbewerbsfähige Preise und ist viel günstiger als AWS und GCP.",
]

for i, text in enumerate(mixed_texts):
    output_file = f"mixed_zh_en_{i+1}.wav"
    tts.tts_to_file(
        text=text,
        speaker_id=speaker_id,
        output_path=output_file,
        speed=0.9  # Etwas langsamer für mehr Klarheit
    )
    print(f"Generiert: {output_file}")
    print(f"  Text: {text[:60]}...")
```

***

## Konfiguration

### Docker-Compose-Setup

Da MeloTTS kein offizielles Docker-Hub-Image hat, verwende das NVIDIA-CUDA-Basis-Image und installiere MeloTTS beim Start aus dem Quellcode:

```yaml
version: '3.8'

services:
  melotts:
    image: nvidia/cuda:12.8.1-devel-ubuntu22.04
    container_name: melotts
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - PYTHONDONTWRITEBYTECODE=1
    ports:
      - "8888:8888"
    volumes:
      - ./outputs:/app/outputs
      - ./cache:/root/.cache
    command: >
      bash -c "apt-get update && apt-get install -y python3-pip ffmpeg espeak-ng git &&
      git clone https://github.com/myshell-ai/MeloTTS.git /app/MeloTTS &&
      cd /app/MeloTTS && pip install -e . &&
      python -m unidic download &&
      python3 -c 'import nltk; nltk.download(\"averaged_perceptron_tagger_eng\")' &&
      python -m melo.api_server --host 0.0.0.0 --port 8888"
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8888/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
```

### API-Konfigurationsoptionen

| Parameter   | Standard    | Beschreibung                                          |
| ----------- | ----------- | ----------------------------------------------------- |
| `--host`    | `127.0.0.1` | Bind-Adresse (verwenden Sie `0.0.0.0` für öffentlich) |
| `--port`    | `8888`      | Port des API-Servers                                  |
| `--workers` | `1`         | Anzahl der Worker-Prozesse                            |
| `--device`  | `auto`      | `cuda`, `cpu`, oder `auto`                            |

### Unterstützte Sprachen und Sprecher

| Sprache     | Code | Sprecher-IDs                                                            |
| ----------- | ---- | ----------------------------------------------------------------------- |
| Englisch    | `EN` | `EN-Default`, `EN-US`, `EN-GB`, `EN-India`, `EN-Australia`, `EN-Brazil` |
| Chinesisch  | `ZH` | `ZH`                                                                    |
| Japanisch   | `JP` | `JP`                                                                    |
| Koreanisch  | `KR` | `KR`                                                                    |
| Spanisch    | `SP` | `SP`                                                                    |
| Französisch | `FR` | `FR`                                                                    |

***

## Leistungstipps

### 1. GPU-gegen-CPU-Benchmark

MeloTTS-Leistung (RTF = Real-Time Factor, niedriger ist besser):

| Gerät         | RTF     | Hinweise                       |
| ------------- | ------- | ------------------------------ |
| CPU (8 Kerne) | \~0,3x  | Schnell, gut für geringe Last  |
| RTX 3080      | \~0,05x | 20x schneller als in Echtzeit  |
| RTX 4090      | \~0,02x | 50x schneller als in Echtzeit  |
| A100          | \~0,01x | 100x schneller als in Echtzeit |

### 2. Für Durchsatz optimieren

```python
# Gradientenberechnung für die Inferenz deaktivieren
import torch

with torch.no_grad():
    tts.tts_to_file(text, speaker_id, output_path)
```

### 3. Modell vorwärmen

```python
# Eine Warmup-Inferenz ausführen, um CUDA-Kerne zu laden
tts.tts_to_file(
    text="warmup",
    speaker_id=speaker_id,
    output_path="/dev/null"
)
print("Modell vorgewärmt, bereit für schnelle Inferenz")
```

### 4. Audioqualität gegen Geschwindigkeit abwägen

```python
# Schneller (leicht geringere Qualität)
tts.tts_to_file(text, speaker_id, output_path, speed=1.2)

# Langsamere Sprache (bessere Artikulation)
tts.tts_to_file(text, speaker_id, output_path, speed=0.8)
```

### 5. Speichereffizienz

```python
# GPU-Speicher zwischen großen Stapeln freigeben
import gc
import torch

gc.collect()
torch.cuda.empty_cache()
```

***

## Fehlerbehebung

### Problem: `espeak-ng` nicht gefunden

```bash
apt-get install -y espeak-ng
python3 -c "import phonemizer; print('phonemizer OK')"
```

### Problem: NLTK-Daten fehlen

```bash
python3 -c "
import nltk
nltk.download('averaged_perceptron_tagger_eng')
nltk.download('punkt')
"
```

### Problem: Port 8888 kollidiert mit Jupyter

MeloTTS verwendet standardmäßig Port 8888, was mit Jupyter Notebook kollidiert. Lösungen:

```bash
# Option 1: MeloTTS auf einem anderen Port ausführen
python -m melo.api_server --host 0.0.0.0 --port 8889

# Option 2: Jupyter auf einem anderen Port ausführen
jupyter notebook --port 8890
```

### Problem: Chinesischer Text wird nicht korrekt angezeigt

```bash
# Unterstützung für die chinesische Sprache installieren
pip install jieba
apt-get install -y python3-opencc

# Test
python3 -c "from melo.api import TTS; t = TTS('ZH'); print('ZH OK')"
```

### Problem: Docker-Image-Pull schlägt fehl

```bash
# Stattdessen aus dem Quellcode bauen
git clone https://github.com/myshell-ai/MeloTTS.git
cd MeloTTS
pip install -e .
python3 -c "import nltk; nltk.download('averaged_perceptron_tagger_eng')"
```

### Problem: Langsame Inferenz auf der GPU

```bash
# Prüfen, ob die GPU verwendet wird
python3 -c "
import torch
from melo.api import TTS
tts = TTS('EN', device='cuda')
print(f'Device: {next(tts.model.parameters()).device}')
print(f'CUDA verfügbar: {torch.cuda.is_available()}')
"
```

***

## GPU-Empfehlungen für Clore.ai

MeloTTS ist leichtgewichtig — es läuft bei geringem Volumen gut auf der CPU und skaliert linear mit GPU-Rechenleistung. Sie brauchen keine teure Hardware.

| GPU       | VRAM  | Clore.ai-Preis                            | RTF (Real-Time Factor)      | Kapazität           |
| --------- | ----- | ----------------------------------------- | --------------------------- | ------------------- |
| Nur CPU   | —     | \~0,02 $/Std.                             | \~0,3×                      | \~3 Anfragen/Min.   |
| RTX 3090  | 24 GB | ca. 0,07–0,21 $/h                         | \~0,02× (50× in Echtzeit)   | \~100 Anfragen/Min. |
| RTX 4090  | 24 GB | ca. 0,14–0,42 $/h                         | \~0,01× (100× in Echtzeit)  | \~200 Anfragen/Min. |
| A100 40GB | 40 GB | [Bare Metal](https://clore.ai/bare-metal) | \~0,005× (200× in Echtzeit) | \~400 Anfragen/Min. |

{% hint style="info" %}
**Bestes Preis-Leistungs-Verhältnis für TTS-Workloads:** Die RTX 3090 für 0,07–0,21 $/Std. liefert eine 50x Echtzeit-TTS-Geschwindigkeit. Für eine Produktions-API, die Hunderte von Nutzern bedient, ist das mehr als ausreichend. Nur-CPU-Instanzen (0,07–0,21 $/Std.) funktionieren gut für Entwicklung und Bereitstellungen mit wenig Traffic.
{% endhint %}

**Empfehlung für den produktiven Einsatz:** Für eine mehrsprachige TTS-API mit 10–50 gleichzeitigen Nutzern ist die RTX 3090 der Sweet Spot. Skalieren Sie horizontal (mehrere Instanzen), statt auf eine teure A100 aufzurüsten — MeloTTS profitiert nicht proportional von High-End-GPUs.

***

## Links

* **GitHub**: <https://github.com/myshell-ai/MeloTTS>
* **Docker**: Kein offizielles Docker-Hub-Image — installieren Sie von [GitHub-Quellcode](https://github.com/myshell-ai/MeloTTS) mit `nvidia/cuda:12.8.1-devel-ubuntu22.04` Basis-Image
* **Paper**: <https://arxiv.org/abs/2406.06753>
* **Hugging Face**: <https://huggingface.co/myshell-ai/MeloTTS-English>
* **MyShell AI**: <https://myshell.ai>
* **CLORE.AI-Marktplatz**: <https://clore.ai/marketplace>


---

# 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/melotts.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.
