-
-
Notifications
You must be signed in to change notification settings - Fork 51
Experimental Features Melody Transcription Melody Transcription
- Introduction
- Project Structure
- Core Components
- Architecture Overview
- Detailed Component Analysis
- Dependency Analysis
- Performance Considerations
- Troubleshooting Guide
- Conclusion
- Appendices
This document explains the melody transcription feature powered by Sheet Sage integration. It covers the experimental non-Jukebox handcrafted melody transformer approach, the Sheet Sage upstream architecture and model components, asset dependencies, API endpoints, and the integration with ChordMiniApp including the SheetsageTranscriptionClient service, cache management, and frontend UI integration. It also documents performance requirements, Docker deployment strategies for local development and Cloud Run, limitations, accuracy considerations, use-case recommendations, and troubleshooting guidance.
The melody transcription feature spans three primary areas:
- Standalone Sheet Sage backend service exposing a Flask API for transcription.
- Upstream Sheet Sage algorithmic components (handcrafted mel-spectrogram representation, transformer modules, theory utilities).
- ChordMiniApp frontend services that orchestrate audio sourcing, offloading, and caching, and present transcription results.
graph TB
subgraph "ChordMiniApp Frontend"
UI["User Interface<br/>MelodicTranscriptionToggle"]
STC["SheetsageTranscriptionClient"]
OUS["OffloadUploadService"]
SCC["SheetSageCacheClient"]
FS["Firestore Service<br/>Melody Cache"]
end
subgraph "Sheet Sage Backend"
FLASK["Flask App<br/>/health, /info, /transcribe"]
SRV["SheetSage Runtime<br/>Asset Management"]
end
subgraph "Upstream Sheet Sage"
HAND["Handcrafted Mel-Spec<br/>OAFMelSpec"]
MODS["Transformer Modules<br/>Enc/Dec, PosEmb, MLP"]
THEO["Theory Utilities<br/>Pitch Classes, Names"]
ASSETS["Assets Manager<br/>Checksum, Download"]
end
UI --> STC
STC --> OUS
STC --> SCC
STC --> FLASK
SCC --> FS
FLASK --> SRV
SRV --> HAND
SRV --> MODS
SRV --> THEO
SRV --> ASSETS
Diagram sources
- app.py:21-163
- service.py:163-194
- sheetSageTranscriptionClient.ts:41-78
- sheetSageCacheClient.ts:3-17
- offloadUploadService.ts:298-352
- handcrafted.py:10-44
- modules.py:41-144
- basic.py:16-126
- assets.py:54-133
- firestoreService.ts:250-274
Section sources
- Sheet Sage Flask API: Provides GET /health, GET /info, and POST /transcribe endpoints. Accepts multipart audio uploads and returns noteEvents in a standardized format.
- Sheet Sage Runtime: Initializes and manages required assets, performs transcription, and reports runtime status.
- ChordMiniApp SheetsageTranscriptionClient: Resolves audio sources (file or URL), optionally uses offload upload for large files, and posts to /transcribe-sheetsage.
- OffloadUploadService: Handles large audio uploads via an offload mechanism and polls for results.
- SheetSageCacheClient: Retrieves cached melody transcription results keyed by videoId.
- Firestore Service: Stores melody transcription data under a dedicated collection and model identifier.
- Upstream Sheet Sage Components: Handcrafted mel-spectrogram representation, transformer encoder/decoder modules, theory utilities, and asset manager.
Section sources
- README.md:5-27
- app.py:124-163
- service.py:163-194
- sheetSageTranscriptionClient.ts:41-78
- offloadUploadService.ts:298-352
- sheetSageCacheClient.ts:3-17
- firestoreService.ts:250-274
- handcrafted.py:10-44
- modules.py:41-144
- basic.py:16-126
- assets.py:54-133
The transcription pipeline integrates frontend orchestration with the Sheet Sage backend and upstream algorithmic components.
sequenceDiagram
participant UI as "ChordMiniApp UI"
participant STC as "SheetsageTranscriptionClient"
participant OUS as "OffloadUploadService"
participant API as "Next.js /transcribe-sheetsage"
participant SA as "Sheet Sage Backend"
participant RT as "SheetSage Runtime"
participant UP as "Upstream Components"
UI->>STC : Request transcription (audioFile or audioUrl, optional videoId)
STC->>OUS : If file too large, use offload upload
alt Offload Upload
OUS->>SA : POST /transcribe-sheetsage (offload URL)
else Direct Upload
STC->>API : POST /transcribe-sheetsage (multipart/form-data)
API->>SA : Forward request
end
SA->>RT : transcribe_file(audio_path)
RT->>UP : Decode audio, extract features, run melody transformer
UP-->>RT : noteEvents, beatTimes, tempoBpm, beatsPerMeasure
RT-->>SA : Transcription result
SA-->>API : JSON {success : true, data}
API-->>STC : JSON {success : true, data}
STC-->>UI : SheetSageResult (noteEvents, etc.)
Diagram sources
- sheetSageTranscriptionClient.ts:41-78
- offloadUploadService.ts:298-352
- app.py:124-163
- service.py:185-194
- handcrafted.py:22-44
- modules.py:372-400
- Endpoints:
- GET /health: Returns service status and initialization details; supports warmup flag.
- GET /info: Returns endpoint details, accepted formats, and example noteEvents structure.
- POST /transcribe: Accepts multipart file uploads and returns a structured transcription result.
- Response format includes:
- success: boolean
- data: object containing source, noteEvents, noteEventCount, beatTimes, beatsPerMeasure, tempoBpm
- Error handling:
- Missing file: 400
- Asset unavailable: 503
- Runtime errors: 500
- Temporary upload cleanup in finally block
Section sources
- Initialization ensures required assets are present and verified via checksums.
- Asset retrieval:
- Tags mapped to asset metadata with checksums and remote URLs.
- Downloads missing assets and validates integrity.
- Transcription:
- Ensures initialization before processing.
- Emits status updates during processing.
Section sources
- Handcrafted Mel-Spectrogram Representation:
- Decodes audio at fixed sample rate and hop size.
- Computes Mel-spectrogram features and applies power-to-db conversion.
- Transformer Modules:
- Encoder/Decoder implementations with positional embedding, token embedding, and transformer layers.
- Supports identity and MLP encoders, and transformer encoders/decoders.
- Theory Utilities:
- Pitch class and human/lilypond pitch name conversions.
- Jukebox Path (non-used in current runtime):
- Provides a separate representation path requiring GPU resources and larger models.
classDiagram
class OAFMelSpec {
+__call__(audio_path, offset, duration) tuple
-_SR
-_NFFT
-_HOP_SIZE
-_FMIN
-_NMELS
-_HTK
-_LOG
}
class EncOnlyTransducer {
+encode(src, src_len) Tensor
+decode(src_enc, src_len, tgt, tgt_len) Tensor
+forward(src, src_len, tgt, tgt_len) Tensor
}
class TransformerEncoder {
+get_src_enc_dim() int
+_encode(src_emb, src_len) Tensor
}
class TransformerDecoder {
+get_tgt_dec_dim() int
+_decode(src_enc, src_len, tgt_emb, tgt_len) Tensor
}
class PitchClass {
+as_human_pitch_name(enharmonics) str
+as_lily_pitch_name(enharmonics) str
}
OAFMelSpec --> EncOnlyTransducer : "feeds features"
EncOnlyTransducer --> TransformerEncoder : "encodes"
EncOnlyTransducer --> TransformerDecoder : "decodes"
PitchClass <.. TransformerEncoder : "used in theory"
PitchClass <.. TransformerDecoder : "used in theory"
Diagram sources
Section sources
- SheetsageTranscriptionClient:
- Resolves audio file from File or URL, optionally proxies via audio proxy.
- Uses offload upload when file exceeds threshold; otherwise posts to /transcribe-sheetsage.
- Parses JSON response and throws on failure.
- OffloadUploadService:
- Uploads audio to offload storage, then posts to /transcribe-sheetsage with delete-after-processing option.
- Tracks processing time and progress.
- SheetSageCacheClient:
- Fetches cached melody transcription keyed by videoId.
- Firestore Service:
- Stores melody transcription data under a dedicated collection and model identifier.
sequenceDiagram
participant UI as "UI"
participant STC as "SheetsageTranscriptionClient"
participant OUS as "OffloadUploadService"
participant API as "Next.js /transcribe-sheetsage"
participant SCC as "SheetSageCacheClient"
participant FS as "Firestore Service"
UI->>STC : requestSheetSageTranscription(audioFile?, audioUrl?, videoId?)
STC->>OUS : shouldUseOffloadUpload(fileSize)
alt Use Offload
OUS->>API : POST with offload URL
else Direct Upload
STC->>API : POST multipart/form-data
end
API-->>STC : {success : true, data}
STC-->>UI : SheetSageResult
UI->>SCC : getCachedSheetSageMelody(videoId)
SCC->>FS : Query melody cache
FS-->>SCC : Cached data or null
SCC-->>UI : SheetSageResult or null
Diagram sources
- sheetSageTranscriptionClient.ts:41-78
- offloadUploadService.ts:298-352
- sheetSageCacheClient.ts:3-17
- firestoreService.ts:250-274
Section sources
- sheetSageTranscriptionClient.ts:41-78
- offloadUploadService.ts:298-352
- sheetSageCacheClient.ts:3-17
- firestoreService.ts:250-274
- Current runtime uses the non-Jukebox handcrafted melody transformer path.
- The handcrafted mel-spectrogram representation decodes audio and computes Mel-spectrogram features at a fixed sampling rate and hop size.
- The upstream modules implement an encoder-decoder architecture suitable for sequence modeling tasks.
Section sources
- POST /transcribe (Sheet Sage backend):
- Accepts multipart form data with field file.
- Returns JSON with success and data fields.
- Example noteEvents include onset, offset, pitch, velocity.
- GET /info (Sheet Sage backend):
- Describes accepted formats and returns example noteEvents structure.
- GET /health (Sheet Sage backend):
- Reports service status and initialization state; supports warmup.
Section sources
- Fields:
- source: string indicating transcription source
- noteEvents: array of events with onset, offset, pitch, velocity
- noteEventCount: integer count of note events
- beatTimes: array of beat timestamps
- beatsPerMeasure: integer indicating beats per measure
- tempoBpm: floating-point tempo in beats per minute
Section sources
- Frontend to Backend:
- SheetsageTranscriptionClient posts to Next.js /transcribe-sheetsage endpoint.
- OffloadUploadService posts to the same endpoint with an offload URL.
- Backend to Upstream:
- Sheet Sage Backend delegates transcription to SheetSage Runtime.
- Runtime uses handcrafted mel-spectrogram representation and transformer modules.
- Asset Dependencies:
- Assets are managed centrally with checksum verification and download logic.
- Theory and Data Structures:
- Theory utilities support pitch class and human/lilypond pitch name conversions.
- Data structures include noteEvents and beat metadata.
graph LR
STC["SheetsageTranscriptionClient"] --> API["/transcribe-sheetsage"]
OUS["OffloadUploadService"] --> API
API --> SA["Sheet Sage Backend"]
SA --> RT["SheetSage Runtime"]
RT --> HAND["OAFMelSpec"]
RT --> MODS["Transformer Modules"]
RT --> ASSETS["Assets Manager"]
RT --> THEO["Theory Utilities"]
Diagram sources
- sheetSageTranscriptionClient.ts:41-78
- offloadUploadService.ts:298-352
- app.py:124-163
- service.py:185-194
- handcrafted.py:10-44
- modules.py:41-144
- assets.py:54-133
- basic.py:16-126
Section sources
- sheetSageTranscriptionClient.ts:41-78
- offloadUploadService.ts:298-352
- app.py:124-163
- service.py:163-194
- assets.py:54-133
- CPU and Memory:
- Cloud Run deployment specifies 6 vCPUs and 4Gi memory for Sheet Sage backend.
- Timeout:
- Backend timeout configured to 900 seconds; frontend timeout configurable via environment variable.
- Concurrency:
- Cloud Run concurrency set to 1 for deterministic resource usage.
- Docker:
- Frontend Dockerfile sets Node.js heap size to 4GB and installs runtime dependencies including ffmpeg and yt-dlp.
Section sources
- Model Loading and Asset Availability:
- Symptoms: 503 Service Unavailable on /health with assetUnavailable true.
- Resolution: Verify asset host accessibility and required asset tags; ensure assets are seeded into cache directory or replace upstream asset URLs.
- Transcription Timeouts:
- Symptoms: 504/500 errors during transcription.
- Resolution: Increase backend timeout; ensure adequate CPU/memory allocation; consider offloading large files.
- Audio Format Compatibility:
- Symptoms: 400 Bad Request indicating rejection.
- Resolution: Ensure uploaded audio matches accepted formats (.wav, .mp3, .flac, .ogg, .m4a).
- Large File Uploads:
- Symptoms: Upload failures or timeouts.
- Resolution: Use OffloadUploadService to upload to offload storage and post the offload URL to /transcribe-sheetsage.
Section sources
The melody transcription feature leverages Sheet Sage’s non-Jukebox handcrafted melody transformer approach, integrating tightly with ChordMiniApp’s frontend services for audio sourcing, offloading, caching, and UI presentation. The backend exposes a clear API with robust error handling and asset management. Deployment configurations specify strong resource guarantees and timeouts suitable for transcription workloads. Users should be aware of upstream licensing terms and consider the current experimental nature of the integration.
- Local Development:
- Docker Compose configurations define frontend, backend, and optional Redis services with health checks and environment variables for API endpoints and model toggles.
- Cloud Run Production:
- Build and push the Sheet Sage backend image to Artifact Registry, then deploy with 6 vCPUs, 4Gi memory, 900s timeout, and concurrency 1.
Section sources
-
Backend Architecture
- Blueprint Organization
- Machine Learning Integration
- Service Layer Architecture
- Backend Architecture
- Error Handling and Logging
- Flask Application Factory
- Frontend Architecture
- Architecture and Design
- Deployment Architecture
- Audio Pipeline
- Audio Playback System
- Audio Processing and Analysis
- Real-time Audio Analysis
- YouTube Integration
- Blueprint Services
- Machine Learning Services
- Backend Services
- External Integrations
- Flask Application Architecture
- Melody Transcription
- Song Segmentation
- Experimental Feature Management
- Experimental Features
- API Integration and Service Layer
-
Component Library and UI System
- Analysis Interface Components
- Chatbot Interface Component
- Chord Analysis Components
- Chord Playback Components
- Common Components
- Component Library and UI System
- Homepage and Landing Components
- Layout and Utility Components
- Lyrics Display Components
- Piano Visualizer Components
- Settings and Configuration Components
- State Management and Data Flow
- Frontend Application
- Next.js Application Architecture
- Beat Detection Models
- Chord Recognition Models
- Adding New Models
- Machine Learning Models
- Model Management
- Model Training and Evaluation