Learn how to use and manage custom voice prompts for personalized speech synthesis
VibeVoice uses cached voice prompts to generate speech with specific voice characteristics. This guide explains how voice prompts work and how to use them effectively.
The VoiceMapper class handles voice name resolution with flexible matching:
1
Exact Match
First, it tries to find an exact match for the voice name:
if speaker_name in self.voice_presets: return self.voice_presets[speaker_name]
2
Partial Match
If no exact match, it performs case-insensitive partial matching:
speaker_lower = speaker_name.lower()for preset_name, path in self.voice_presets.items(): if preset_name.lower() in speaker_lower or speaker_lower in preset_name.lower(): return path
3
Default Fallback
If no match is found, it uses the first available voice:
default_voice = list(self.voice_presets.values())[0]print(f"Warning: No voice preset found for '{speaker_name}', using default voice")
import torch# Load voice promptvoice_prompt = torch.load( "demo/voices/streaming_model/Wayne.pt", map_location="cuda", weights_only=False)# The voice_prompt contains:# - voice_prompt['tts_lm']['last_hidden_state']: TTS language model cache# - voice_prompt['lm']['last_hidden_state']: Base language model cache
The processor’s process_input_with_cached_prompt method handles voice prompts:
from vibevoice import VibeVoiceStreamingProcessorimport torchprocessor = VibeVoiceStreamingProcessor.from_pretrained("microsoft/VibeVoice-Realtime-0.5B")# Load voice promptvoice_prompt = torch.load("demo/voices/streaming_model/Wayne.pt", map_location="cuda", weights_only=False)# Process input with cached promptinputs = processor.process_input_with_cached_prompt( text="Hello, this is a test.", cached_prompt=voice_prompt, padding=True, return_tensors="pt", return_attention_mask=True)
# Check if file existsimport osvoice_path = "demo/voices/streaming_model/Wayne.pt"if not os.path.exists(voice_path): print(f"Voice file not found: {voice_path}")
voices_dir = "demo/voices/streaming_model"if not os.path.exists(voices_dir): print(f"Warning: Voices directory not found at {voices_dir}") # Create directory or update path