add a loop over all speakers

This commit is contained in:
2025-03-24 21:05:27 +01:00
commit 7e97db55a0
8 changed files with 5435 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.venv
output.wav
output_wav

61
hello_world.py Normal file
View File

@@ -0,0 +1,61 @@
import torch
import time
from TTS.api import TTS
# Get device
if torch.cuda.is_available():
device = "cuda"
else:
print('Running on cpu')
device= "cpu"
# List available 🐸TTS models
print(TTS().list_models())
# Initialize TTS
start_init = time.time()
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
end_init = time.time()
print(f"Initialization time: {end_init - start_init:.2f} seconds")
# 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="en_sample.wav",
# language="en"
# )
# Create output directory
import os
os.makedirs("output_wav", exist_ok=True)
# Generate sample for each speaker
start_gen = time.time()
total_speakers = len(tts.speakers)
print(f"Starting generation for {total_speakers} speakers...")
for idx, speaker in enumerate(tts.speakers, 1):
# Sanitize speaker name for filename
safe_name = speaker.replace(" ", "_").replace("/", "-")
filename = f"output_wav/{safe_name}.wav"
# Generate audio
tts.tts_to_file(
text="Bitte beachten Sie: Sicherheitscheck 5 ist jetzt geöffnet. Bitte warten Sie im bereitgestellten Wartebereich, bis Sie aufgerufen werden.",
speaker=speaker,
language="de",
file_path=filename
)
# Print progress
progress = f"[{idx}/{total_speakers}] {filename}"
print(progress)
end_gen = time.time()
print(f"Generation time: {end_gen - start_gen:.2f} seconds")

BIN
output.wav Normal file

Binary file not shown.

5354
poetry.lock generated Normal file

File diff suppressed because it is too large Load Diff

17
pyproject.toml Normal file
View File

@@ -0,0 +1,17 @@
[project]
name = "xtts-test"
version = "0.1.0"
description = ""
authors = [
{name = "pstruebi",email = "struebin.patrick@gmail.com"}
]
#readme = "README.md"
requires-python = ">=3.9.0, <3.12"
dependencies = [
"coqui-tts"
]
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"

BIN
speaker_wav/en_sample.wav Normal file

Binary file not shown.

BIN
speaker_wav/es_sample.wav Normal file

Binary file not shown.

BIN
speaker_wav/fr_sample.wav Normal file

Binary file not shown.