fix: ensure MP3 to WAV conversion creates file

- Add proper error handling around pydub conversion
- Use absolute paths instead of relative paths
- Ensure output directory exists before saving
- Verify file was actually created before returning
- Add fallback to MP3 if conversion fails
- Update tts.py to handle both .wav and .mp3 extensions
- Add detailed logging for debugging
This commit is contained in:
Azimkin
2026-04-08 02:28:30 +02:00
parent 263bc3e54c
commit 69cb910eb9
2 changed files with 84 additions and 12 deletions

View File

@@ -121,16 +121,28 @@ class TTS(Resource):
seed_vc_model = current_app.config['SEED_VC_MODEL']
seed_vc_repo = current_app.config['SEED_VC_REPO_PATH']
vc_service = SeedVCService(model_name=seed_vc_model, repo_path=seed_vc_repo)
vc_service.convert_voice(tts_output, reference_path, final_output)
actual_output = vc_service.convert_voice(tts_output, reference_path, final_output)
logger.info(f"TTS+VC complete: {final_output}")
# Verify the output file exists
if not os.path.exists(actual_output):
raise FileNotFoundError(f"Output file was not created: {actual_output}")
# Determine mimetype and download name based on actual output
if actual_output.endswith('.mp3'):
mimetype = 'audio/mpeg'
download_name = f"tts_{voice_id}.mp3"
else:
mimetype = 'audio/wav'
download_name = f"tts_{voice_id}.wav"
logger.info(f"TTS+VC complete: {actual_output} ({os.path.getsize(actual_output)} bytes)")
# Return audio file
return send_file(
final_output,
mimetype='audio/wav',
actual_output,
mimetype=mimetype,
as_attachment=True,
download_name=f"tts_{voice_id}.wav"
download_name=download_name
)
except Exception as e: