Skip to content

Accept audio submitted as a URL - #29

Merged
m-messer merged 5 commits into
mainfrom
28-audio-url-input
Nov 5, 2026
Merged

m-messer merged 5 commits into
mainfrom
28-audio-url-input

Conversation

@peterbjohnson

Copy link
Copy Markdown
Member

Closes #28. Based on main, independent of the #23/#26/#27 chain.

Detection. file_extension() and file_name() parse the URL path instead of the raw string, so a query string or fragment no longer swallows the extension. Local paths go through the same helpers and behave exactly as before. is_audio_input and preview.py both use them, so the two no longer disagree about the same submission.

Fetching. Fixing detection alone would only have moved the failure: Basic Pitch reads audio via librosa.load, which needs a file on disk. local_audio_file() is a context manager that hands back a local path unchanged and downloads a URL to a temp file, removing it afterwards. The temp file keeps the original extension, since Basic Pitch picks its decoder from it.

Preview. A presigned URL was printing its full signature back to the student through os.path.basename. It now shows just practice.wav.

Verified end to end, not only by unit test: served rec_1906.wav over localhost and transcribed it through a presigned-style URL — 97 notes in 8.0s, temp file cleaned up.

Tests. New audio_processing_test.py covers the path helpers, is_audio_input, and local_audio_file including a real download against a temporary localhost server (no external network). One preview test asserts the signature never reaches the student. 124 pass; no new lint.

Deliberately not done, per "minimal for now": no caching, retries, size limit, or content-type check, and no allowlist on the fetched host. Worth noting that last one — the function now issues an HTTP GET to a URL taken from the submission, so anything that can submit can make the container fetch a URL of its choosing. Fine if submissions only ever come from the platform's own bucket, worth a follow-up if not.

🤖 Generated with Claude Code

peterbjohnson and others added 5 commits September 10, 2026 23:16
Uploaded recordings arrive as URLs to a bucket object, and none of them
reached transcription.

- file_extension() and file_name() read the URL path rather than the raw
  string, so a presigned URL is no longer seen as ".wav?X-Amz-Signature="
  and misrouted into the MIDI branch. Local paths parse the same way as
  before.
- local_audio_file() downloads a URL to a temporary file and removes it
  afterwards. Basic Pitch reads audio through librosa, which needs a file
  on disk, so fixing detection alone would only move the failure.
- preview.py names the recording from the URL path, so a presigned URL no
  longer prints its signature back to the student.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The shared deploy workflow now requires function-admin-api-key-staging
(and function-admin-api-key-production for production) instead of the
deprecated function-admin-api-key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Read .mid/.midi paths and URLs into note data with pretty_midi
  instead of trying to parse the URL as JSON; preview summarises them.
- Add .aac and .opus to the transcribed audio extensions.
- Install ffmpeg in the image so librosa can decode m4a and aac
  (wav/flac/ogg/opus/mp3 are handled by libsndfile).
- Test that every supported audio format decodes when ffmpeg is present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UI sends answer and response as [{url, name, type, size, comment}].
Mark the first file, taking its format from the URL, name or MIME type;
treat an empty list as no notes and report unsupported files as feedback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
librosa's numba functions cache next to their source by default, which is
read-only on Lambda, so transcribing audio failed with 'cannot cache
function __o_fold: no locator available'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-messer
m-messer merged commit 477da5b into main Nov 5, 2026
10 checks passed
@m-messer
m-messer deleted the 28-audio-url-input branch November 5, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio URLs are not usable as input

2 participants