Miso TTS can condition generation on prior audio (voice cloning) by providing a list of Segment objects to the context parameter in the .generate() method. Each Segment requires a speaker ID, the text transcript of the audio, and the audio tensor itself.
import torchaudio
from generator import Segment, load_miso_8b
generator = load_miso_8b(device="cuda")
prompt_audio, sample_rate = torchaudio.load("prompt.wav")
prompt_audio = torchaudio.functional.resample(
prompt_audio.squeeze(0),
orig_freq=sample_rate,
new_freq=generator.sample_rate,
)
context = [
Segment(
speaker=0,
text="This is the transcript for the prompt audio.",
audio=prompt_audio,
)
]
audio = generator.generate(
text="This is the next sentence to synthesize.",
speaker=0,
context=context,
max_audio_length_ms=10_000,
)