fix: Improve Piper TTS error handling and user messaging
- Added proper error handling for missing voice models in preview endpoint - Return 404 with helpful message when Piper models not found - Added user-friendly alert in frontend when preview fails - Added prominent warning in UI when Piper is selected about manual setup - Check for empty audio before returning to prevent decode errors Users now get clear feedback when Piper voice models are missing instead of cryptic 'media could not be decoded' errors.
This commit is contained in:
@@ -414,6 +414,10 @@ async def preview_voice(request: VoicePreviewRequest):
|
||||
else:
|
||||
raise ValueError(f"Unknown engine: {tts_service.engine_name}")
|
||||
|
||||
# Check if audio was generated
|
||||
if audio is None or len(audio) == 0:
|
||||
raise ValueError("No audio generated - voice model may be missing")
|
||||
|
||||
# Convert to WAV bytes
|
||||
buffer = io.BytesIO()
|
||||
sf.write(buffer, audio, sample_rate, format='WAV')
|
||||
@@ -427,7 +431,31 @@ async def preview_voice(request: VoicePreviewRequest):
|
||||
media_type="audio/wav",
|
||||
headers={"Content-Disposition": "inline; filename=preview.wav"}
|
||||
)
|
||||
|
||||
|
||||
except FileNotFoundError as e:
|
||||
logger.error(f"Voice model not found: {str(e)}")
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
content={
|
||||
"error": "VoiceModelNotFound",
|
||||
"message": f"Voice model '{request.voice}' not found. Please download Piper voice models manually.",
|
||||
"details": {
|
||||
"voice": request.voice,
|
||||
"engine": tts_service.engine_name,
|
||||
"setup_guide": "See backend/PIPER_SETUP.md for instructions"
|
||||
}
|
||||
}
|
||||
)
|
||||
except ValueError as e:
|
||||
logger.error(f"Validation error during preview: {str(e)}")
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
content={
|
||||
"error": "ValidationError",
|
||||
"message": str(e),
|
||||
"details": {"voice": request.voice, "engine": tts_service.engine_name}
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error during voice preview: {str(e)}", exc_info=True)
|
||||
return JSONResponse(
|
||||
|
||||
Reference in New Issue
Block a user