Fix model size selection ignored when generating speech

The /generate endpoint created the voice prompt before loading the
user's requested model size. Since create_voice_prompt() internally
calls load_model_async(None), it fell back to the hardcoded default
of "1.7B", causing the 1.7B model to be downloaded even when the
user explicitly selected 0.6B.

This reorders the operations so the requested model is loaded first,
ensuring create_voice_prompt() and generate() use the correct model.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Abraham
2026-02-18 09:41:44 -08:00
co-authored by Claude Opus 4.6
parent eb2cd861b1
commit ca6ed0998a
+9 -6
View File
@@ -542,12 +542,6 @@ async def generate_speech(
if not profile:
raise HTTPException(status_code=404, detail="Profile not found")
# Create voice prompt from profile
voice_prompt = await profiles.create_voice_prompt_for_profile(
data.profile_id,
db,
)
# Generate audio
tts_model = tts.get_tts_model()
# Load the requested model size if different from current (async to not block)
@@ -582,7 +576,16 @@ async def generate_speech(
}
)
# Load the requested model BEFORE creating voice prompt,
# so create_voice_prompt uses the correct model size
await tts_model.load_model_async(model_size)
# Create voice prompt from profile
voice_prompt = await profiles.create_voice_prompt_for_profile(
data.profile_id,
db,
)
audio, sample_rate = await tts_model.generate(
data.text,
voice_prompt,