Skip to content

Accept audio submitted as a URL - #29

Open
peterbjohnson wants to merge 1 commit into
mainfrom
28-audio-url-input
Open

Accept audio submitted as a URL#29
peterbjohnson wants to merge 1 commit 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

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>
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

1 participant