Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions demo/realtime_model_inference_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def __init__(self):

def setup_voice_presets(self):
"""Setup voice presets by scanning the voices directory."""
voices_dir = os.path.join(os.path.dirname(__file__), "voices/streaming_model")
self.voices_dir = os.path.join(os.path.dirname(__file__), "voices/streaming_model")

# Check if voices directory exists
if not os.path.exists(voices_dir):
print(f"Warning: Voices directory not found at {voices_dir}")
if not os.path.exists(self.voices_dir):
print(f"Warning: Voices directory not found at {self.voices_dir}")
self.voice_presets = {}
self.available_voices = {}
return
Expand All @@ -41,7 +41,7 @@ def setup_voice_presets(self):
self.voice_presets = {}

# Get all .pt files in the voices directory
pt_files = glob.glob(os.path.join(voices_dir, "**", "*.pt"), recursive=True)
pt_files = glob.glob(os.path.join(self.voices_dir, "**", "*.pt"), recursive=True)

# Create dictionary with filename (without extension) as key
for pt_file in pt_files:
Expand All @@ -59,7 +59,7 @@ def setup_voice_presets(self):
if os.path.exists(path)
}

print(f"Found {len(self.available_voices)} voice files in {voices_dir}")
print(f"Found {len(self.available_voices)} voice files in {self.voices_dir}")
print(f"Available voices: {', '.join(self.available_voices.keys())}")

def get_voice_path(self, speaker_name: str) -> str:
Expand All @@ -80,6 +80,8 @@ def get_voice_path(self, speaker_name: str) -> str:
return matched_path

# Default to first voice if no match found
if not self.voice_presets:
raise ValueError(f"No voice preset (.pt) files found under {self.voices_dir}.")
default_voice = list(self.voice_presets.values())[0]
print(f"Warning: No voice preset found for '{speaker_name}', using default voice: {default_voice}")
return default_voice
Expand Down