Inspiration

  • Sampling is one of the most creative parts of making beats, but it's also one of the hardest for new producers to get into. Finding usable material means scrubbing through whole songs looking for a few clean bars, guessing at tempo and key, and hoping you aren't building on something you can't legally use.
  • The tools that solve this are either expensive sample-pack subscriptions or pro DAWs with steep learning curves. We wanted something a beginner could open in a browser and go from "I want a dusty, melancholy piano loop" to an exported WAV in a few minutes.
  • We also wanted it to teach: explain why a section works as a sample and how you might flip it, instead of just handing over files.
  • We also want to learn music production :)

What it does

  • Smart search over a curated Creative Commons library. Type something like "warm soul keys, sparse, around 90 BPM" and/or stack category chips (instrument, mood, genre, tempo, key) by clicking or dragging them into the search bar. Beatopia returns specific 4–16 bar windows, not whole songs, already snapped to the beat.
  • "Why this works as a sample" notes. Every result has a short note written by Gemini explaining what makes that window usable, plus "flip this sample" tips.
  • Instant preview. Each result plays the suggested window right on its card.
  • Stem separation. Pull drums, bass, vocals or "other" out of any window. Featured "hero" tracks come with stems already separated, and anything else gets separated on demand by a background worker.
  • A browser sample editor. Chop (equal parts, on the beat, or on transients), trim, reverse, repitch, pitch-shift, time-stretch to a target BPM, add gain/fades, normalize, filter, loop, and rearrange the chops. It's non-destructive, with full undo/redo.
  • An AI editing assistant. Ask in plain English ("chop the drums into 4 and reverse the last one") and the assistant suggests a batch of edits that it has checked against the editor's rules before it applies them. The whole batch undoes as one step.
  • WAV export, 44.1 kHz 16-bit stereo.
  • Bring your own audio. Import a file from your computer and it gets analyzed (BPM, key, beats, windows) like library tracks.
  • Licensing is always visible. Every track shows its license and attribution, and results from the Freesound fallback carry their attribution too.
  • Never a dead end. If the library doesn't have a good match, search expands live to Freesound.

How we built it

  • Four people, four agents, one contract. We split the app into four streams: (1) audio data & stems, (2) search API & AI, (3) web shell & search UX, (4) editor & audio engine. Each of us drove one coding agent on our own laptop. Before anyone wrote feature code, we wrote a binding CONTRACT.md with the shared types, endpoints, DB schema, storage layout, and exact op-chain semantics. Pydantic models generate JSON Schema, which generates the TypeScript types, and every stream coded against shared fixtures so nobody blocked on anyone else. Contract changes went through written proposals and dedicated contract: PRs.
  • Data & audio pipeline (Python). We ingested CC-licensed tracks from Freesound and Jamendo, analyzed them with librosa (BPM, key, beat grid, loopability, density), cut them into overlapping 10 s windows, and embedded every window with CLAP (laion/larger_clap_general) into pgvector on Supabase Postgres. The library has 351 tracks and ~12,600 indexed windows, and 67 hero tracks have full stems pre-separated with Demucs (htdemucs). A job worker handles on-demand stem separation and import analysis.
  • Search API (FastAPI). Each query goes through:
    1. a Gemini planner that turns free text into a structured search plan (tags, BPM range, key, "prefer sparse"), cached by query hash, with chip filters merged in deterministically afterward so chips always apply;
    2. a CLAP text embedding of the query and a pgvector similarity search;
    3. a hybrid score (0.6·similarity + 0.2·tag overlap + 0.1·BPM fit + 0.1·loopability, minus a density penalty when you want something sparse), with at most 3 windows per track, snapped to 1/2/4/8/16 bars on the beat grid;
    4. a Gemini rerank of the top 20 that also writes the "why" notes;
    5. per-session Rocchio personalization from play/pick/skip events;
    6. a Freesound fallback when the library's best matches are weak.
  • AI editing assistant. It uses Gemini function calling where the editor's 13 operations are the tool registry. A server-side chain simulator replays the proposed ops against the current editor state and rejects anything invalid (unknown clips, editing an already-sliced parent, and so on) before the browser ever sees it.
  • Frontend (Next.js App Router + TypeScript + Tailwind + shadcn/ui). We used TanStack Query for server state and dnd-kit for dragging chips into the search bar and reordering them. The UI is fully keyboard-accessible (/ to search, j/k to move between results, s for stems, e for the editor) and has an ?offline=1 fixture mode as a demo backup.
  • Editor & audio engine. We built it on wavesurfer.js v7 (waveform + regions) and Tone.js, with Zustand for editor state. Edits are a non-destructive op chain that gets replayed into PCM, and we wrote our own WAV encoder. An LRU prefix cache keeps re-renders fast: appending an op to a 16-bar chain re-renders in roughly 16–55 ms median once cached.
  • Deployment. The API and worker run in Docker Compose behind Caddy on a Vultr VM, the web app is on Vercel, and audio lives in Supabase Storage.
  • Resilience. Gemini is optional on every path. After repeated failures the API switches itself into a degraded mode (raw-text plans, score-ordered results, cached notes) and retries later. Per-session and per-IP token buckets keep the shared hackathon Wi-Fi from tripping rate limits.

Challenges we ran into

  • The "music" CLAP model couldn't tell text prompts apart. The obvious checkpoint, larger_clap_music, produced almost identical text embeddings for unrelated prompts (mean cosine 0.999). We benchmarked it against larger_clap_general (0.29) and switched before ingesting the library.
  • CLAP similarity scores are small. Text-to-audio cosine scores usually land between 0.1 and 0.4, which wrecked our scoring weights and meant our Freesound fallback trigger could never fire. We rescaled similarity and rewrote the trigger to use the top-3 similarity scores, which took a contract proposal agreed across streams.
  • Cold search latency. The first uncached search spent most of its time waiting on two Gemini calls. Running the planner and the embedding in parallel and shrinking the rerank output brought cold p50 down from 3.9 s to 2.6 s. Warm searches take about 80 ms.
  • Rate limits and stuff Unfortunately couldn't get everything done on just free plans, so we had to spend 10 whole dollars altogether to make it work.
  • Stem separation on CPU. Demucs is heavy. We pre-separated the hero tracks offline, capped on-demand separation at short ranges, reused cached stems whenever a request overlapped an existing range, and polled job progress in the UI.
  • Coordinating four agents in one repo. Squash merges, rebases, and generated files caused real friction. Strict path ownership, a shared contract, and fixture-first development are what kept four parallel streams from stepping on each other.
  • Sample-accurate audio in the browser. Getting chops, reverses, and repitches to replay exactly the same way every time (and export bit-identical WAVs) meant careful handling of offsets, stem ranges, and resampling. We verified exports by hashing them.
  • Windows tooling. We fought missing make, pnpm launcher paths, and path-escaping bugs throughout the weekend.

Accomplishments that we're proud of

  • An end-to-end flow that works on the live deployment: search → preview → stems → chop → export.
  • Every result shows its license and attribution, so what you make is something you can actually use.
  • A Gemini editing assistant whose suggestions are validated before they reach the user, so it can't put the editor into a broken state.
  • A deterministic editor: exported WAVs were checked sample-by-sample against independently decoded audio, and human listening tests confirmed the pitch, stretch, and transient-chop results.
  • Graceful degradation everywhere: no Gemini, no network (offline fixture mode), and no library match (Freesound fallback) all still give you something usable.
  • Building it as four people running four AI coding agents in parallel, held together by a written contract.

What we learned

  • Contract-first beats "we'll integrate later." Agreeing on types, endpoints, and fixtures up front let four streams build in parallel and integrate with few surprises.
  • Check your embedding model yourself before trusting it. The model whose name sounded right was the wrong one, and a ten-minute sanity check saved us from indexing the whole library with it.
  • LLMs are best as a layer on top of deterministic systems. Gemini plans, reranks, explains, and suggests, but scoring, bar snapping, op validation, and audio rendering are all ordinary code we can test.
  • Measure latency stage by stage. Server-Timing breakdowns showed us exactly which stage to cut (the rerank), instead of us guessing.
  • A lot about audio DSP in the browser: Web Audio offline rendering, onset detection, time-stretching, and WAV encoding.

What's next for Beatopia

  • A bigger, more varied library: more sources, more genres, and reaching our target of 80+ hero tracks with pre-separated stems. Also would be nice to get absolutely any song with proper licensing here.
  • Smarter windows: snapping that respects musical phrases and never crosses a section boundary, plus listening-based tuning of the "sparse vs. dense" scores.
  • Saved kits and projects: accounts, favorites, and the ability to save and share a chop session.
  • DAW hand-off: export individual chops, MIDI slice maps, and project files for Ableton/FL Studio.
  • A deeper teaching mode: walkthroughs of classic sampling techniques using the user's own chops, with the assistant explaining each step.
  • Faster stems: GPU separation so on-demand stems take seconds instead of tens of seconds.

Built With

  • clap
  • demucs
  • fastapi
  • gemini
  • next.js
  • pgvector
  • supabase
  • vercel
  • vultr
Share this project:

Updates

Submission history