Add audio-to-MIDI import via Basic Pitch (MP3, WAV, M4A, OGG, FLAC, AAC), fix piano remount on view change

This commit is contained in:
Fabricio Giglio
2026-05-17 08:10:03 +02:00
parent 9d2991a916
commit 6de3c8d98e
6 changed files with 134 additions and 47 deletions
+23 -2
View File
@@ -158,6 +158,27 @@ async def transcribe_mp3(file: UploadFile, background_tasks: BackgroundTasks):
)
except HTTPException:
raise
except Exception:
except Exception as e:
# Surface actionable runtime errors (e.g. missing basic-pitch) to the
# client so the user knows what to install. Match by message substring
# since exceptions may be wrapped on the way back.
logger.exception("transcribe_mp3 failed")
raise HTTPException(status_code=500, detail="Transcription failed. Please try again.")
msg = str(e)
# Only match the specific "not installed" sentinel - any other error
# that happens to mention basic-pitch (e.g. file paths inside the
# package, model-load failures) should NOT be wrongly reported as
# "needs install".
if "basic-pitch is not installed" in msg.lower():
raise HTTPException(
status_code=503,
detail=(
"Audio-to-MIDI transcription needs Basic Pitch on the backend "
"(not bundled by default).\n\n"
"Quick install: with a Python 3.11 venv active on macOS (or 3.11/3.12 "
"on Linux), run pip install -r backend/requirements-transcribe.txt. "
"For Docker, see the README section 'Optional: Audio-to-MIDI via Basic Pitch'."
),
)
raise HTTPException(
status_code=500, detail=f"Transcription failed: {msg or 'Unknown error'}"
)