40 lines
980 B
Python
40 lines
980 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
|
|
|
|
# Configure output path
|
|
output_path = "output.wav"
|
|
|
|
# TTS to a file, use a preset speaker
|
|
tts.tts_to_file(
|
|
text="Verehrte Fahrgäste, das heutige Besäufnis wird Ihnen gesponsert von, Rheinmetall",
|
|
speaker_wav=["./0248.wav"],
|
|
language="de",
|
|
file_path=output_path
|
|
)
|
|
|
|
# Process Audio (geklaut von meinem guten Freund flon)
|
|
|
|
from pydub import AudioSegment
|
|
from pydub.utils import make_chunks
|
|
|
|
audio = AudioSegment.from_wav(output_path)
|
|
audio = audio.set_channels(1)
|
|
audio = audio.set_sample_width(2)
|
|
audio = audio.set_frame_rate(16000)
|
|
|
|
silence = AudioSegment.silent(duration=1000)
|
|
gong = AudioSegment.from_wav("./513_1.wav")
|
|
|
|
audio = silence + gong + audio
|
|
audio.export(output_path, format="wav")
|