bahnansage/ansage.py
2026-01-07 19:30:05 +01:00

33 lines
795 B
Python

import torch
from TTS.api import TTS
# Get device
device = "cuda" if torch.cuda.is_available() else "cpu"
# List available 🐸TTS models
print(TTS().list_models())
# Initialize TTS
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
# List speakers
print(tts.speakers)
# Run TTS
# ❗ XTTS supports both, but many models allow only one of the `speaker` and
# `speaker_wav` arguments
# TTS with list of amplitude values as output, clone the voice from `speaker_wav`
#wav = tts.tts(
# text="Hello world!",
# speaker_wav="my/cloning/audio.wav",
# language="en"
#)
# TTS to a file, use a preset speaker
tts.tts_to_file(
text="Hallo Oliver, herzlichen Glückwunsch zur erfolgreichen Entlastung",
speaker_wav="./0248.wav",
language="en",
file_path="output2.wav"
)