Compare commits

...
Author SHA1 Message Date
Andrew Beveridge ☄️ 10cb868481 Merge pull request #80 from nomadkaraoke/feature/local-whisper-transcriber
Add local Whisper transcription support
2025-12-28 01:24:18 -05:00
Andrew Beveridge 02a64faecc Updated deps 2025-12-28 01:07:25 -05:00
Andrew BeveridgeandClaude Opus 4.5 ba4ec72040 Merge main into feature/local-whisper-transcriber
Resolved version conflict by keeping 0.76.24 from feature branch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 01:07:06 -05:00
Andrew Beveridge ☄️ ae2846b90b Merge pull request #85 from nomadkaraoke/fix/instrumental-ui-duration-nan
Fix instrumental UI NaN duration causing seek to fail
2025-12-28 01:05:27 -05:00
Andrew BeveridgeandClaude Opus 4.5 8c0eab7d7b Increase logo height to 40px
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 01:04:13 -05:00
Andrew BeveridgeandClaude Opus 4.5 0f51f595a3 Replace microphone emoji with Nomad Karaoke logo in instrumental UI
- Added logo-img CSS class for proper image sizing
- Updated header to use the SVG logo instead of emoji

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 01:02:18 -05:00
Andrew BeveridgeandClaude Opus 4.5 98bb30114e Fix instrumental UI NaN duration causing seek to fail
The waveform API returns `duration_seconds` but the frontend was reading
`waveformData.duration` which is undefined, causing duration to be NaN.

Fixes:
- Read `duration_seconds` from API response instead of `duration`
- Add guard in formatTime() to return '0:00' for NaN/Infinity
- Add guard in seekTo() to prevent setting audio.currentTime to NaN
- Add guards in waveform click handlers to prevent NaN calculations

This fixes the 'NaN:NaN' display and the TypeError when clicking to seek.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 01:01:26 -05:00
Andrew Beveridge ☄️ e88110a25c Merge pull request #84 from nomadkaraoke/fix/instrumental-ui-auth
Fix instrumental UI authentication token not being passed in URL
2025-12-28 00:48:34 -05:00
Andrew Beveridge 12a62db7f8 Remove test files and add to gitignore 2025-12-28 00:48:13 -05:00
Andrew Beveridge ☄️ c4a0cb2a63 Merge pull request #83 from nomadkaraoke/fix/docker-cache-ignore-error
Fix Docker registry cache error on first build
2025-12-28 00:47:45 -05:00
Andrew BeveridgeandClaude Opus 4.5 b0a16a90a4 Fix OutputPaths attribute access (dataclass not dict)
OutputPaths is a dataclass, not a dictionary. Changed .get() calls
to proper attribute access (.video, .ass).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:46:54 -05:00
Andrew BeveridgeandClaude Opus 4.5 2f6cd7a745 Fix Docker registry cache error and optimize CI workflow
Changes:
1. Add ignore-error=true to cache-from/cache-to so builds continue
   gracefully when cache doesn't exist (first build)

2. Add aggressive disk space cleanup at start of deploy-backend using
   jlumbroso/free-disk-space action (fixes "No space left on device")

3. Skip tests on main branch - tests only run on PRs now
   - PRs run full test suite with path filtering
   - Main branch only runs build/deploy jobs
   - CI Gate only required for PRs, not main

This significantly speeds up deployments on main since tests
already passed on the PR before merge.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:46:02 -05:00
Andrew BeveridgeandClaude Opus 4.5 1da1a17235 Fix instrumental UI authentication token not being passed in URL
The instrumental review UI was getting 401 errors because the frontend
JobCard component was looking for the token in job.state_data.instrumental_token
when it's actually stored at job.instrumental_token (same pattern as review_token).

Changes:
- Add instrumental_token field to Job interface in api.ts
- Fix JobCard.tsx getInstrumentalUrl() to use job.instrumental_token
- Update test to use correct token location

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:40:44 -05:00
Andrew Beveridge daa6807b39 Remove accidentally committed test audio files 2025-12-28 00:36:34 -05:00
Andrew BeveridgeandClaude Opus 4.5 06c8587e99 Fix missing lyrics_results argument in generate_outputs call
The OutputGenerator.generate_outputs() method requires a lyrics_results
argument. Since we're at the video rendering stage after loading
corrections from JSON, we pass an empty dict as the lyrics were already
written during the transcription phase.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:35:24 -05:00
Andrew Beveridge 81c7d1cc7f Merge main into feature/local-whisper-transcriber 2025-12-28 00:31:56 -05:00
Andrew BeveridgeandClaude Opus 4.5 b2c8608e0c Use default styles when no output_styles_json provided
When rendering video or CDG without a styles file, the OutputGenerator
now uses sensible default karaoke styles instead of raising an error.
This allows end-to-end karaoke generation to work without requiring a
styles JSON file.

Changes:
- Add _get_default_styles() method with embedded default karaoke styles
- Modify init to use defaults when styles file is missing/None
- Update test to verify default styles are loaded correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:29:18 -05:00
Andrew Beveridge ☄️ d6f22f5494 Merge pull request #82 from nomadkaraoke/feature/github-actions-docker-builds
Replace Cloud Build with GitHub Actions for Docker builds
2025-12-28 00:25:11 -05:00
Andrew BeveridgeandClaude Opus 4.5 ea1c659828 Replace Cloud Build with GitHub Actions for Docker builds
Cost optimization: Migrate from expensive Cloud Build ($100+/month) to
free GitHub Actions with registry caching.

Changes:
- Add .dockerignore to reduce build context (~1GB → ~10MB)
- Rewrite deploy-backend job to use docker/build-push-action
- Use Artifact Registry as persistent layer cache (mode=max)
- Keep cloudbuild*.yaml as fallback for manual builds
- Add documentation for new build process

Benefits:
- $0 monthly cost (public repo, free GitHub Actions)
- Faster builds with registry-cached layers
- Simpler deployment pipeline (all in one workflow)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:22:39 -05:00
Andrew BeveridgeandClaude Opus 4.5 8bd8f3343f Fix pip extras for local-whisper installation
Poetry extras require the optional dependency to be in the main
[tool.poetry.dependencies] section with `optional = true`, not just
in a separate group. The group syntax is only for Poetry's own
`poetry install --with` command.

Now `pip install karaoke-gen[local-whisper]` correctly installs
whisper-timestamped.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:19:19 -05:00
Andrew BeveridgeandClaude Opus 4.5 ce07080fc7 Add disk space cleanup to backend-unit-tests CI job
Prevents transient "No space left on device" failures on GitHub Actions
runners by freeing up disk space before running tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:13:13 -05:00
Andrew BeveridgeandClaude Opus 4.5 eceab9f422 Fix LocalWhisper integration in lyrics_processor.py
- Add LocalWhisper check to _check_transcription_providers()
- Update error message to include LocalWhisper as option 3
- Pass runpod_api_key, whisper_runpod_id, and enable_local_whisper
  to TranscriberConfig

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 00:04:31 -05:00
Andrew Beveridge ☄️ e4223634d1 Merge pull request #81 from nomadkaraoke/fix/remove-instrumental-selector-export
Fix stale exports in job/index.ts and add frontend build CI check
2025-12-27 23:52:42 -05:00
Andrew BeveridgeandClaude Opus 4.5 6586ea3584 Update poetry.lock for local-whisper extras
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:52:23 -05:00
Andrew BeveridgeandClaude Opus 4.5 b7c1850a3b Fix stale exports in job/index.ts and add frontend build CI check
The previous PR removed InstrumentalSelector.tsx but didn't update the
barrel export file, breaking the production build.

Changes:
- Remove stale InstrumentalSelector and StatusBadge exports from index.ts
- Add frontend-build job to CI workflow to catch build failures on PRs
- Add frontend-build to ci-gate and deploy-frontend dependencies

This ensures future PRs will fail CI if they break the frontend build.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:51:42 -05:00
Andrew BeveridgeandClaude Opus 4.5 e4dbd7393e Add local Whisper transcription support
Implements LocalWhisperTranscriber for running Whisper inference locally
using the whisper-timestamped library, addressing issue #68.

Changes:
- Add LocalWhisperTranscriber class with lazy model loading
- Support auto-detection of device (CPU/CUDA/MPS) with fallback
- Add configuration via environment variables (WHISPER_MODEL_SIZE,
  WHISPER_DEVICE, WHISPER_CACHE_DIR, WHISPER_LANGUAGE)
- Integrate into controller with priority 3 (fallback after cloud services)
- Add whisper-timestamped as optional dependency [local-whisper]
- Add comprehensive unit tests
- Update README with setup instructions and troubleshooting guide

Installation:
  pip install karaoke-gen[local-whisper]

For CPU-only systems:
  pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
  pip install karaoke-gen[local-whisper]

Fixes #68

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:40:34 -05:00
Andrew Beveridge ☄️ 7736a4a8f7 Merge pull request #79 from nomadkaraoke/feature/instrumental-review-ui
Replace primitive instrumental selector with full-featured review UI
2025-12-27 23:36:45 -05:00
Andrew BeveridgeandClaude Opus 4.5 156b83ace1 Replace primitive instrumental selector with full-featured review UI
The web frontend now opens the same rich instrumental review UI that the
CLI uses. This provides waveform visualization, audio playback for
different stems, mute region selection, and custom instrumental creation.

Changes:
- Add instrumental review static HTML to frontend/public/instrumental/
- Update JobCard to open /instrumental/ page instead of showing dialog
- Remove InstrumentalSelector.tsx primitive dialog component
- Remove orphaned instrumental-review components (never used)
- Update tests to reflect link-based navigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:34:20 -05:00
Andrew Beveridge ☄️ 8978eb6d96 Merge pull request #77 from nomadkaraoke/fix/flacfetch-youtube-url
Update flacfetch to 0.15.1 (fixes YouTube URL download)
2025-12-27 23:10:12 -05:00
Andrew Beveridge ☄️ c4143947ca Merge pull request #78 from nomadkaraoke/feature/mandatory-worktrees
Make git worktrees mandatory for all changes
2025-12-27 23:09:07 -05:00
Andrew BeveridgeandClaude Opus 4.5 8a28c95786 Simplify flacfetch workflow: no PR required
flacfetch changes can be committed directly to main once tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:07:36 -05:00
Andrew BeveridgeandClaude Opus 4.5 48acb6c4e1 Add flacfetch as a related project with workflow docs
Documents that flacfetch is a dependency we own, located at
/Users/andrew/Projects/flacfetch, and provides the workflow for
making changes to it and updating karaoke-gen's dependency.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:07:05 -05:00
Andrew BeveridgeandClaude Opus 4.5 da60495144 Clarify version bump rule applies only to code changes
Documentation-only changes (CLAUDE.md, README.md, etc.) don't require
version bumps since they don't affect deployed code.

Also reverts the unnecessary version bump from the previous commit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:04:39 -05:00
Andrew BeveridgeandClaude Opus 4.5 e282f40758 Make git worktrees mandatory for all changes
Since all changes must go through a PR, worktrees are now required for
all changes (not just non-trivial ones). This keeps the main directory
clean on main and enables parallel work.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:03:54 -05:00
Andrew BeveridgeandClaude Opus 4.5 aaeda8679a Update flacfetch to 0.15.1 (fixes YouTube URL download)
Fixes the "Release.__init__() missing 1 required positional argument: 'quality'"
error that occurred when downloading from YouTube URLs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 22:59:31 -05:00
Andrew Beveridge ☄️ 6da6656c15 Merge pull request #76 from nomadkaraoke/fix/remove-deployment-tracking
Remove deployment tracking to fix PR banner
2025-12-27 22:50:44 -05:00
Andrew BeveridgeandClaude Opus 4.5 d81591ca99 Remove deployment tracking to fix PR banner
Remove the `environment` block from the deploy-frontend job to prevent
GitHub from creating deployment entries. This fixes the "This branch
has not been deployed" banner that appears on all PRs.

The deployment to GitHub Pages still works via actions/deploy-pages@v4,
but without tracked environment deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 22:49:44 -05:00
Andrew Beveridge ☄️ 0e66ac84ec Merge pull request #74 from nomadkaraoke/fix/youtube-url-support
Fix YouTube URL support in karaoke-gen CLI
2025-12-27 22:48:12 -05:00
Andrew BeveridgeandClaude Opus 4.5 d8e3542850 Address CodeRabbit lint feedback
- Remove f-string prefix from strings without placeholders (F541)
- Add 'from e' to ImportError handler to preserve stack trace (B904)
- Use raw string for regex pattern in pytest match (RUF043)
- Remove unused result variables (F841)
- Remove redundant KaraokePrep import in fixture (F811)
- Rename unused mock parameters with underscore prefix (ARG002)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 22:36:22 -05:00
Andrew Beveridge ☄️ 8b66e97459 Merge pull request #75 from nomadkaraoke/fix/progress-display-during-parallel-processing
Fix progress display to show step 4 when workers are active during download
2025-12-27 22:34:53 -05:00
Andrew Beveridge 8dc0a96734 Added CI gate check 2025-12-27 22:24:52 -05:00
29 changed files with 3311 additions and 1107 deletions

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
# .dockerignore - Reduce Docker build context size
# This is critical for fast builds as it reduces upload time and cache invalidation
# Git
.git/
.gitignore
.gitmodules
# Node.js / Frontend (not needed for backend image)
node_modules/
frontend/
frontend-react/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Python virtual environments (use Docker's Python instead)
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
.venv/
venv/
backend/venv/
ENV/
env/
*.egg-info/
.eggs/
dist/
build/
*.egg
# IDE
.idea/
.vscode/
*.swp
*.swo
*~
.DS_Store
# Testing (not needed in production image)
.pytest_cache/
.coverage
htmlcov/
.tox/
.nox/
coverage.xml
*.cover
tests/
backend/tests/
# Documentation (not needed in Docker image)
docs/
*.md
!README.md
# Infrastructure (not needed for Docker build)
infrastructure/
# CI/CD configs
.github/
# Cloud Build configs (keep for reference but not in image)
cloudbuild*.yaml
# Local development files
lyrics_transcriber_local/
*.local
.env
.env.*
*.bak
*.tmp
Thumbs.db
# Large test/sample files
tests/data/
*.mp3
*.wav
*.mp4
*.mkv
*.flac
+243 -118
View File
@@ -18,11 +18,13 @@ concurrency:
jobs:
# ============================================
# PATH FILTERING - Determine what changed
# Only needed for PRs (main branch skips tests)
# ============================================
changes:
name: "Detect Changes"
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
backend: ${{ steps.filter.outputs.backend }}
@@ -61,14 +63,14 @@ jobs:
echo "| Dependencies | ${{ steps.filter.outputs.deps }} |" >> $GITHUB_STEP_SUMMARY
# ============================================
# FRONTEND TESTS
# FRONTEND TESTS (PRs only - main skips tests)
# ============================================
frontend-unit-tests:
name: "Frontend - Unit Tests"
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' || github.ref == 'refs/heads/main' }}
if: github.ref != 'refs/heads/main' && needs.changes.outputs.frontend == 'true'
steps:
- uses: actions/checkout@v4
@@ -95,15 +97,40 @@ jobs:
path: frontend/coverage/
retention-days: 7
frontend-build:
name: "Frontend - Build"
runs-on: ubuntu-latest
needs: changes
if: github.ref != 'refs/heads/main' && needs.changes.outputs.frontend == 'true'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js with caching
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci --legacy-peer-deps
- name: Build frontend
working-directory: frontend
env:
NEXT_PUBLIC_API_URL: https://api.nomadkaraoke.com
run: npm run build
# ============================================
# PACKAGE TESTS (karaoke-gen Python CLI)
# PACKAGE TESTS (PRs only - main skips tests)
# ============================================
package-unit-tests:
name: "Package - Unit Tests (70% coverage)"
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true' || github.ref == 'refs/heads/main' }}
if: github.ref != 'refs/heads/main' && (needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true')
steps:
- uses: actions/checkout@v4
with:
@@ -161,7 +188,7 @@ jobs:
name: "Package - Integration Tests"
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true' || github.ref == 'refs/heads/main' }}
if: github.ref != 'refs/heads/main' && (needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true')
steps:
- uses: actions/checkout@v4
with:
@@ -206,11 +233,15 @@ jobs:
- name: Run integration tests
run: poetry run pytest tests/integration/ -v
package-build:
name: "Package - Build & Install"
package-build-test:
name: "Package - Build & Install (Test)"
runs-on: ubuntu-latest
needs: [changes, package-unit-tests, package-integration-tests]
if: ${{ always() && (needs.package-unit-tests.result == 'success' || needs.package-unit-tests.result == 'skipped') && (needs.package-integration-tests.result == 'success' || needs.package-integration-tests.result == 'skipped') && (needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true' || github.ref == 'refs/heads/main') }}
if: >-
github.ref != 'refs/heads/main' && always() &&
(needs.package-unit-tests.result == 'success' || needs.package-unit-tests.result == 'skipped') &&
(needs.package-integration-tests.result == 'success' || needs.package-integration-tests.result == 'skipped') &&
(needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true')
steps:
- uses: actions/checkout@v4
with:
@@ -254,23 +285,23 @@ jobs:
pip install dist/*.whl
python -m karaoke_gen.utils.gen_cli --help
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: package-dist
path: dist/
retention-days: 1
# ============================================
# BACKEND TESTS (Cloud Run API service)
# BACKEND TESTS (PRs only - main skips tests)
# ============================================
backend-unit-tests:
name: "Backend - Unit Tests"
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' || needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true' || github.ref == 'refs/heads/main' }}
if: github.ref != 'refs/heads/main' && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true')
steps:
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
df -h
- name: Checkout code
uses: actions/checkout@v4
with:
@@ -314,14 +345,18 @@ jobs:
name: "Backend - Emulator Integration Tests"
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' || needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true' || github.ref == 'refs/heads/main' }}
if: github.ref != 'refs/heads/main' && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.package == 'true' || needs.changes.outputs.deps == 'true')
steps:
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
df -h
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: true
haskell: true
dotnet: true
large-packages: false
docker-images: false
swap-storage: false
- name: Checkout code
uses: actions/checkout@v4
@@ -384,7 +419,7 @@ jobs:
name: "Backend - Code Quality"
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' || needs.changes.outputs.package == 'true' || github.ref == 'refs/heads/main' }}
if: github.ref != 'refs/heads/main' && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.package == 'true')
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -419,9 +454,78 @@ jobs:
echo "✅ Basic syntax validation passed"
# ============================================
# DEPLOYMENTS (main branch only)
# CI GATE - Required status check for PRs
# Only runs on PRs, not on main
# ============================================
ci-gate:
name: "CI Gate"
runs-on: ubuntu-latest
needs: [frontend-unit-tests, frontend-build, package-unit-tests, package-integration-tests, backend-unit-tests, backend-emulator-tests, backend-lint]
if: github.ref != 'refs/heads/main' && always()
steps:
- name: Check results
run: |
results=(
"${{ needs.frontend-unit-tests.result }}"
"${{ needs.frontend-build.result }}"
"${{ needs.package-unit-tests.result }}"
"${{ needs.package-integration-tests.result }}"
"${{ needs.backend-unit-tests.result }}"
"${{ needs.backend-emulator-tests.result }}"
"${{ needs.backend-lint.result }}"
)
for result in "${results[@]}"; do
if [[ "$result" == "failure" || "$result" == "cancelled" ]]; then
echo "❌ CI failed"
exit 1
fi
done
echo "✅ CI passed"
# ============================================
# DEPLOYMENTS (main branch only)
# Tests already passed on PR, so we skip them here
# ============================================
package-build:
name: "Package - Build"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache Poetry dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-package-${{ runner.os }}-py3.13-${{ hashFiles('poetry.lock') }}
restore-keys: |
venv-package-${{ runner.os }}-py3.13-
- name: Build package
run: poetry build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: package-dist
path: dist/
retention-days: 1
package-publish:
name: "Deploy - Publish to PyPI"
runs-on: ubuntu-latest
@@ -512,11 +616,7 @@ jobs:
deploy-frontend:
name: "Deploy - Frontend (GitHub Pages)"
runs-on: ubuntu-latest
needs: [frontend-unit-tests]
if: ${{ always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && (needs.frontend-unit-tests.result == 'success' || needs.frontend-unit-tests.result == 'skipped') }}
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -588,12 +688,32 @@ jobs:
deploy-backend:
name: "Deploy - Backend (Cloud Run)"
runs-on: ubuntu-latest
needs: [backend-unit-tests, backend-emulator-tests, backend-lint]
if: ${{ always() && github.ref == 'refs/heads/main' && github.event_name == 'push' && (needs.backend-unit-tests.result == 'success' || needs.backend-unit-tests.result == 'skipped') && (needs.backend-emulator-tests.result == 'success' || needs.backend-emulator-tests.result == 'skipped') && (needs.backend-lint.result == 'success' || needs.backend-lint.result == 'skipped') }}
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
id-token: write
env:
REGISTRY: us-central1-docker.pkg.dev
PROJECT_ID: nomadkaraoke
REPOSITORY: karaoke-repo
BASE_IMAGE_NAME: karaoke-backend-base
APP_IMAGE_NAME: karaoke-backend
steps:
# ============================================
# Free disk space FIRST - before anything else
# This prevents "No space left on device" errors
# ============================================
- name: Free disk space (aggressive)
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
android: true
haskell: true
dotnet: true
large-packages: true
docker-images: true
swap-storage: true
- name: Checkout code
uses: actions/checkout@v4
with:
@@ -638,21 +758,37 @@ jobs:
with:
version: "latest"
- name: Check if base image needs rebuild
- name: Configure Docker for Artifact Registry
if: steps.version_check.outputs.needs_deploy == 'true'
run: gcloud auth configure-docker ${{ env.REGISTRY }} --quiet
# ============================================
# Docker Build with BuildKit + Registry Cache
# This replaces expensive Cloud Build with free GitHub Actions
# Registry cache persists between builds for fast rebuilds
# ============================================
- name: Set up Docker Buildx
if: steps.version_check.outputs.needs_deploy == 'true'
uses: docker/setup-buildx-action@v3
- name: Calculate base image hash
if: steps.version_check.outputs.needs_deploy == 'true'
id: base-hash
run: |
# Hash both poetry.lock AND Dockerfile.base - rebuild if either changes
CURRENT_HASH=$(cat poetry.lock backend/Dockerfile.base | sha256sum | cut -d' ' -f1)
echo "hash=$CURRENT_HASH" >> $GITHUB_OUTPUT
echo "📋 Base content hash: $CURRENT_HASH"
- name: Check if base image exists and is current
if: steps.version_check.outputs.needs_deploy == 'true'
id: check-base
run: |
echo "🔍 Checking if base image needs rebuild..."
BASE_IMAGE="${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.BASE_IMAGE_NAME }}:latest"
# Hash both poetry.lock AND Dockerfile.base - rebuild if either changes
CURRENT_HASH=$(cat poetry.lock backend/Dockerfile.base | sha256sum | cut -d' ' -f1)
echo "Current combined hash (poetry.lock + Dockerfile.base): $CURRENT_HASH"
gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
BASE_IMAGE="us-central1-docker.pkg.dev/nomadkaraoke/karaoke-repo/karaoke-backend-base:latest"
# Try to get the existing base image's hash label
EXISTING_HASH=""
if docker pull $BASE_IMAGE 2>/dev/null; then
EXISTING_HASH=$(docker inspect $BASE_IMAGE --format='{{index .Config.Labels "base.content.hash"}}' 2>/dev/null || echo "")
# Fallback to old label name for backwards compatibility
@@ -661,10 +797,10 @@ jobs:
fi
echo "Existing base image hash: $EXISTING_HASH"
else
echo "⚠️ No existing base image found"
echo "⚠️ No existing base image found - will build"
fi
if [ "$CURRENT_HASH" != "$EXISTING_HASH" ]; then
if [ "${{ steps.base-hash.outputs.hash }}" != "$EXISTING_HASH" ]; then
echo "🔄 Base image needs rebuild (poetry.lock or Dockerfile.base changed)"
echo "needs_rebuild=true" >> $GITHUB_OUTPUT
else
@@ -672,88 +808,73 @@ jobs:
echo "needs_rebuild=false" >> $GITHUB_OUTPUT
fi
- name: Rebuild base image (if needed)
- name: Build and push base image (if needed)
if: steps.version_check.outputs.needs_deploy == 'true' && steps.check-base.outputs.needs_rebuild == 'true'
run: |
echo "🏗️ Rebuilding base image with updated dependencies..."
uses: docker/build-push-action@v6
with:
context: .
file: backend/Dockerfile.base
push: true
tags: |
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.BASE_IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.BASE_IMAGE_NAME }}:${{ github.sha }}
# Registry cache for ALL layers (mode=max) - persists between builds
# ignore-error=true allows build to continue if cache doesn't exist yet
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.BASE_IMAGE_NAME }}:cache,ignore-error=true
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.BASE_IMAGE_NAME }}:cache,mode=max,ignore-error=true
build-args: |
BUILD_DATE=${{ github.run_id }}
BUILD_ID=${{ github.sha }}
BASE_CONTENT_HASH=${{ steps.base-hash.outputs.hash }}
# Provenance disabled for smaller image and faster push
provenance: false
BASE_BUILD_ID=$(gcloud builds submit \
--config=cloudbuild-base.yaml \
--project=nomadkaraoke \
--format='value(id)' \
--async \
.)
- name: Build and push app image
if: steps.version_check.outputs.needs_deploy == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: backend/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.APP_IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.APP_IMAGE_NAME }}:${{ github.sha }}
${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.APP_IMAGE_NAME }}:v${{ steps.version_check.outputs.version }}
# Registry cache for app layers
# ignore-error=true allows build to continue if cache doesn't exist yet
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.APP_IMAGE_NAME }}:cache,ignore-error=true
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.APP_IMAGE_NAME }}:cache,mode=max,ignore-error=true
provenance: false
echo "Base Build ID: $BASE_BUILD_ID"
echo "Build URL: https://console.cloud.google.com/cloud-build/builds/$BASE_BUILD_ID?project=nomadkaraoke"
# ============================================
# Deploy to Cloud Run
# ============================================
echo "Waiting for base image build to complete..."
while true; do
BUILD_STATUS=$(gcloud builds describe $BASE_BUILD_ID --project=nomadkaraoke --format='value(status)')
echo "Base build status: $BUILD_STATUS"
if [ "$BUILD_STATUS" = "SUCCESS" ]; then
echo "✅ Base image build completed successfully"
break
elif [ "$BUILD_STATUS" = "FAILURE" ] || [ "$BUILD_STATUS" = "CANCELLED" ] || [ "$BUILD_STATUS" = "TIMEOUT" ]; then
echo "❌ Base image build failed with status: $BUILD_STATUS"
echo ""
echo "==================== BUILD LOGS ===================="
gcloud logging read "resource.type=build AND resource.labels.build_id=$BASE_BUILD_ID" \
--project=nomadkaraoke \
--format="value(textPayload)" \
--limit=200 \
--order=asc || echo "Failed to retrieve logs from Cloud Logging"
echo "===================================================="
gcloud builds log $BASE_BUILD_ID --project=nomadkaraoke 2>&1 || true
exit 1
fi
sleep 30
done
- name: Trigger Cloud Build
- name: Deploy to Cloud Run
if: steps.version_check.outputs.needs_deploy == 'true'
run: |
echo "🚀 Triggering Cloud Build for deployment..."
echo "Commit: ${{ github.sha }}"
echo "Version: ${{ steps.version_check.outputs.version }}"
VERSION="${{ steps.version_check.outputs.version }}"
IMAGE="${{ env.REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.APP_IMAGE_NAME }}:${{ github.sha }}"
BUILD_ID=$(gcloud builds submit \
--config=cloudbuild.yaml \
--project=nomadkaraoke \
--format='value(id)' \
--async \
.)
echo "🚀 Deploying to Cloud Run..."
echo "Image: $IMAGE"
echo "Version: $VERSION"
echo "Build ID: $BUILD_ID"
echo "Build URL: https://console.cloud.google.com/cloud-build/builds/$BUILD_ID?project=nomadkaraoke"
echo "Waiting for build to complete..."
while true; do
BUILD_STATUS=$(gcloud builds describe $BUILD_ID --project=nomadkaraoke --format='value(status)')
echo "Build status: $BUILD_STATUS"
if [ "$BUILD_STATUS" = "SUCCESS" ]; then
echo "✅ Build completed successfully"
break
elif [ "$BUILD_STATUS" = "FAILURE" ] || [ "$BUILD_STATUS" = "CANCELLED" ] || [ "$BUILD_STATUS" = "TIMEOUT" ]; then
echo "❌ Build failed with status: $BUILD_STATUS"
echo ""
echo "==================== BUILD LOGS ===================="
gcloud logging read "resource.type=build AND resource.labels.build_id=$BUILD_ID" \
--project=nomadkaraoke \
--format="value(textPayload)" \
--limit=200 \
--order=asc || echo "Failed to retrieve logs from Cloud Logging"
echo "===================================================="
echo ""
gcloud builds log $BUILD_ID --project=nomadkaraoke 2>&1 || true
exit 1
fi
sleep 30
done
gcloud run deploy karaoke-backend \
--image $IMAGE \
--region us-central1 \
--platform managed \
--allow-unauthenticated \
--memory 16Gi \
--cpu 8 \
--cpu-boost \
--execution-environment gen2 \
--timeout 1800 \
--concurrency 1 \
--max-instances 50 \
--min-instances 0 \
--set-env-vars "GOOGLE_CLOUD_PROJECT=${{ env.PROJECT_ID }},GCS_BUCKET_NAME=karaoke-gen-storage-${{ env.PROJECT_ID }},FIRESTORE_COLLECTION=jobs,ENVIRONMENT=production,AUDIO_SEPARATOR_API_URL=https://nomadkaraoke--audio-separator-api.modal.run,KARAOKE_GEN_VERSION=$VERSION,DEFAULT_DROPBOX_PATH=/MediaUnsynced/Karaoke/Tracks-Organized,DEFAULT_GDRIVE_FOLDER_ID=1laRKAyxo0v817SstfM5XkpbWiNKNAMSX,ENABLE_CLOUD_TASKS=true,CLOUD_RUN_SERVICE_URL=https://api.nomadkaraoke.com,GCP_REGION=us-central1,DEFAULT_ENABLE_YOUTUBE_UPLOAD=true,DEFAULT_BRAND_PREFIX=NOMAD" \
--set-secrets "AUDIOSHAKE_API_TOKEN=audioshake-api-key:latest,GENIUS_API_TOKEN=genius-api-key:latest,SPOTIFY_COOKIE_SP_DC=spotify-cookie:latest,RAPIDAPI_KEY=rapidapi-key:latest,DEFAULT_DISCORD_WEBHOOK_URL=discord-releases-webhook:latest,ADMIN_TOKENS=admin-tokens:latest,RED_API_KEY=red-api-key:latest,RED_API_URL=red-api-url:latest,OPS_API_KEY=ops-api-key:latest,OPS_API_URL=ops-api-url:latest,FLACFETCH_API_URL=flacfetch-api-url:latest,FLACFETCH_API_KEY=flacfetch-api-key:latest"
- name: Verify deployment and version
if: steps.version_check.outputs.needs_deploy == 'true'
@@ -804,6 +925,10 @@ jobs:
echo "Commit: ${{ github.sha }}"
echo "Branch: ${{ github.ref_name }}"
echo "Run: ${{ github.run_number }}"
echo ""
echo "📊 Cost savings: This build used FREE GitHub Actions instead of Cloud Build"
echo " Previously: ~\$0.064/min with N1_HIGHCPU_32"
echo " Now: \$0 (public repo) with registry-cached builds"
- name: Skipped deployment summary
if: steps.version_check.outputs.needs_deploy == 'false'
+3
View File
@@ -227,3 +227,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
flacfetch
# Test output directories
Rick Astley*/
+32 -11
View File
@@ -18,18 +18,15 @@ Create descriptive branch names like `feature/add-discord-notifications`, `fix/a
### Using Git Worktrees
**For non-trivial changes** (new features, multi-file edits, refactors):
- Create a git worktree in the parent folder before making any file changes:
```bash
git worktree add ../karaoke-gen-feat-xyz feature/xyz
```
**All changes require a git worktree.** Since all changes must go through a PR, always create a worktree in the parent folder before making any file changes:
```bash
git worktree add -b feature/xyz ../karaoke-gen-feat-xyz main
```
- This keeps the main directory clean on `main` and enables parallel work on multiple features
- Name the worktree folder descriptively, e.g., `../karaoke-gen-fix-audio-sync`
**For trivial changes** (typos, single-line fixes):
- Creating a branch in the current directory is acceptable
- Use `git checkout -b fix/typo-xyz` before making changes
**Cleanup:** When done with a worktree, remove it with:
```bash
git worktree remove ../karaoke-gen-feat-xyz
@@ -75,11 +72,13 @@ Do not attempt to work around auth issues or make assumptions about credentials.
## Version Management
When committing and pushing changes, always bump the patch version in `pyproject.toml`.
When committing and pushing **code changes**, bump the patch version in `pyproject.toml`.
The version is located at `tool.poetry.version` in `pyproject.toml`. For example, if the current version is `0.70.3`, bump it to `0.70.4`.
This ensures every commit pushed to the repository has a unique version number for tracking and deployment purposes.
**Skip version bumps** for documentation-only changes (e.g., updating `CLAUDE.md`, `README.md`, or other markdown files) that don't affect deployed code.
This ensures every code release has a unique version number for tracking and deployment purposes.
## Testing Requirements
@@ -129,3 +128,25 @@ Individual test commands:
**Do not commit or push code that fails tests. Fix any test failures before proceeding.**
## Related Projects
### flacfetch
**Location:** `/Users/andrew/Projects/flacfetch`
The `flacfetch` package is a dependency of karaoke-gen that we also own. When working on features that interact with flacfetch, you can read and modify its code directly.
**Workflow for flacfetch changes:**
1. Navigate to `/Users/andrew/Projects/flacfetch`
2. Make changes directly on `main` (no PR required for this repo)
3. Run tests and ensure they pass
4. Bump the version in flacfetch's `pyproject.toml`
5. Commit and push to `main`
6. Wait for CI workflow to complete and auto-release the new version
7. Return to karaoke-gen and update the poetry dependency:
```bash
poetry update flacfetch
```
8. Commit the updated `poetry.lock` in karaoke-gen
+72 -2
View File
@@ -71,8 +71,40 @@ export AUDIOSHAKE_API_TOKEN="your_audioshake_token"
Get an API key at [https://www.audioshake.ai/](https://www.audioshake.ai/) - business only, at time of writing this.
#### Option 2: Whisper via RunPod
Open-source alternative using OpenAI's Whisper model on RunPod infrastructure.
#### Option 2: Local Whisper (No Cloud Required)
Run Whisper directly on your local machine using whisper-timestamped. Works on CPU, NVIDIA GPU (CUDA), or Apple Silicon.
```bash
# Install with local Whisper support
pip install karaoke-gen[local-whisper]
# Optional: Configure model size (tiny, base, small, medium, large)
export WHISPER_MODEL_SIZE="medium"
# Optional: Force specific device (cpu, cuda, mps)
export WHISPER_DEVICE="cpu"
```
**Model Size Guide:**
| Model | VRAM | Speed | Quality |
|-------|------|-------|---------|
| tiny | ~1GB | Fast | Lower |
| base | ~1GB | Fast | Basic |
| small | ~2GB | Medium | Good |
| medium | ~5GB | Slower | Better |
| large | ~10GB | Slowest | Best |
**CPU-Only Installation** (no GPU required):
```bash
# Pre-install CPU-only PyTorch first
pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install karaoke-gen[local-whisper]
```
Local Whisper runs automatically as a fallback when no cloud transcription services are configured.
#### Option 3: Whisper via RunPod
Cloud-based alternative using OpenAI's Whisper model on RunPod infrastructure.
```bash
export RUNPOD_API_KEY="your_runpod_key"
@@ -574,6 +606,44 @@ If the output video has quality problems:
- Check available codecs: `ffmpeg -codecs`
- For 4K output, ensure sufficient disk space (10GB+ per track)
### Local Whisper Issues
#### GPU Out of Memory
If you get CUDA out of memory errors:
```bash
# Use a smaller model
export WHISPER_MODEL_SIZE="small" # or "tiny"
# Or force CPU mode
export WHISPER_DEVICE="cpu"
```
#### Slow Transcription on CPU
CPU transcription is significantly slower than GPU. For faster processing:
- Use a smaller model (`tiny` or `base`)
- Consider using cloud transcription (AudioShake or RunPod)
- On Apple Silicon, the `small` model offers good speed/quality balance
#### Model Download Issues
Whisper models are downloaded on first use (~1-3GB depending on size). If downloads fail:
- Check your internet connection
- Set a custom cache directory: `export WHISPER_CACHE_DIR="/path/with/space"`
- Models are cached in `~/.cache/whisper/` by default
#### whisper-timestamped Not Found
If you get "whisper-timestamped is not installed":
```bash
pip install karaoke-gen[local-whisper]
# Or install directly:
pip install whisper-timestamped
```
#### Disabling Local Whisper
If you want to disable local Whisper (e.g., to force cloud transcription):
```bash
export ENABLE_LOCAL_WHISPER="false"
```
---
## 🧪 Development
@@ -0,0 +1,197 @@
# GitHub Actions Docker Builds - Cost Optimization
**Date:** 2025-12-28
**Problem:** Cloud Build costing $100+/month with slow builds
**Solution:** Move Docker builds to GitHub Actions with registry caching
---
## Overview
This document describes the migration from Google Cloud Build to GitHub Actions for Docker image builds. This change eliminates Cloud Build costs while improving build speeds through better caching.
## Cost Comparison
| Approach | Monthly Cost | Build Speed | Caching |
|----------|-------------|-------------|---------|
| **Cloud Build (N1_HIGHCPU_32)** | ~$100+ | 5-15 min | Limited |
| **GitHub Actions + Registry Cache** | **$0** | 2-5 min | Excellent |
### Why Cloud Build Was Expensive
1. **N1_HIGHCPU_32 pricing**: ~$0.064/build-minute (21x more than default)
2. **No persistent layer cache**: Each build re-downloaded dependencies
3. **Cold start overhead**: Spinning up build VMs added latency
4. **Large dependency tree**: torch, transformers, etc. = ~500 packages
### Why GitHub Actions Is Free
- **Public repositories**: Unlimited build minutes on GitHub-hosted runners
- **Registry cache**: Layers cached in Artifact Registry, persist between builds
- **BuildKit mode=max**: Caches ALL intermediate layers, not just final
---
## Architecture
```
┌─────────────────────────────────────────────────────────────────────────┐
│ NEW BUILD PIPELINE │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ GitHub Actions (Free) │
│ ├── docker/setup-buildx-action (BuildKit) │
│ ├── google-github-actions/auth (Workload Identity) │
│ └── docker/build-push-action │
│ ├── cache-from: type=registry,ref=...karaoke-backend:cache │
│ └── cache-to: type=registry,ref=...karaoke-backend:cache,mode=max│
│ │
│ Artifact Registry │
│ ├── karaoke-backend:latest (production image) │
│ ├── karaoke-backend:cache (build cache - ALL layers) │
│ ├── karaoke-backend-base:latest (base image with deps) │
│ └── karaoke-backend-base:cache (base cache) │
│ │
│ Build Times (Expected): │
│ ├── First build (cold): ~8-10 min │
│ ├── Code-only changes: ~2-3 min (cache hit) │
│ └── Dependency changes: ~6-8 min (partial cache hit) │
│ │
└─────────────────────────────────────────────────────────────────────────┘
```
---
## How It Works
### Two-Stage Build Pattern
We maintain the existing two-stage build pattern for efficiency:
1. **Base Image** (`karaoke-backend-base`)
- Contains Python 3.11, ffmpeg, system dependencies
- All pip dependencies pre-installed
- Only rebuilt when `poetry.lock` or `Dockerfile.base` changes
- Hash-based change detection via image labels
2. **App Image** (`karaoke-backend`)
- Built FROM the base image
- Contains only application code
- Fast rebuilds (~2 min) for code-only changes
### Registry Cache
The key optimization is using Artifact Registry as a persistent layer cache:
```yaml
- uses: docker/build-push-action@v6
with:
cache-from: type=registry,ref=.../karaoke-backend:cache
cache-to: type=registry,ref=.../karaoke-backend:cache,mode=max
```
**Benefits:**
- `mode=max` caches ALL layers, not just the final image
- Cache persists between CI runs (unlike GitHub Actions cache which has 10GB limit)
- Layers only re-built when inputs change
---
## Files Changed
### New Files
- **`.dockerignore`** - Reduces build context from ~1GB to ~10MB
### Modified Files
- **`.github/workflows/ci.yml`** - `deploy-backend` job rewritten to use:
- `docker/setup-buildx-action@v3`
- `docker/build-push-action@v6`
- Registry caching to Artifact Registry
### Kept (as fallback)
- **`cloudbuild.yaml`** - Still works for manual triggers
- **`cloudbuild-base.yaml`** - Still works for manual base image builds
---
## Manual Builds (Fallback)
If GitHub Actions fails, you can still use Cloud Build:
```bash
# Build base image (only if dependencies changed)
gcloud builds submit --config=cloudbuild-base.yaml --project=nomadkaraoke
# Build and deploy app image
gcloud builds submit --config=cloudbuild.yaml --project=nomadkaraoke
```
---
## Monitoring
### Check Build Cache Usage
View cache images in Artifact Registry:
```bash
gcloud artifacts docker images list \
us-central1-docker.pkg.dev/nomadkaraoke/karaoke-repo \
--include-tags
```
You should see `*:cache` tags for both base and app images.
### Compare Build Times
- **GitHub Actions**: Check workflow run times in Actions tab
- **Previous Cloud Build**: ~5-15 min per build
- **Expected with cache**: ~2-3 min for code changes
---
## Troubleshooting
### Cache Miss (Slow Build)
If builds are slow despite no dependency changes:
1. Check if cache image exists:
```bash
docker pull us-central1-docker.pkg.dev/nomadkaraoke/karaoke-repo/karaoke-backend:cache
```
2. Force cache rebuild by pushing to `main` with a small change
### Disk Space Issues
GitHub Actions runners have limited disk. If base image builds fail:
1. The workflow includes `jlumbroso/free-disk-space` action
2. It removes Android SDK, Haskell, .NET, etc. to free ~20GB
### Authentication Issues
If `docker push` fails with permission errors:
1. Check Workload Identity is configured correctly
2. Verify service account has `roles/artifactregistry.writer`
---
## Future Improvements
1. **Parallel base/app builds**: If base is unchanged, start app build immediately
2. **GitHub Actions cache fallback**: Use GHA cache when registry is slow
3. **Build metrics**: Track build times and cache hit rates
---
## References
- [Docker Build with GitHub Actions](https://docs.docker.com/build/ci/github-actions/)
- [Registry Cache Backend](https://docs.docker.com/build/cache/backends/registry/)
- [Cache Management](https://docs.docker.com/build/ci/github-actions/cache/)
+13 -8
View File
@@ -29,10 +29,6 @@ jest.mock('../job/OutputLinks', () => ({
OutputLinks: () => <div data-testid="output-links">Output Links</div>
}))
jest.mock('../job/InstrumentalSelector', () => ({
InstrumentalSelector: () => <div data-testid="instrumental-selector">Instrumental Selector</div>
}))
jest.mock('../audio-search/AudioSearchDialog', () => ({
AudioSearchDialog: () => <div data-testid="audio-search-dialog">Audio Search Dialog</div>
}))
@@ -135,11 +131,20 @@ describe('JobCard', () => {
expect(screen.getByRole('button', { name: 'Select Audio' })).toBeInTheDocument()
})
it('shows instrumental selection button for awaiting_instrumental_selection status', () => {
const instrumentalJob = { ...mockJob, status: 'awaiting_instrumental_selection' }
it('shows instrumental selection link for awaiting_instrumental_selection status', () => {
const instrumentalJob = {
...mockJob,
status: 'awaiting_instrumental_selection',
instrumental_token: 'test-instrumental-token'
}
render(<JobCard job={instrumentalJob} onRefresh={mockOnRefresh} />)
expect(screen.getByRole('button', { name: 'Select Instrumental' })).toBeInTheDocument()
const instrumentalLink = screen.getByText('Select Instrumental')
expect(instrumentalLink).toBeInTheDocument()
const href = instrumentalLink.closest('a')?.getAttribute('href') || ''
expect(href).toContain('/instrumental/')
expect(href).toContain('baseApiUrl=')
expect(href).toContain('instrumentalToken=test-instrumental-token')
})
})
@@ -164,7 +169,7 @@ describe('JobCard', () => {
render(<JobCard job={instrumentalJob} onRefresh={mockOnRefresh} />)
expect(screen.getByText(/Will auto-select clean/)).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Select Instrumental' })).not.toBeInTheDocument()
expect(screen.queryByText('Select Instrumental')).not.toBeInTheDocument()
})
it('shows auto-select message for awaiting_audio_selection status', () => {
@@ -1,263 +0,0 @@
"use client"
import { useRef, useState, useEffect, useCallback } from "react"
import { Button } from "@/components/ui/button"
import { Slider } from "@/components/ui/slider"
import { Play, Pause, SkipBack, SkipForward, Volume2, VolumeX } from "lucide-react"
interface AudioPlayerProps {
src: string
onTimeUpdate?: (currentTime: number) => void
onDurationChange?: (duration: number) => void
seekTo?: number
label?: string
className?: string
}
export function AudioPlayer({
src,
onTimeUpdate,
onDurationChange,
seekTo,
label,
className = "",
}: AudioPlayerProps) {
const audioRef = useRef<HTMLAudioElement>(null)
const [isPlaying, setIsPlaying] = useState(false)
const [currentTime, setCurrentTime] = useState(0)
const [duration, setDuration] = useState(0)
const [volume, setVolume] = useState(1)
const [isMuted, setIsMuted] = useState(false)
const [isLoading, setIsLoading] = useState(true)
// Handle external seek requests
useEffect(() => {
if (seekTo !== undefined && audioRef.current && !isNaN(seekTo)) {
audioRef.current.currentTime = seekTo
}
}, [seekTo])
// Handle audio events
useEffect(() => {
const audio = audioRef.current
if (!audio) return
const handleTimeUpdate = () => {
setCurrentTime(audio.currentTime)
onTimeUpdate?.(audio.currentTime)
}
const handleDurationChange = () => {
setDuration(audio.duration)
onDurationChange?.(audio.duration)
}
const handleLoadedData = () => {
setIsLoading(false)
setDuration(audio.duration)
onDurationChange?.(audio.duration)
}
const handleEnded = () => {
setIsPlaying(false)
}
const handleLoadStart = () => {
setIsLoading(true)
}
const handleCanPlay = () => {
setIsLoading(false)
}
// Sync isPlaying state with actual audio element state
const handlePlay = () => {
setIsPlaying(true)
}
const handlePause = () => {
setIsPlaying(false)
}
audio.addEventListener("timeupdate", handleTimeUpdate)
audio.addEventListener("durationchange", handleDurationChange)
audio.addEventListener("loadeddata", handleLoadedData)
audio.addEventListener("ended", handleEnded)
audio.addEventListener("loadstart", handleLoadStart)
audio.addEventListener("canplay", handleCanPlay)
audio.addEventListener("play", handlePlay)
audio.addEventListener("pause", handlePause)
return () => {
audio.removeEventListener("timeupdate", handleTimeUpdate)
audio.removeEventListener("durationchange", handleDurationChange)
audio.removeEventListener("loadeddata", handleLoadedData)
audio.removeEventListener("ended", handleEnded)
audio.removeEventListener("loadstart", handleLoadStart)
audio.removeEventListener("canplay", handleCanPlay)
audio.removeEventListener("play", handlePlay)
audio.removeEventListener("pause", handlePause)
}
}, [onTimeUpdate, onDurationChange])
// Update volume
useEffect(() => {
if (audioRef.current) {
audioRef.current.volume = isMuted ? 0 : volume
}
}, [volume, isMuted])
const togglePlay = useCallback(async () => {
const audio = audioRef.current
if (!audio) return
try {
if (audio.paused) {
await audio.play()
} else {
audio.pause()
}
// State will be updated by the play/pause event listeners
} catch (error) {
// Play was prevented (e.g., user hasn't interacted with page yet)
console.warn("Audio playback was prevented:", error)
}
}, [])
const handleSeek = useCallback((value: number[]) => {
const audio = audioRef.current
if (!audio) return
const newTime = value[0]
audio.currentTime = newTime
setCurrentTime(newTime)
}, [])
const skipBackward = useCallback(() => {
const audio = audioRef.current
if (!audio) return
audio.currentTime = Math.max(0, audio.currentTime - 5)
}, [])
const skipForward = useCallback(() => {
const audio = audioRef.current
if (!audio) return
audio.currentTime = Math.min(duration, audio.currentTime + 5)
}, [duration])
const toggleMute = useCallback(() => {
setIsMuted(!isMuted)
}, [isMuted])
const handleVolumeChange = useCallback((value: number[]) => {
setVolume(value[0])
if (value[0] > 0 && isMuted) {
setIsMuted(false)
}
}, [isMuted])
const formatTime = (time: number) => {
if (isNaN(time)) return "0:00"
const minutes = Math.floor(time / 60)
const seconds = Math.floor(time % 60)
return `${minutes}:${seconds.toString().padStart(2, "0")}`
}
return (
<div className={`bg-card rounded-lg p-4 ${className}`}>
<audio ref={audioRef} src={src} preload="metadata" />
{label && (
<div className="text-sm font-medium text-muted-foreground mb-3">
{label}
</div>
)}
{/* Progress bar */}
<div className="mb-4">
<Slider
value={[currentTime]}
max={duration || 100}
step={0.1}
onValueChange={handleSeek}
disabled={isLoading}
className="w-full"
/>
<div className="flex justify-between text-xs text-muted-foreground mt-1">
<span>{formatTime(currentTime)}</span>
<span>{formatTime(duration)}</span>
</div>
</div>
{/* Controls */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="icon"
onClick={skipBackward}
disabled={isLoading}
className="h-8 w-8"
>
<SkipBack className="h-4 w-4" />
</Button>
<Button
variant="default"
size="icon"
onClick={togglePlay}
disabled={isLoading}
className="h-10 w-10"
>
{isPlaying ? (
<Pause className="h-5 w-5" />
) : (
<Play className="h-5 w-5 ml-0.5" />
)}
</Button>
<Button
variant="ghost"
size="icon"
onClick={skipForward}
disabled={isLoading}
className="h-8 w-8"
>
<SkipForward className="h-4 w-4" />
</Button>
</div>
{/* Volume control */}
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="icon"
onClick={toggleMute}
className="h-8 w-8"
>
{isMuted || volume === 0 ? (
<VolumeX className="h-4 w-4" />
) : (
<Volume2 className="h-4 w-4" />
)}
</Button>
<Slider
value={[isMuted ? 0 : volume]}
max={1}
step={0.1}
onValueChange={handleVolumeChange}
className="w-20"
/>
</div>
</div>
{isLoading && (
<div className="text-xs text-muted-foreground text-center mt-2">
Loading audio...
</div>
)}
</div>
)
}
@@ -1,3 +0,0 @@
export { WaveformDisplay } from "./waveform-display"
export { AudioPlayer } from "./audio-player"
export { RegionSelector } from "./region-selector"
@@ -1,222 +0,0 @@
"use client"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Trash2, VolumeX, Plus } from "lucide-react"
interface MuteRegion {
start_seconds: number
end_seconds: number
}
interface AudibleSegment {
start_seconds: number
end_seconds: number
duration_seconds: number
avg_amplitude_db: number
}
interface RegionSelectorProps {
muteRegions: MuteRegion[]
audibleSegments?: AudibleSegment[]
onAddRegion: (region: MuteRegion) => void
onRemoveRegion: (index: number) => void
onClearAll: () => void
onSeekTo?: (time: number) => void
isSelectionMode: boolean
onToggleSelectionMode: () => void
className?: string
}
export function RegionSelector({
muteRegions,
audibleSegments = [],
onAddRegion,
onRemoveRegion,
onClearAll,
onSeekTo,
isSelectionMode,
onToggleSelectionMode,
className = "",
}: RegionSelectorProps) {
const formatTime = (seconds: number) => {
const mins = Math.floor(seconds / 60)
const secs = Math.floor(seconds % 60)
const ms = Math.floor((seconds % 1) * 100)
return `${mins}:${secs.toString().padStart(2, "0")}.${ms.toString().padStart(2, "0")}`
}
const formatDuration = (seconds: number) => {
if (seconds < 1) {
return `${Math.round(seconds * 1000)}ms`
}
return `${seconds.toFixed(1)}s`
}
const totalMutedDuration = muteRegions.reduce(
(sum, r) => sum + (r.end_seconds - r.start_seconds),
0
)
// Quick mute: add mute region for an audible segment
const handleQuickMute = (segment: AudibleSegment) => {
onAddRegion({
start_seconds: segment.start_seconds,
end_seconds: segment.end_seconds,
})
}
// Check if a segment is already muted
const isSegmentMuted = (segment: AudibleSegment) => {
return muteRegions.some(
(r) =>
r.start_seconds <= segment.start_seconds &&
r.end_seconds >= segment.end_seconds
)
}
return (
<div className={`space-y-4 ${className}`}>
{/* Selection Mode Toggle */}
<Card>
<CardHeader className="pb-3">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">Mute Regions</CardTitle>
<Button
variant={isSelectionMode ? "default" : "outline"}
size="sm"
onClick={onToggleSelectionMode}
>
<Plus className="h-4 w-4 mr-2" />
{isSelectionMode ? "Click waveform to select" : "Add Region"}
</Button>
</div>
</CardHeader>
<CardContent>
{muteRegions.length === 0 ? (
<p className="text-sm text-muted-foreground">
No mute regions selected. Click "Add Region" and drag on the waveform to select areas to mute.
</p>
) : (
<div className="space-y-2">
{muteRegions.map((region, index) => (
<div
key={index}
className="flex items-center justify-between p-2 bg-muted/50 rounded-lg group"
>
<div className="flex items-center gap-3">
<VolumeX className="h-4 w-4 text-destructive" />
<button
onClick={() => onSeekTo?.(region.start_seconds)}
className="text-sm font-mono hover:text-primary transition-colors"
>
{formatTime(region.start_seconds)}
</button>
<span className="text-muted-foreground">→</span>
<button
onClick={() => onSeekTo?.(region.end_seconds)}
className="text-sm font-mono hover:text-primary transition-colors"
>
{formatTime(region.end_seconds)}
</button>
<Badge variant="secondary" className="ml-2">
{formatDuration(region.end_seconds - region.start_seconds)}
</Badge>
</div>
<Button
variant="ghost"
size="icon"
onClick={() => onRemoveRegion(index)}
className="h-8 w-8 opacity-0 group-hover:opacity-100 transition-opacity"
>
<Trash2 className="h-4 w-4 text-destructive" />
</Button>
</div>
))}
<div className="flex items-center justify-between pt-2 border-t mt-3">
<span className="text-sm text-muted-foreground">
Total muted: {formatDuration(totalMutedDuration)}
</span>
<Button
variant="ghost"
size="sm"
onClick={onClearAll}
className="text-destructive hover:text-destructive"
>
Clear All
</Button>
</div>
</div>
)}
</CardContent>
</Card>
{/* Detected Audible Segments */}
{audibleSegments.length > 0 && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-lg">Detected Backing Vocals</CardTitle>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground mb-3">
Click a segment to jump to that time, or click the mute button to add it as a mute region.
</p>
<div className="space-y-2 max-h-64 overflow-y-auto">
{audibleSegments.map((segment, index) => {
const isMuted = isSegmentMuted(segment)
return (
<div
key={index}
className={`flex items-center justify-between p-2 rounded-lg transition-colors ${
isMuted ? "bg-destructive/10" : "bg-muted/50 hover:bg-muted"
}`}
>
<button
onClick={() => onSeekTo?.(segment.start_seconds)}
className="flex items-center gap-3 text-left"
>
<span className="text-sm font-mono">
{formatTime(segment.start_seconds)} - {formatTime(segment.end_seconds)}
</span>
<Badge variant="outline" className="text-xs">
{formatDuration(segment.duration_seconds)}
</Badge>
<Badge
variant="outline"
className={`text-xs ${
segment.avg_amplitude_db > -20
? "border-yellow-500 text-yellow-500"
: "border-muted-foreground"
}`}
>
{segment.avg_amplitude_db.toFixed(1)}dB
</Badge>
</button>
{!isMuted && (
<Button
variant="ghost"
size="sm"
onClick={() => handleQuickMute(segment)}
className="text-xs"
>
<VolumeX className="h-3 w-3 mr-1" />
Mute
</Button>
)}
{isMuted && (
<Badge variant="destructive" className="text-xs">
Muted
</Badge>
)}
</div>
)
})}
</div>
</CardContent>
</Card>
)}
</div>
)
}
@@ -1,259 +0,0 @@
"use client"
import { useRef, useEffect, useState, useCallback } from "react"
interface AudibleSegment {
start_seconds: number
end_seconds: number
duration_seconds: number
avg_amplitude_db: number
}
interface MuteRegion {
start_seconds: number
end_seconds: number
}
interface WaveformDisplayProps {
amplitudes: number[]
duration: number
currentTime?: number
segments?: AudibleSegment[]
muteRegions?: MuteRegion[]
onSeek?: (time: number) => void
onRegionSelect?: (region: MuteRegion) => void
isSelecting?: boolean
width?: number
height?: number
className?: string
}
export function WaveformDisplay({
amplitudes,
duration,
currentTime = 0,
segments = [],
muteRegions = [],
onSeek,
onRegionSelect,
isSelecting = false,
width = 800,
height = 150,
className = "",
}: WaveformDisplayProps) {
const canvasRef = useRef<HTMLCanvasElement>(null)
const [isDragging, setIsDragging] = useState(false)
const [dragStart, setDragStart] = useState<number | null>(null)
const [dragEnd, setDragEnd] = useState<number | null>(null)
const [hoveredTime, setHoveredTime] = useState<number | null>(null)
// Convert time to x position
const timeToX = useCallback((time: number) => {
return (time / duration) * width
}, [duration, width])
// Convert x position to time
const xToTime = useCallback((x: number) => {
return (x / width) * duration
}, [duration, width])
// Draw the waveform
useEffect(() => {
const canvas = canvasRef.current
if (!canvas) return
const ctx = canvas.getContext("2d")
if (!ctx) return
// Clear canvas
ctx.fillStyle = "#1a1a2e"
ctx.fillRect(0, 0, width, height)
const barWidth = width / amplitudes.length
const centerY = height / 2
// Draw mute regions background
ctx.fillStyle = "rgba(255, 107, 107, 0.2)"
for (const region of muteRegions) {
const startX = timeToX(region.start_seconds)
const endX = timeToX(region.end_seconds)
ctx.fillRect(startX, 0, endX - startX, height)
}
// Draw current drag selection
if (isDragging && dragStart !== null && dragEnd !== null) {
const startX = Math.min(timeToX(dragStart), timeToX(dragEnd))
const endX = Math.max(timeToX(dragStart), timeToX(dragEnd))
ctx.fillStyle = "rgba(255, 107, 107, 0.3)"
ctx.fillRect(startX, 0, endX - startX, height)
}
// Draw segment highlights
for (const segment of segments) {
const startX = timeToX(segment.start_seconds)
const endX = timeToX(segment.end_seconds)
const startIdx = Math.floor((segment.start_seconds / duration) * amplitudes.length)
const endIdx = Math.ceil((segment.end_seconds / duration) * amplitudes.length)
ctx.fillStyle = "rgba(233, 69, 96, 0.4)"
for (let i = startIdx; i < endIdx && i < amplitudes.length; i++) {
const amplitude = amplitudes[i]
const barHeight = amplitude * height * 0.8
const x = i * barWidth
ctx.fillRect(x, centerY - barHeight / 2, barWidth - 1, barHeight)
}
}
// Draw main waveform
ctx.fillStyle = "#4a90d9"
for (let i = 0; i < amplitudes.length; i++) {
const amplitude = amplitudes[i]
const barHeight = amplitude * height * 0.8
const x = i * barWidth
ctx.fillRect(x, centerY - barHeight / 2, barWidth - 1, barHeight)
}
// Draw silence threshold line
ctx.strokeStyle = "rgba(255, 255, 255, 0.2)"
ctx.setLineDash([5, 5])
ctx.beginPath()
const thresholdY = height * 0.5 // Visual representation
ctx.moveTo(0, thresholdY)
ctx.lineTo(width, thresholdY)
ctx.stroke()
ctx.setLineDash([])
// Draw playhead
if (currentTime > 0) {
const playheadX = timeToX(currentTime)
ctx.strokeStyle = "#ffffff"
ctx.lineWidth = 2
ctx.beginPath()
ctx.moveTo(playheadX, 0)
ctx.lineTo(playheadX, height)
ctx.stroke()
}
// Draw hover position
if (hoveredTime !== null && !isDragging) {
const hoverX = timeToX(hoveredTime)
ctx.strokeStyle = "rgba(255, 255, 255, 0.5)"
ctx.lineWidth = 1
ctx.beginPath()
ctx.moveTo(hoverX, 0)
ctx.lineTo(hoverX, height)
ctx.stroke()
}
// Draw time axis
ctx.fillStyle = "#ffffff"
ctx.font = "10px sans-serif"
ctx.textAlign = "center"
const tickInterval = duration > 300 ? 60 : duration > 60 ? 30 : 10
for (let t = 0; t <= duration; t += tickInterval) {
const x = timeToX(t)
const minutes = Math.floor(t / 60)
const seconds = Math.floor(t % 60)
const label = `${minutes}:${seconds.toString().padStart(2, "0")}`
ctx.fillText(label, x, height - 5)
// Tick mark
ctx.strokeStyle = "rgba(255, 255, 255, 0.3)"
ctx.beginPath()
ctx.moveTo(x, height - 20)
ctx.lineTo(x, height - 15)
ctx.stroke()
}
}, [amplitudes, duration, currentTime, segments, muteRegions, width, height, isDragging, dragStart, dragEnd, hoveredTime, timeToX])
// Handle mouse events for seeking and region selection
const handleMouseDown = (e: React.MouseEvent<HTMLCanvasElement>) => {
const canvas = canvasRef.current
if (!canvas) return
const rect = canvas.getBoundingClientRect()
const x = e.clientX - rect.left
const time = xToTime(x)
if (isSelecting) {
setIsDragging(true)
setDragStart(time)
setDragEnd(time)
} else if (onSeek) {
onSeek(time)
}
}
const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
const canvas = canvasRef.current
if (!canvas) return
const rect = canvas.getBoundingClientRect()
const x = e.clientX - rect.left
const time = xToTime(x)
setHoveredTime(time)
if (isDragging && isSelecting) {
setDragEnd(time)
}
}
const handleMouseUp = () => {
if (isDragging && dragStart !== null && dragEnd !== null && onRegionSelect) {
const start = Math.min(dragStart, dragEnd)
const end = Math.max(dragStart, dragEnd)
// Only create region if it's at least 0.1 seconds
if (end - start >= 0.1) {
onRegionSelect({ start_seconds: start, end_seconds: end })
}
}
setIsDragging(false)
setDragStart(null)
setDragEnd(null)
}
const handleMouseLeave = () => {
setHoveredTime(null)
if (isDragging) {
handleMouseUp()
}
}
// Format time for tooltip
const formatTime = (time: number) => {
const minutes = Math.floor(time / 60)
const seconds = Math.floor(time % 60)
const ms = Math.floor((time % 1) * 100)
return `${minutes}:${seconds.toString().padStart(2, "0")}.${ms.toString().padStart(2, "0")}`
}
return (
<div className={`relative ${className}`}>
<canvas
ref={canvasRef}
width={width}
height={height}
className={`rounded-lg ${isSelecting ? "cursor-crosshair" : "cursor-pointer"}`}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
onMouseLeave={handleMouseLeave}
/>
{/* Time tooltip */}
{hoveredTime !== null && (
<div
className="absolute top-0 transform -translate-x-1/2 bg-black/80 text-white text-xs px-2 py-1 rounded pointer-events-none"
style={{ left: timeToX(hoveredTime) }}
>
{formatTime(hoveredTime)}
</div>
)}
</div>
)
}
@@ -1,166 +0,0 @@
"use client"
import { useState, useEffect } from "react"
import { api, InstrumentalOption } from "@/lib/api"
import { Button } from "@/components/ui/button"
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Loader2, Music2, Play, Pause } from "lucide-react"
interface InstrumentalSelectorProps {
jobId: string
open: boolean
onClose: () => void
onSelect: () => void
}
export function InstrumentalSelector({ jobId, open, onClose, onSelect }: InstrumentalSelectorProps) {
const [options, setOptions] = useState<InstrumentalOption[]>([])
const [isLoading, setIsLoading] = useState(true)
const [isSelecting, setIsSelecting] = useState(false)
const [error, setError] = useState("")
const [playingId, setPlayingId] = useState<string | null>(null)
const [audioElements, setAudioElements] = useState<Map<string, HTMLAudioElement>>(new Map())
useEffect(() => {
if (open) {
loadOptions()
}
return () => {
// Cleanup audio elements
audioElements.forEach(audio => {
audio.pause()
audio.src = ""
})
}
}, [open])
async function loadOptions() {
setIsLoading(true)
setError("")
try {
const data = await api.getInstrumentalOptions(jobId)
setOptions(data.options || [])
} catch (err: any) {
console.error("Failed to load instrumental options:", err)
setError(err.message || "Failed to load options")
} finally {
setIsLoading(false)
}
}
async function handleSelect(selection: 'clean' | 'with_backing') {
setIsSelecting(true)
try {
await api.selectInstrumental(jobId, selection)
onSelect()
onClose()
} catch (err: any) {
console.error("Failed to select instrumental:", err)
setError(err.message || "Failed to select instrumental")
} finally {
setIsSelecting(false)
}
}
function togglePlayback(optionId: string, audioUrl: string) {
if (playingId === optionId) {
// Pause current
const audio = audioElements.get(optionId)
if (audio) {
audio.pause()
}
setPlayingId(null)
} else {
// Stop any currently playing audio
audioElements.forEach(audio => audio.pause())
// Play new audio
let audio = audioElements.get(optionId)
if (!audio) {
audio = new Audio(audioUrl)
audio.addEventListener('ended', () => setPlayingId(null))
audioElements.set(optionId, audio)
setAudioElements(new Map(audioElements))
}
audio.play()
setPlayingId(optionId)
}
}
return (
<Dialog open={open} onOpenChange={(open) => !open && onClose()}>
<DialogContent className="max-w-2xl bg-slate-900 border-slate-700">
<DialogHeader>
<DialogTitle className="text-white">Select Instrumental Version</DialogTitle>
<DialogDescription className="text-slate-400">
Choose between a clean instrumental or one with backing vocals
</DialogDescription>
</DialogHeader>
{isLoading ? (
<div className="flex items-center justify-center py-8">
<Loader2 className="w-6 h-6 animate-spin text-slate-400" />
<span className="ml-2 text-slate-400">Loading options...</span>
</div>
) : error ? (
<div className="text-center py-8 text-red-400">{error}</div>
) : options.length === 0 ? (
<div className="text-center py-8 text-slate-500">
<Music2 className="w-12 h-12 mx-auto mb-3 opacity-50" />
<p>No instrumental options available</p>
</div>
) : (
<div className="space-y-3">
{options.map((option) => (
<div
key={option.id}
className="border border-slate-700 rounded-lg p-4 hover:bg-slate-800/50 transition-colors"
>
<div className="flex items-center justify-between gap-3">
<div className="flex-1">
<p className="font-medium text-white">{option.label}</p>
{option.duration_seconds && (
<p className="text-xs text-slate-400 mt-1">
Duration: {Math.floor(option.duration_seconds / 60)}:
{(option.duration_seconds % 60).toString().padStart(2, '0')}
</p>
)}
</div>
<div className="flex items-center gap-2">
{option.audio_url && (
<Button
size="sm"
variant="ghost"
onClick={() => togglePlayback(option.id, option.audio_url)}
className="text-slate-400 hover:text-white"
>
{playingId === option.id ? (
<Pause className="w-4 h-4" />
) : (
<Play className="w-4 h-4" />
)}
</Button>
)}
<Button
size="sm"
onClick={() => handleSelect(option.id as 'clean' | 'with_backing')}
disabled={isSelecting}
className="bg-pink-600 hover:bg-pink-500 text-white"
>
{isSelecting ? (
<Loader2 className="w-3 h-3 animate-spin" />
) : (
"Select"
)}
</Button>
</div>
</div>
</div>
))}
</div>
)}
</DialogContent>
</Dialog>
)
}
+19 -14
View File
@@ -8,7 +8,6 @@ import { Loader2, ExternalLink, Zap } from "lucide-react"
import { JobActions } from "./JobActions"
import { JobLogs } from "./JobLogs"
import { OutputLinks } from "./OutputLinks"
import { InstrumentalSelector } from "./InstrumentalSelector"
import { AudioSearchDialog } from "../audio-search/AudioSearchDialog"
import { getJobStep, formatStepIndicator, getJobProgressPercent } from "@/lib/job-status"
@@ -78,7 +77,6 @@ interface JobCardProps {
export function JobCard({ job, onRefresh }: JobCardProps) {
const [showLogs, setShowLogs] = useState(false)
const [showAudioSearch, setShowAudioSearch] = useState(false)
const [showInstrumentalSelector, setShowInstrumentalSelector] = useState(false)
const { enabled: autoModeEnabled, isProcessing: isAutoProcessing } = useAutoMode()
const createdAt = new Date(job.created_at).toLocaleString()
@@ -113,6 +111,18 @@ export function JobCard({ job, onRefresh }: JobCardProps) {
return url
}
// Build instrumental review URL for awaiting_instrumental_selection status
const getInstrumentalUrl = () => {
const backendUrl = process.env.NEXT_PUBLIC_API_URL || 'https://api.nomadkaraoke.com'
const baseApiUrl = `${backendUrl}/api/jobs/${job.job_id}`
const encodedApiUrl = encodeURIComponent(baseApiUrl)
let url = `/instrumental/?baseApiUrl=${encodedApiUrl}`
if (job.instrumental_token) {
url += `&instrumentalToken=${encodeURIComponent(job.instrumental_token)}`
}
return url
}
// Render primary action button based on status
const renderPrimaryAction = () => {
if (autoModeEnabled && isInteractive) {
@@ -163,13 +173,15 @@ export function JobCard({ job, onRefresh }: JobCardProps) {
if (job.status === "awaiting_instrumental_selection") {
return (
<Button
size="sm"
onClick={() => setShowInstrumentalSelector(true)}
className="text-xs h-7 px-3 bg-blue-600 hover:bg-blue-500"
<a
href={getInstrumentalUrl()}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 text-xs px-3 py-1.5 rounded bg-blue-600 hover:bg-blue-500 text-white"
>
<ExternalLink className="w-3 h-3" />
Select Instrumental
</Button>
</a>
)
}
@@ -235,13 +247,6 @@ export function JobCard({ job, onRefresh }: JobCardProps) {
onClose={() => setShowAudioSearch(false)}
onSelect={onRefresh}
/>
<InstrumentalSelector
jobId={job.job_id}
open={showInstrumentalSelector}
onClose={() => setShowInstrumentalSelector(false)}
onSelect={onRefresh}
/>
</div>
)
}
+1 -2
View File
@@ -1,6 +1,5 @@
export { JobCard, StatusBadge } from "./JobCard"
export { JobCard } from "./JobCard"
export { JobActions } from "./JobActions"
export { JobLogs } from "./JobLogs"
export { OutputLinks } from "./OutputLinks"
export { InstrumentalSelector } from "./InstrumentalSelector"
+1
View File
@@ -63,6 +63,7 @@ export interface Job {
message?: string;
}>;
review_token?: string;
instrumental_token?: string;
audio_hash?: string;
}
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -1696,7 +1696,7 @@ class RemoteFlacFetchAudioFetcher(AudioFetcher):
import re
self.logger.info(f"[RemoteFlacFetcher] Downloading from URL: {url}")
self.logger.info(f"[RemoteFlacFetcher] Using local flacfetch for YouTube download (no remote API needed)")
self.logger.info("[RemoteFlacFetcher] Using local flacfetch for YouTube download (no remote API needed)")
try:
# Use local flacfetch for YouTube downloads - no need for remote API
@@ -1762,7 +1762,7 @@ class RemoteFlacFetchAudioFetcher(AudioFetcher):
except ImportError as e:
raise DownloadError(
f"flacfetch is required for URL downloads but import failed: {e}"
)
) from e
except Exception as e:
raise DownloadError(f"Failed to download from URL {url}: {e}") from e
+6 -5
View File
@@ -503,7 +503,7 @@ class KaraokePrep:
)
# Update extractor to reflect the source
self.extractor = f"youtube"
self.extractor = "youtube"
else:
# Use flacfetch to search and download audio
self.logger.info(f"Using flacfetch to search and download: {self.artist} - {self.title}")
@@ -796,21 +796,22 @@ class KaraokePrep:
outputs = output_generator.generate_outputs(
transcription_corrected=correction_result,
lyrics_results={}, # Lyrics already written during transcription phase
audio_filepath=audio_path,
output_prefix=output_prefix,
)
# Copy video to expected location in parent directory
if outputs and outputs.get("video_filepath"):
source_video = outputs["video_filepath"]
if outputs and outputs.video:
source_video = outputs.video
dest_video = os.path.join(track_output_dir, f"{artist_title} (With Vocals).mkv")
shutil.copy2(source_video, dest_video)
self.logger.info(f"Video rendered successfully: {dest_video}")
processed_track["with_vocals_video"] = dest_video
# Update ASS filepath for video background processing
if outputs.get("ass_filepath"):
processed_track["ass_filepath"] = outputs["ass_filepath"]
if outputs.ass:
processed_track["ass_filepath"] = outputs.ass
else:
self.logger.warning("Video rendering did not produce expected output")
else:
+25 -6
View File
@@ -170,15 +170,15 @@ class LyricsProcessor:
def _check_transcription_providers(self) -> dict:
"""
Check which transcription providers are configured and return their status.
Returns:
dict with 'configured' (list of provider names) and 'missing' (list of missing configs)
"""
load_dotenv()
configured = []
missing = []
# Check AudioShake
audioshake_token = os.getenv("AUDIOSHAKE_API_TOKEN")
if audioshake_token:
@@ -187,7 +187,7 @@ class LyricsProcessor:
else:
missing.append("AudioShake (AUDIOSHAKE_API_TOKEN)")
self.logger.debug("AudioShake transcription provider: not configured (missing AUDIOSHAKE_API_TOKEN)")
# Check Whisper via RunPod
runpod_key = os.getenv("RUNPOD_API_KEY")
whisper_id = os.getenv("WHISPER_RUNPOD_ID")
@@ -203,7 +203,16 @@ class LyricsProcessor:
else:
missing.append("Whisper (RUNPOD_API_KEY + WHISPER_RUNPOD_ID)")
self.logger.debug("Whisper transcription provider: not configured")
# Check Local Whisper (whisper-timestamped)
try:
import whisper_timestamped
configured.append("Local Whisper")
self.logger.debug("Local Whisper transcription provider: configured (whisper-timestamped installed)")
except ImportError:
missing.append("Local Whisper (pip install karaoke-gen[local-whisper])")
self.logger.debug("Local Whisper transcription provider: not configured (whisper-timestamped not installed)")
return {"configured": configured, "missing": missing}
def _build_transcription_provider_error_message(self, missing_providers: list) -> str:
@@ -221,12 +230,18 @@ class LyricsProcessor:
" - Set environment variable: AUDIOSHAKE_API_TOKEN=your_token\n"
" - Get an API key at: https://www.audioshake.ai/\n"
"\n"
"2. Whisper via RunPod (Open-source alternative)\n"
"2. Whisper via RunPod (Cloud-based open-source)\n"
" - Set environment variables:\n"
" RUNPOD_API_KEY=your_key\n"
" WHISPER_RUNPOD_ID=your_endpoint_id\n"
" - Set up a Whisper endpoint at: https://www.runpod.io/\n"
"\n"
"3. Local Whisper (No cloud required - runs on your machine)\n"
" - Install with: pip install karaoke-gen[local-whisper]\n"
" - For CPU-only: pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu\n"
" pip install karaoke-gen[local-whisper]\n"
" - Requires 2-10GB RAM depending on model size\n"
"\n"
"ALTERNATIVES:\n"
"\n"
"- Use --skip-lyrics flag to generate instrumental-only karaoke (no synchronized lyrics)\n"
@@ -348,6 +363,10 @@ class LyricsProcessor:
# Create config objects for LyricsTranscriber
transcriber_config = TranscriberConfig(
audioshake_api_token=env_config.get("audioshake_api_token"),
runpod_api_key=env_config.get("runpod_api_key"),
whisper_runpod_id=env_config.get("whisper_runpod_id"),
# Local Whisper is enabled by default as a fallback when no cloud providers are configured
enable_local_whisper=True,
)
lyrics_config = LyricsConfig(
@@ -11,6 +11,13 @@ class TranscriberConfig:
runpod_api_key: Optional[str] = None
whisper_runpod_id: Optional[str] = None
# Local Whisper configuration
enable_local_whisper: bool = True # Enabled by default as fallback
local_whisper_model_size: str = "medium" # tiny, base, small, medium, large
local_whisper_device: Optional[str] = None # None for auto-detect, or cpu/cuda/mps
local_whisper_cache_dir: Optional[str] = None # Custom model download location
local_whisper_language: Optional[str] = None # None for auto-detect
@dataclass
class LyricsConfig:
@@ -7,6 +7,7 @@ from lyrics_transcriber.types import LyricsData, TranscriptionResult, Correction
from lyrics_transcriber.transcribers.base_transcriber import BaseTranscriber
from lyrics_transcriber.transcribers.audioshake import AudioShakeTranscriber, AudioShakeConfig
from lyrics_transcriber.transcribers.whisper import WhisperTranscriber, WhisperConfig
from lyrics_transcriber.transcribers.local_whisper import LocalWhisperTranscriber, LocalWhisperConfig
from lyrics_transcriber.lyrics.base_lyrics_provider import BaseLyricsProvider, LyricsProviderConfig
from lyrics_transcriber.lyrics.genius import GeniusProvider
from lyrics_transcriber.lyrics.spotify import SpotifyProvider
@@ -206,6 +207,34 @@ class LyricsTranscriber:
else:
self.logger.debug("Skipping Whisper transcriber - missing runpod_api_key or whisper_runpod_id")
# Local Whisper - lowest priority, fallback when cloud services unavailable
if self.transcriber_config.enable_local_whisper:
# Check if whisper-timestamped is available
try:
import whisper_timestamped # noqa: F401
self.logger.debug("Initializing LocalWhisper transcriber")
transcribers["local_whisper"] = {
"instance": LocalWhisperTranscriber(
cache_dir=self.output_config.cache_dir,
config=LocalWhisperConfig(
model_size=self.transcriber_config.local_whisper_model_size,
device=self.transcriber_config.local_whisper_device,
cache_dir=self.transcriber_config.local_whisper_cache_dir,
language=self.transcriber_config.local_whisper_language,
),
logger=self.logger,
),
"priority": 3, # Local Whisper has lowest priority (fallback)
}
except ImportError:
self.logger.debug(
"Skipping LocalWhisper transcriber - whisper-timestamped not installed. "
"Install with: pip install karaoke-gen[local-whisper]"
)
else:
self.logger.debug("Skipping LocalWhisper transcriber - disabled via enable_local_whisper=False")
return transcribers
def _initialize_lyrics_providers(self) -> Dict[str, BaseLyricsProvider]:
@@ -442,7 +471,7 @@ class LyricsTranscriber:
# Whisper/RunPod status
has_runpod_key = bool(self.transcriber_config.runpod_api_key)
has_whisper_id = bool(self.transcriber_config.whisper_runpod_id)
if has_runpod_key and has_whisper_id:
self.logger.debug(" - Whisper (RunPod): CONFIGURED (API key and endpoint ID provided)")
elif has_runpod_key:
@@ -452,6 +481,19 @@ class LyricsTranscriber:
else:
self.logger.debug(" - Whisper (RunPod): NOT CONFIGURED (missing RUNPOD_API_KEY and WHISPER_RUNPOD_ID)")
# Local Whisper status
if self.transcriber_config.enable_local_whisper:
try:
import whisper_timestamped # noqa: F401
self.logger.debug(
f" - LocalWhisper: AVAILABLE (model={self.transcriber_config.local_whisper_model_size}, "
f"device={self.transcriber_config.local_whisper_device or 'auto'})"
)
except ImportError:
self.logger.debug(" - LocalWhisper: ENABLED but whisper-timestamped not installed")
else:
self.logger.debug(" - LocalWhisper: DISABLED (enable_local_whisper=False)")
def correct_lyrics(self) -> None:
"""Run lyrics correction using transcription and internet lyrics."""
self.logger.info("Starting lyrics correction process")
@@ -52,7 +52,7 @@ class OutputGenerator:
self.logger.info(f"Initializing OutputGenerator with config: {self.config}")
# Load output styles from JSON if provided
# Load output styles from JSON if provided, otherwise use defaults
if self.config.output_styles_json and os.path.exists(self.config.output_styles_json):
try:
with open(self.config.output_styles_json, "r") as f:
@@ -67,9 +67,10 @@ class OutputGenerator:
self.logger.warning(f"Failed to load output styles file: {str(e)}")
self.config.styles = {}
else:
# No styles file provided or doesn't exist
# No styles file provided or doesn't exist - use defaults
if self.config.render_video or self.config.generate_cdg:
raise ValueError(f"Output styles file required for video/CDG generation but not found: {self.config.output_styles_json}")
self.logger.info("No output styles file provided, using default karaoke styles")
self.config.styles = self._get_default_styles()
else:
self.config.styles = {}
@@ -242,6 +243,52 @@ class OutputGenerator:
return resolution_dims, font_size, line_height
def _get_default_styles(self) -> dict:
"""Get default styles for video/CDG generation when no styles file is provided."""
return {
"karaoke": {
# Video background
"background_color": "#000000",
"background_image": None,
# Font settings
"font": "Arial",
"font_path": "", # Must be string, not None (for ASS generator)
"ass_name": "Default",
# Colors in "R, G, B, A" format (required by ASS)
"primary_color": "112, 112, 247, 255",
"secondary_color": "255, 255, 255, 255",
"outline_color": "26, 58, 235, 255",
"back_color": "0, 0, 0, 0",
# Boolean style options
"bold": False,
"italic": False,
"underline": False,
"strike_out": False,
# Numeric style options (all required for ASS)
"scale_x": 100,
"scale_y": 100,
"spacing": 0,
"angle": 0.0,
"border_style": 1,
"outline": 1,
"shadow": 0,
"margin_l": 0,
"margin_r": 0,
"margin_v": 0,
"encoding": 0,
# Layout settings
"max_line_length": 40,
"top_padding": 200,
"font_size": 100,
},
"cdg": {
"font_path": None,
"instrumental_background": None,
"title_screen_background": None,
"outro_background": None,
},
}
def write_corrections_data(self, correction_result: CorrectionResult, output_prefix: str) -> str:
"""Write corrections data to JSON file."""
self.logger.info("Writing corrections data JSON")
@@ -0,0 +1,260 @@
"""Local Whisper transcription service using whisper-timestamped for word-level timestamps."""
from dataclasses import dataclass
import os
import logging
from typing import Optional, Dict, Any, Union
from pathlib import Path
from lyrics_transcriber.types import TranscriptionData, LyricsSegment, Word
from lyrics_transcriber.transcribers.base_transcriber import BaseTranscriber, TranscriptionError
from lyrics_transcriber.utils.word_utils import WordUtils
@dataclass
class LocalWhisperConfig:
"""Configuration for local Whisper transcription service."""
model_size: str = "medium" # tiny, base, small, medium, large, large-v2, large-v3
device: Optional[str] = None # None for auto-detect, or "cpu", "cuda", "mps"
cache_dir: Optional[str] = None # Directory for model downloads (~/.cache/whisper by default)
language: Optional[str] = None # Language code for transcription, None for auto-detect
compute_type: str = "auto" # float16, float32, int8, auto
class LocalWhisperTranscriber(BaseTranscriber):
"""
Transcription service using local Whisper inference via whisper-timestamped.
This transcriber runs Whisper models locally on your machine, supporting
CPU, CUDA GPU, and Apple Silicon MPS acceleration. It uses the
whisper-timestamped library to get accurate word-level timestamps.
Requirements:
pip install karaoke-gen[local-whisper]
Configuration:
Set environment variables to customize behavior:
- WHISPER_MODEL_SIZE: Model size (tiny, base, small, medium, large)
- WHISPER_DEVICE: Device to use (cpu, cuda, mps, or auto)
- WHISPER_CACHE_DIR: Directory for model downloads
- WHISPER_LANGUAGE: Language code (en, es, fr, etc.) or auto-detect
"""
def __init__(
self,
cache_dir: Union[str, Path],
config: Optional[LocalWhisperConfig] = None,
logger: Optional[logging.Logger] = None,
):
"""
Initialize local Whisper transcriber.
Args:
cache_dir: Directory for caching transcription results
config: Configuration options for the transcriber
logger: Logger instance to use
"""
super().__init__(cache_dir=cache_dir, logger=logger)
# Initialize configuration from env vars or defaults
self.config = config or LocalWhisperConfig(
model_size=os.getenv("WHISPER_MODEL_SIZE", "medium"),
device=os.getenv("WHISPER_DEVICE"), # None for auto-detect
cache_dir=os.getenv("WHISPER_CACHE_DIR"),
language=os.getenv("WHISPER_LANGUAGE"), # None for auto-detect
)
# Lazy-loaded model instance (loaded on first use)
self._model = None
self._whisper_module = None
self.logger.debug(
f"LocalWhisperTranscriber initialized with model_size={self.config.model_size}, "
f"device={self.config.device or 'auto'}, language={self.config.language or 'auto-detect'}"
)
def get_name(self) -> str:
"""Return the name of this transcription service."""
return "LocalWhisper"
def _check_dependencies(self) -> None:
"""Check that required dependencies are installed."""
try:
import whisper_timestamped # noqa: F401
except ImportError:
raise TranscriptionError(
"whisper-timestamped is not installed. "
"Install it with: pip install karaoke-gen[local-whisper] "
"or: pip install whisper-timestamped"
)
def _get_device(self) -> str:
"""Determine the best device to use for inference."""
if self.config.device:
return self.config.device
# Auto-detect best available device
try:
import torch
if torch.cuda.is_available():
self.logger.info("Using CUDA GPU for Whisper inference")
return "cuda"
elif hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
self.logger.info("Using Apple Silicon MPS for Whisper inference")
return "cpu" # whisper-timestamped works better with CPU on MPS
else:
self.logger.info("Using CPU for Whisper inference (no GPU detected)")
return "cpu"
except ImportError:
self.logger.warning("PyTorch not available, defaulting to CPU")
return "cpu"
def _load_model(self):
"""Load the Whisper model (lazy loading on first use)."""
if self._model is not None:
return self._model
self._check_dependencies()
import whisper_timestamped as whisper
self._whisper_module = whisper
device = self._get_device()
self.logger.info(f"Loading Whisper model '{self.config.model_size}' on device '{device}'...")
try:
# Load model with optional custom cache directory
download_root = self.config.cache_dir
self._model = whisper.load_model(
self.config.model_size,
device=device,
download_root=download_root,
)
self.logger.info(f"Whisper model '{self.config.model_size}' loaded successfully")
return self._model
except RuntimeError as e:
if "out of memory" in str(e).lower() or "CUDA" in str(e):
raise TranscriptionError(
f"GPU out of memory loading model '{self.config.model_size}'. "
"Try using a smaller model (set WHISPER_MODEL_SIZE=small or tiny) "
"or force CPU mode (set WHISPER_DEVICE=cpu)"
) from e
raise TranscriptionError(f"Failed to load Whisper model: {e}") from e
except Exception as e:
raise TranscriptionError(f"Failed to load Whisper model: {e}") from e
def _perform_transcription(self, audio_filepath: str) -> Dict[str, Any]:
"""
Perform local Whisper transcription with word-level timestamps.
Args:
audio_filepath: Path to the audio file to transcribe
Returns:
Raw transcription result dictionary
"""
self.logger.info(f"Starting local Whisper transcription for {audio_filepath}")
# Load model if not already loaded
model = self._load_model()
try:
# Perform transcription with word-level timestamps
transcribe_kwargs = {
"verbose": False,
}
# Add language if specified
if self.config.language:
transcribe_kwargs["language"] = self.config.language
self.logger.debug(f"Transcribing with options: {transcribe_kwargs}")
result = self._whisper_module.transcribe_timestamped(
model,
audio_filepath,
**transcribe_kwargs,
)
self.logger.info("Local Whisper transcription completed successfully")
return result
except RuntimeError as e:
if "out of memory" in str(e).lower():
raise TranscriptionError(
f"GPU out of memory during transcription. "
"Try using a smaller model (WHISPER_MODEL_SIZE=small) "
"or force CPU mode (WHISPER_DEVICE=cpu)"
) from e
raise TranscriptionError(f"Transcription failed: {e}") from e
except Exception as e:
raise TranscriptionError(f"Transcription failed: {e}") from e
def _convert_result_format(self, raw_data: Dict[str, Any]) -> TranscriptionData:
"""
Convert whisper-timestamped output to standard TranscriptionData format.
The whisper-timestamped library returns results in this format:
{
"text": "Full transcription text",
"segments": [
{
"id": 0,
"text": "Segment text",
"start": 0.0,
"end": 2.5,
"words": [
{"text": "word", "start": 0.0, "end": 0.5, "confidence": 0.95},
...
]
},
...
],
"language": "en"
}
Args:
raw_data: Raw output from whisper_timestamped.transcribe_timestamped()
Returns:
TranscriptionData with segments, words, and metadata
"""
segments = []
all_words = []
for seg in raw_data.get("segments", []):
segment_words = []
for word_data in seg.get("words", []):
word = Word(
id=WordUtils.generate_id(),
text=word_data.get("text", "").strip(),
start_time=word_data.get("start", 0.0),
end_time=word_data.get("end", 0.0),
confidence=word_data.get("confidence"),
)
segment_words.append(word)
all_words.append(word)
# Create segment with its words
segment = LyricsSegment(
id=WordUtils.generate_id(),
text=seg.get("text", "").strip(),
words=segment_words,
start_time=seg.get("start", 0.0),
end_time=seg.get("end", 0.0),
)
segments.append(segment)
return TranscriptionData(
segments=segments,
words=all_words,
text=raw_data.get("text", "").strip(),
source=self.get_name(),
metadata={
"model_size": self.config.model_size,
"detected_language": raw_data.get("language", "unknown"),
"device": self._get_device(),
},
)
@@ -82,8 +82,8 @@ class TestOutputGenerator:
assert generator.font_size == 40
assert generator.line_height == 50
def test_initialization_missing_styles_file(self, tmp_path):
"""Test OutputGenerator initialization with missing styles file."""
def test_initialization_missing_styles_file_uses_defaults(self, tmp_path):
"""Test OutputGenerator uses default styles when styles file is missing."""
config = OutputConfig(
output_styles_json=str(tmp_path / "nonexistent.json"),
output_dir=str(tmp_path / "output"),
@@ -91,9 +91,33 @@ class TestOutputGenerator:
default_max_line_length=36,
render_video=True
)
with pytest.raises(ValueError, match="Output styles file required for video/CDG generation but not found"):
OutputGenerator(config=config)
# Should initialize successfully with default styles
generator = OutputGenerator(config=config)
# Verify default styles are loaded
assert "karaoke" in generator.config.styles
assert "cdg" in generator.config.styles
assert generator.config.styles["karaoke"]["font"] == "Arial"
assert generator.config.styles["karaoke"]["primary_color"] == "112, 112, 247, 255"
assert generator.config.styles["karaoke"]["max_line_length"] == 40
def test_initialization_no_styles_path_uses_defaults(self, tmp_path):
"""Test OutputGenerator uses default styles when styles path is None."""
config = OutputConfig(
output_styles_json=None,
output_dir=str(tmp_path / "output"),
cache_dir=str(tmp_path / "cache"),
default_max_line_length=36,
render_video=True
)
# Should initialize successfully with default styles
generator = OutputGenerator(config=config)
# Verify default styles are loaded
assert "karaoke" in generator.config.styles
assert generator.config.styles["karaoke"]["background_color"] == "#000000"
def test_initialization_invalid_styles_file(self, tmp_path):
"""Test OutputGenerator initialization with invalid JSON in styles file."""
@@ -0,0 +1,540 @@
"""Tests for LocalWhisperTranscriber."""
import pytest
import logging
import os
import shutil
import tempfile
from unittest.mock import Mock, patch, MagicMock
from lyrics_transcriber.types import TranscriptionData
from lyrics_transcriber.transcribers.local_whisper import (
LocalWhisperTranscriber,
LocalWhisperConfig,
)
from lyrics_transcriber.transcribers.base_transcriber import TranscriptionError
from tests.test_helpers import create_test_word, create_test_segment
@pytest.fixture
def mock_logger():
return Mock(spec=logging.Logger)
@pytest.fixture
def test_cache_dir():
"""Create and cleanup a test cache directory."""
cache_dir = tempfile.mkdtemp(prefix="test_local_whisper_cache_")
yield cache_dir
if os.path.exists(cache_dir):
shutil.rmtree(cache_dir)
@pytest.fixture
def default_config():
"""Create a default LocalWhisperConfig for testing."""
return LocalWhisperConfig(
model_size="medium",
device="cpu",
cache_dir=None,
language=None,
)
@pytest.fixture
def mock_whisper_output():
"""Sample output from whisper-timestamped."""
return {
"text": "Hello world, this is a test.",
"segments": [
{
"id": 0,
"text": "Hello world,",
"start": 0.0,
"end": 1.5,
"words": [
{"text": "Hello", "start": 0.0, "end": 0.5, "confidence": 0.95},
{"text": "world,", "start": 0.6, "end": 1.5, "confidence": 0.92},
],
},
{
"id": 1,
"text": "this is a test.",
"start": 1.6,
"end": 3.0,
"words": [
{"text": "this", "start": 1.6, "end": 1.8, "confidence": 0.98},
{"text": "is", "start": 1.9, "end": 2.0, "confidence": 0.97},
{"text": "a", "start": 2.1, "end": 2.2, "confidence": 0.99},
{"text": "test.", "start": 2.3, "end": 3.0, "confidence": 0.96},
],
},
],
"language": "en",
}
class TestLocalWhisperConfig:
"""Tests for LocalWhisperConfig dataclass."""
def test_default_values(self):
"""Test that default values are set correctly."""
config = LocalWhisperConfig()
assert config.model_size == "medium"
assert config.device is None
assert config.cache_dir is None
assert config.language is None
def test_custom_values(self):
"""Test that custom values can be set."""
config = LocalWhisperConfig(
model_size="large",
device="cuda",
cache_dir="/custom/cache",
language="en",
)
assert config.model_size == "large"
assert config.device == "cuda"
assert config.cache_dir == "/custom/cache"
assert config.language == "en"
class TestLocalWhisperTranscriber:
"""Tests for LocalWhisperTranscriber class."""
def test_init_with_config(self, mock_logger, test_cache_dir, default_config):
"""Test initialization with explicit config."""
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=default_config,
logger=mock_logger,
)
assert transcriber.config == default_config
assert transcriber.logger == mock_logger
assert str(transcriber.cache_dir) == test_cache_dir
def test_init_without_config(self, mock_logger, test_cache_dir):
"""Test initialization without config uses environment variables."""
with patch.dict(
os.environ,
{
"WHISPER_MODEL_SIZE": "small",
"WHISPER_DEVICE": "cpu",
},
clear=False,
):
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
logger=mock_logger,
)
assert transcriber.config.model_size == "small"
assert transcriber.config.device == "cpu"
def test_get_name(self, mock_logger, test_cache_dir, default_config):
"""Test that get_name returns correct name."""
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=default_config,
logger=mock_logger,
)
assert transcriber.get_name() == "LocalWhisper"
def test_check_dependencies_not_installed(self, mock_logger, test_cache_dir, default_config):
"""Test that missing dependencies raise TranscriptionError."""
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=default_config,
logger=mock_logger,
)
# Mock import to fail
with patch.dict("sys.modules", {"whisper_timestamped": None}):
with pytest.raises(TranscriptionError, match="whisper-timestamped is not installed"):
transcriber._check_dependencies()
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._check_dependencies")
def test_get_device_explicit(self, mock_check, mock_logger, test_cache_dir):
"""Test device selection when explicitly set."""
config = LocalWhisperConfig(device="cuda")
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=config,
logger=mock_logger,
)
assert transcriber._get_device() == "cuda"
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._check_dependencies")
def test_get_device_auto_detect_cpu(self, mock_check, mock_logger, test_cache_dir, default_config):
"""Test auto-detection falls back to CPU."""
# Mock torch to simulate no GPU available
mock_torch = MagicMock()
mock_torch.cuda.is_available.return_value = False
mock_torch.backends.mps.is_available.return_value = False
with patch.dict("sys.modules", {"torch": mock_torch}):
config = LocalWhisperConfig(device=None) # Auto-detect
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=config,
logger=mock_logger,
)
device = transcriber._get_device()
assert device == "cpu"
class TestLocalWhisperTranscriberConversion:
"""Tests for result format conversion."""
@pytest.fixture
def transcriber(self, mock_logger, test_cache_dir, default_config):
"""Create transcriber instance for conversion tests."""
return LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=default_config,
logger=mock_logger,
)
def test_convert_result_format_basic(self, transcriber, mock_whisper_output):
"""Test basic conversion of whisper output."""
result = transcriber._convert_result_format(mock_whisper_output)
assert isinstance(result, TranscriptionData)
assert result.text == "Hello world, this is a test."
assert result.source == "LocalWhisper"
assert len(result.segments) == 2
assert len(result.words) == 6 # 2 + 4 words
def test_convert_result_format_segments(self, transcriber, mock_whisper_output):
"""Test that segments are correctly converted."""
result = transcriber._convert_result_format(mock_whisper_output)
# Check first segment
seg1 = result.segments[0]
assert seg1.text == "Hello world,"
assert seg1.start_time == 0.0
assert seg1.end_time == 1.5
assert len(seg1.words) == 2
# Check second segment
seg2 = result.segments[1]
assert seg2.text == "this is a test."
assert seg2.start_time == 1.6
assert seg2.end_time == 3.0
assert len(seg2.words) == 4
def test_convert_result_format_words(self, transcriber, mock_whisper_output):
"""Test that words are correctly converted with IDs."""
result = transcriber._convert_result_format(mock_whisper_output)
# Check first word
word1 = result.words[0]
assert word1.text == "Hello"
assert word1.start_time == 0.0
assert word1.end_time == 0.5
assert word1.confidence == 0.95
assert word1.id is not None # Should have generated ID
# Check that all words have unique IDs
word_ids = [w.id for w in result.words]
assert len(word_ids) == len(set(word_ids)) # All unique
def test_convert_result_format_metadata(self, transcriber, mock_whisper_output):
"""Test that metadata is correctly set."""
result = transcriber._convert_result_format(mock_whisper_output)
assert result.metadata["model_size"] == "medium"
assert result.metadata["detected_language"] == "en"
assert result.metadata["device"] == "cpu"
def test_convert_result_format_empty_segments(self, transcriber):
"""Test conversion with empty segments."""
empty_output = {
"text": "",
"segments": [],
"language": "en",
}
result = transcriber._convert_result_format(empty_output)
assert result.text == ""
assert len(result.segments) == 0
assert len(result.words) == 0
def test_convert_result_format_missing_confidence(self, transcriber):
"""Test conversion when words are missing confidence scores."""
output_no_confidence = {
"text": "Hello world",
"segments": [
{
"id": 0,
"text": "Hello world",
"start": 0.0,
"end": 1.0,
"words": [
{"text": "Hello", "start": 0.0, "end": 0.4},
{"text": "world", "start": 0.5, "end": 1.0},
],
}
],
"language": "en",
}
result = transcriber._convert_result_format(output_no_confidence)
# Words should have None confidence
assert result.words[0].confidence is None
assert result.words[1].confidence is None
def test_convert_result_format_special_characters(self, transcriber):
"""Test conversion with special characters in lyrics."""
output_special = {
"text": "Don't stop believin'!",
"segments": [
{
"id": 0,
"text": "Don't stop believin'!",
"start": 0.0,
"end": 2.0,
"words": [
{"text": "Don't", "start": 0.0, "end": 0.5, "confidence": 0.9},
{"text": "stop", "start": 0.6, "end": 1.0, "confidence": 0.95},
{"text": "believin'!", "start": 1.1, "end": 2.0, "confidence": 0.88},
],
}
],
"language": "en",
}
result = transcriber._convert_result_format(output_special)
assert result.text == "Don't stop believin'!"
assert result.words[0].text == "Don't"
assert result.words[2].text == "believin'!"
class TestLocalWhisperTranscriberTranscription:
"""Tests for actual transcription functionality."""
@pytest.fixture
def transcriber(self, mock_logger, test_cache_dir, default_config):
"""Create transcriber instance."""
return LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=default_config,
logger=mock_logger,
)
@pytest.fixture
def test_audio_file(self, test_cache_dir):
"""Create a dummy audio file for testing."""
audio_path = os.path.join(test_cache_dir, "test_audio.wav")
with open(audio_path, "wb") as f:
f.write(b"dummy audio content")
return audio_path
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._load_model")
def test_perform_transcription_calls_model(
self, mock_load_model, transcriber, test_audio_file, mock_whisper_output
):
"""Test that _perform_transcription calls the model correctly."""
# Setup mock
mock_model = MagicMock()
mock_load_model.return_value = mock_model
mock_whisper = MagicMock()
mock_whisper.transcribe_timestamped.return_value = mock_whisper_output
transcriber._whisper_module = mock_whisper
# Call transcription
result = transcriber._perform_transcription(test_audio_file)
# Verify model was loaded and transcription was called
mock_load_model.assert_called_once()
mock_whisper.transcribe_timestamped.assert_called_once()
# Verify the audio file path was passed
call_args = mock_whisper.transcribe_timestamped.call_args
assert call_args[0][1] == test_audio_file
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._load_model")
def test_perform_transcription_with_language(
self, mock_load_model, mock_logger, test_cache_dir, test_audio_file, mock_whisper_output
):
"""Test transcription with specified language."""
config = LocalWhisperConfig(language="en")
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=config,
logger=mock_logger,
)
mock_model = MagicMock()
mock_load_model.return_value = mock_model
mock_whisper = MagicMock()
mock_whisper.transcribe_timestamped.return_value = mock_whisper_output
transcriber._whisper_module = mock_whisper
transcriber._perform_transcription(test_audio_file)
# Verify language was passed
call_kwargs = mock_whisper.transcribe_timestamped.call_args[1]
assert call_kwargs["language"] == "en"
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._load_model")
def test_perform_transcription_oom_error(
self, mock_load_model, transcriber, test_audio_file
):
"""Test that OOM errors are handled gracefully."""
mock_model = MagicMock()
mock_load_model.return_value = mock_model
mock_whisper = MagicMock()
mock_whisper.transcribe_timestamped.side_effect = RuntimeError("CUDA out of memory")
transcriber._whisper_module = mock_whisper
with pytest.raises(TranscriptionError, match="out of memory"):
transcriber._perform_transcription(test_audio_file)
class TestLocalWhisperTranscriberModelLoading:
"""Tests for model loading functionality."""
@pytest.fixture
def transcriber(self, mock_logger, test_cache_dir, default_config):
"""Create transcriber instance."""
return LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=default_config,
logger=mock_logger,
)
def test_lazy_model_loading(self, transcriber):
"""Test that model is not loaded until first use."""
assert transcriber._model is None
assert transcriber._whisper_module is None
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._check_dependencies")
def test_model_caching(self, mock_check, transcriber):
"""Test that model is cached after first load."""
mock_whisper = MagicMock()
mock_model = MagicMock()
mock_whisper.load_model.return_value = mock_model
with patch.dict("sys.modules", {"whisper_timestamped": mock_whisper}):
# First load
model1 = transcriber._load_model()
# Second load should return cached model
model2 = transcriber._load_model()
assert model1 is model2
# load_model should only be called once
mock_whisper.load_model.assert_called_once()
@patch("lyrics_transcriber.transcribers.local_whisper.LocalWhisperTranscriber._check_dependencies")
def test_load_model_with_custom_cache_dir(self, mock_check, mock_logger, test_cache_dir):
"""Test model loading with custom cache directory."""
custom_cache = "/custom/whisper/cache"
config = LocalWhisperConfig(cache_dir=custom_cache)
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=config,
logger=mock_logger,
)
mock_whisper = MagicMock()
mock_model = MagicMock()
mock_whisper.load_model.return_value = mock_model
with patch.dict("sys.modules", {"whisper_timestamped": mock_whisper}):
transcriber._load_model()
# Verify custom cache dir was passed
call_kwargs = mock_whisper.load_model.call_args[1]
assert call_kwargs["download_root"] == custom_cache
class TestLocalWhisperTranscriberIntegration:
"""Integration tests for full transcription flow."""
@pytest.fixture(autouse=True)
def setup_teardown(self):
"""Clean up test environment."""
test_cache_dir = tempfile.mkdtemp(prefix="test_local_whisper_integration_")
os.environ["LYRICS_TRANSCRIBER_CACHE_DIR"] = test_cache_dir
yield test_cache_dir
if os.path.exists(test_cache_dir):
shutil.rmtree(test_cache_dir)
if "LYRICS_TRANSCRIBER_CACHE_DIR" in os.environ:
del os.environ["LYRICS_TRANSCRIBER_CACHE_DIR"]
def test_full_transcription_flow(self, setup_teardown, mock_logger, mock_whisper_output):
"""Test complete transcription flow from audio to TranscriptionData."""
test_cache_dir = setup_teardown
# Create test audio file
audio_path = os.path.join(test_cache_dir, "test.wav")
with open(audio_path, "wb") as f:
f.write(b"dummy audio content for testing")
config = LocalWhisperConfig(model_size="tiny", device="cpu")
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=config,
logger=mock_logger,
)
# Mock the model and transcription
mock_whisper = MagicMock()
mock_model = MagicMock()
mock_whisper.load_model.return_value = mock_model
mock_whisper.transcribe_timestamped.return_value = mock_whisper_output
with patch.dict("sys.modules", {"whisper_timestamped": mock_whisper}):
# Bypass dependency check
with patch.object(transcriber, "_check_dependencies"):
result = transcriber.transcribe(audio_path)
# Verify result
assert isinstance(result, TranscriptionData)
assert result.source == "LocalWhisper"
assert len(result.segments) == 2
assert len(result.words) == 6
# Verify caching
file_hash = transcriber._get_file_hash(audio_path)
raw_cache_path = transcriber._get_cache_path(file_hash, "raw")
converted_cache_path = transcriber._get_cache_path(file_hash, "converted")
assert os.path.exists(raw_cache_path)
assert os.path.exists(converted_cache_path)
def test_transcription_uses_cache(self, setup_teardown, mock_logger, mock_whisper_output):
"""Test that subsequent transcriptions use cache."""
test_cache_dir = setup_teardown
audio_path = os.path.join(test_cache_dir, "test.wav")
with open(audio_path, "wb") as f:
f.write(b"dummy audio content for testing")
config = LocalWhisperConfig(model_size="tiny", device="cpu")
transcriber = LocalWhisperTranscriber(
cache_dir=test_cache_dir,
config=config,
logger=mock_logger,
)
mock_whisper = MagicMock()
mock_model = MagicMock()
mock_whisper.load_model.return_value = mock_model
mock_whisper.transcribe_timestamped.return_value = mock_whisper_output
with patch.dict("sys.modules", {"whisper_timestamped": mock_whisper}):
with patch.object(transcriber, "_check_dependencies"):
# First transcription
result1 = transcriber.transcribe(audio_path)
# Second transcription should use cache
result2 = transcriber.transcribe(audio_path)
# Both results should match
assert result1.text == result2.text
assert len(result1.segments) == len(result2.segments)
# transcribe_timestamped should only be called once
mock_whisper.transcribe_timestamped.assert_called_once()
Generated
+105 -6
View File
@@ -1632,6 +1632,53 @@ requests = ">=2.16.2"
six = ">=1.12.0"
stone = ">=2,<3.3.3"
[[package]]
name = "dtw-python"
version = "1.7.2"
description = "A comprehensive implementation of dynamic time warping (DTW) algorithms."
optional = true
python-versions = ">=3.9"
groups = ["main"]
markers = "extra == \"local-whisper\""
files = [
{file = "dtw_python-1.7.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:ae97d9d1a34bf1267b5742800eebc83655d6edac7ef11eaa1da614fe15ecbf15"},
{file = "dtw_python-1.7.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:48de94c12f57bf524f70f4debdf46e4895c43e24abc71fa14f15dec8ecdce7a0"},
{file = "dtw_python-1.7.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4ca9ed4abdcc3a74e46d5cc8a08f892e28d1151969914839ac60ac5ff030dbfc"},
{file = "dtw_python-1.7.2-cp310-cp310-win_amd64.whl", hash = "sha256:8071c345f1dde18830d520690bb4a95dcaa50ea0bd4d260fc4368d592f1b214f"},
{file = "dtw_python-1.7.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:e5bbf17129365ee88aea98890332bb7d20e80fa78eb9c64a11175f07e4c699b3"},
{file = "dtw_python-1.7.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:0f1f075f90bc1faacfa0661cd29f070516b09ce1fc90ea353313aae8c19f5c2e"},
{file = "dtw_python-1.7.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d81ddd8e03befc4041cdf66d569c0f8ba730fd7aebede0d38add7862a10f9779"},
{file = "dtw_python-1.7.2-cp311-cp311-win_amd64.whl", hash = "sha256:e5aecfee9abc5cb39f94ebb25bc74683575dda507836ab0563badfa0fbb11b2b"},
{file = "dtw_python-1.7.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:85ff43afd6adb64a25755f01e98ee21eb70a34c105231720e5f4104b5988741a"},
{file = "dtw_python-1.7.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c507179cae0f38bc22b22fd63c53d99274e11aa2e3a65e6148108345da9df033"},
{file = "dtw_python-1.7.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:239cb6207f512dbd1b0a5da03269ec3ddb2dc177719fe9b6eb5149feeec1bd63"},
{file = "dtw_python-1.7.2-cp312-cp312-win_amd64.whl", hash = "sha256:3126abd69b18a2a4809790d71f5f42fcc2cb483921e17da8f11bac5ddd7d548d"},
{file = "dtw_python-1.7.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:7d36341701b6a049b9dc3b234fe80047c4cd7df438bb86c6236179f2ce79dcf6"},
{file = "dtw_python-1.7.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:129d860f875ded4c4e119450315eff27bcf4d7e6dee8831fd91e68c0e757219c"},
{file = "dtw_python-1.7.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1b0cf947bc5e71f4d7ad139deaa51ad02bba5458e28e5df92b94a90374f5067e"},
{file = "dtw_python-1.7.2-cp313-cp313-win_amd64.whl", hash = "sha256:61e5e4abaa7fd58ef3d63b064fa394770c095a3bbad991339b1fb934928cbc1b"},
{file = "dtw_python-1.7.2-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:1bcc6ace984ed893d688cd8b8a0676bf76f0f01647265d2a017c9f7d3bfcc71a"},
{file = "dtw_python-1.7.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c77633dc1d8d9d0276aed0a782b508b415aab04ddc79bfc2c1abe647a8ccc151"},
{file = "dtw_python-1.7.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:217811332fc3b4e53290942abe45f11ae65a9ca91c77c475d38daa6b73e4d47f"},
{file = "dtw_python-1.7.2-cp314-cp314-win_amd64.whl", hash = "sha256:d7e6675e4b6179b80f8a9c1cd8db60d92f59019e8ea1f344f6b1c8c61142ed45"},
{file = "dtw_python-1.7.2-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:4d4395a97d20b84c665adef5873d3841f658885568c289d46a649484d994a6b6"},
{file = "dtw_python-1.7.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:e7ce66f2c72c28c657e03ba799d7a00a538ced00870b9801debeab2bf4168792"},
{file = "dtw_python-1.7.2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f19ef9ad1ea09f373db003a191f5615c772039ff261b98e33aab186e62e13e1e"},
{file = "dtw_python-1.7.2-cp314-cp314t-win_amd64.whl", hash = "sha256:fcd8f8f484eb100362e2fe65ca27cb8b431964fceb33c64d97c4a841b5abaef8"},
{file = "dtw_python-1.7.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d403cd4d72db13576fe318aacc792adaa895658465c28f5a92b66e845577c1e1"},
{file = "dtw_python-1.7.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:33ce34017855fecee57ef08ed03b858f6f520bee4eef744b171938ac0e5262b6"},
{file = "dtw_python-1.7.2-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3d4438d9ba63355492d7c8ffd7455d0335dfb95f7e2ab50a7dc0ffe013d89b45"},
{file = "dtw_python-1.7.2-cp39-cp39-win_amd64.whl", hash = "sha256:97d243009705603c45c073f84abbb1d02a3fda2c9b18afabb92d012cba058509"},
{file = "dtw_python-1.7.2.tar.gz", hash = "sha256:ad832a96067c9ddc104307abcc7ed3787fc627b71aa48dd2a6a7cf208dbec020"},
]
[package.dependencies]
numpy = ">=2.0"
scipy = "*"
[package.extras]
test = ["numpy"]
[[package]]
name = "dulwich"
version = "0.24.10"
@@ -1873,14 +1920,14 @@ platformdirs = ">=4.3.6"
[[package]]
name = "flacfetch"
version = "0.15.0"
version = "0.15.1"
description = "Search and download high-quality audio from multiple sources"
optional = false
python-versions = ">=3.8"
groups = ["main"]
files = [
{file = "flacfetch-0.15.0-py3-none-any.whl", hash = "sha256:fa2eb155dd92113d37952fe0df5587ce472c85d5c924574342955c0968e802a1"},
{file = "flacfetch-0.15.0.tar.gz", hash = "sha256:ff7ce633d89fae69c7c221a8244afdf56598bfbe2b1ae71e6584df424b9ca995"},
{file = "flacfetch-0.15.1-py3-none-any.whl", hash = "sha256:d50beda83866a8d5567e50e6a2f714379a3c48fae23ccbe5f8153403a5979f09"},
{file = "flacfetch-0.15.1.tar.gz", hash = "sha256:d0953931e63d858d71f5e9ece61a82886b8104c2b30be0bdf7b53c97290e6610"},
]
[package.dependencies]
@@ -4185,11 +4232,12 @@ version = "10.8.0"
description = "More routines for operating on iterables, beyond itertools"
optional = false
python-versions = ">=3.9"
groups = ["dev"]
groups = ["main", "dev"]
files = [
{file = "more_itertools-10.8.0-py3-none-any.whl", hash = "sha256:52d4362373dcf7c52546bc4af9a86ee7c4579df9a8dc268be0a2f949d376cc9b"},
{file = "more_itertools-10.8.0.tar.gz", hash = "sha256:f638ddf8a1a0d134181275fb5d58b086ead7c6a72429ad725c67503f13ba30bd"},
]
markers = {main = "extra == \"local-whisper\""}
[[package]]
name = "mpmath"
@@ -5101,6 +5149,30 @@ datalib = ["numpy (>=1)", "pandas (>=1.2.3)", "pandas-stubs (>=1.1.0.11)"]
realtime = ["websockets (>=13,<16)"]
voice-helpers = ["numpy (>=2.0.2)", "sounddevice (>=0.5.1)"]
[[package]]
name = "openai-whisper"
version = "20250625"
description = "Robust Speech Recognition via Large-Scale Weak Supervision"
optional = true
python-versions = ">=3.8"
groups = ["main"]
markers = "extra == \"local-whisper\""
files = [
{file = "openai_whisper-20250625.tar.gz", hash = "sha256:37a91a3921809d9f44748ffc73c0a55c9f366c85a3ef5c2ae0cc09540432eb96"},
]
[package.dependencies]
more-itertools = "*"
numba = "*"
numpy = "*"
tiktoken = "*"
torch = "*"
tqdm = "*"
triton = {version = ">=2", markers = "platform_machine == \"x86_64\" and sys_platform == \"linux\" or sys_platform == \"linux2\""}
[package.extras]
dev = ["black", "flake8", "isort", "pytest", "scipy"]
[[package]]
name = "opentelemetry-api"
version = "1.39.1"
@@ -8559,7 +8631,7 @@ description = "A language and compiler for custom Deep Learning operations"
optional = false
python-versions = "<3.15,>=3.10"
groups = ["main"]
markers = "platform_system == \"Linux\" and platform_machine == \"x86_64\""
markers = "(platform_machine == \"x86_64\" or sys_platform == \"linux2\") and (platform_system == \"Linux\" or sys_platform == \"linux\" or sys_platform == \"linux2\") and (platform_system == \"Linux\" or extra == \"local-whisper\") and (platform_machine == \"x86_64\" or extra == \"local-whisper\")"
files = [
{file = "triton-3.5.1-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f63e34dcb32d7bd3a1d0195f60f30d2aee8b08a69a0424189b71017e23dfc3d2"},
{file = "triton-3.5.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5fc53d849f879911ea13f4a877243afc513187bc7ee92d1f2c0f1ba3169e3c94"},
@@ -9087,6 +9159,30 @@ files = [
{file = "websockets-15.0.1.tar.gz", hash = "sha256:82544de02076bafba038ce055ee6412d68da13ab47f0c60cab827346de828dee"},
]
[[package]]
name = "whisper-timestamped"
version = "1.15.9"
description = "Multi-lingual Automatic Speech Recognition (ASR) based on Whisper models, with accurate word timestamps, access to language detection confidence, several options for Voice Activity Detection (VAD), and more."
optional = true
python-versions = ">=3.7"
groups = ["main"]
markers = "extra == \"local-whisper\""
files = [
{file = "whisper_timestamped-1.15.9-py3-none-any.whl", hash = "sha256:7582e0cc45dfda78af3a35874485145c20cecb8cc4bfc4599ebb5eeb9fd2ffc2"},
{file = "whisper_timestamped-1.15.9.tar.gz", hash = "sha256:f3609d446ead6d8e0fc82021311b087efd8ef63b7fa255fa1b3a58a32b760a1e"},
]
[package.dependencies]
Cython = "*"
dtw-python = "*"
openai-whisper = "*"
[package.extras]
dev = ["matplotlib (==3.7.4)", "transformers"]
test = ["jsonschema"]
vad-auditok = ["auditok"]
vad-silero = ["onnxruntime", "torchaudio"]
[[package]]
name = "win-unicode-console"
version = "0.5"
@@ -9586,7 +9682,10 @@ files = [
[package.extras]
cffi = ["cffi (>=1.17,<2.0) ; platform_python_implementation != \"PyPy\" and python_version < \"3.14\"", "cffi (>=2.0.0b) ; platform_python_implementation != \"PyPy\" and python_version >= \"3.14\""]
[extras]
local-whisper = ["whisper-timestamped"]
[metadata]
lock-version = "2.1"
python-versions = ">=3.10,<3.14"
content-hash = "8639a26faea41348894a9f6491a95fa1a4a222e206f9d0afafd299ffc41cf5e1"
content-hash = "c14214372c6d52a86d32afc8638b2f1486aac7b4d06a444e8be7d14379bd4e25"
+10 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.76.17"
version = "0.76.24"
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"
@@ -101,6 +101,8 @@ opentelemetry-instrumentation-httpx = ">=0.41b0"
opentelemetry-instrumentation-logging = ">=0.41b0"
opentelemetry-exporter-gcp-trace = ">=1.6.0"
opentelemetry-resourcedetector-gcp = ">=1.6.0a0"
# Optional: Local Whisper transcription (install with: pip install karaoke-gen[local-whisper])
whisper-timestamped = { version = ">=1.15.0", optional = true }
[tool.poetry.group.dev.dependencies]
black = ">=23"
@@ -110,6 +112,13 @@ pytest-cov = ">=4.0"
pytest-mock = ">=3.10"
pytest-asyncio = "*"
[tool.poetry.extras]
# Local Whisper transcription support - optional, heavy dependencies
# Install with: pip install karaoke-gen[local-whisper]
# For CPU-only installation (recommended for systems without GPU):
# pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
# pip install karaoke-gen[local-whisper]
local-whisper = ["whisper-timestamped"]
[tool.poetry.scripts]
karaoke-gen = 'karaoke_gen.utils.gen_cli:main'
+9 -4
View File
@@ -568,7 +568,7 @@ class TestAsync:
basic_karaoke_gen.title = None # Missing title
# Test that ValueError is raised
with pytest.raises(ValueError, match="Either a local file path.*or both artist and title must be provided"):
with pytest.raises(ValueError, match=r"Either a local file path.*or both artist and title must be provided"):
await basic_karaoke_gen.process()
@pytest.mark.asyncio
@@ -610,7 +610,10 @@ class TestAsync:
with patch.object(basic_karaoke_gen, 'prep_single_track', new_callable=AsyncMock) as mock_prep_single_track:
mock_prep_single_track.return_value = {"track": "result"}
result = await basic_karaoke_gen.process()
await basic_karaoke_gen.process()
# Verify prep_single_track was called
mock_prep_single_track.assert_called_once()
# Verify URL mode was enabled
assert basic_karaoke_gen._use_audio_fetcher is True
@@ -631,7 +634,10 @@ class TestAsync:
with patch.object(basic_karaoke_gen, 'prep_single_track', new_callable=AsyncMock) as mock_prep_single_track:
mock_prep_single_track.return_value = {"track": "result"}
result = await basic_karaoke_gen.process()
await basic_karaoke_gen.process()
# Verify prep_single_track was called
mock_prep_single_track.assert_called_once()
# Verify URL mode was enabled
assert basic_karaoke_gen._use_audio_fetcher is True
@@ -645,7 +651,6 @@ class TestKaraokePrepIsUrlHelper:
@pytest.fixture
def karaoke_prep(self, tmp_path):
"""Create a KaraokePrep instance for testing."""
from karaoke_gen.karaoke_gen import KaraokePrep
return KaraokePrep(
artist="Test",
title="Test",
+6 -6
View File
@@ -2452,7 +2452,7 @@ class TestFlacFetchAudioFetcherDownloadFromUrl:
mock_manager.download_by_id.return_value = downloaded_path
mock_get_manager.return_value = mock_manager
result = fetcher.download_from_url(
fetcher.download_from_url(
url="https://www.youtube.com/embed/dQw4w9WgXcQ",
output_dir=str(tmp_path),
)
@@ -2468,7 +2468,7 @@ class TestFlacFetchAudioFetcherDownloadFromUrl:
mock_manager.download_by_id.return_value = downloaded_path
mock_get_manager.return_value = mock_manager
result = fetcher.download_from_url(
fetcher.download_from_url(
url="https://www.youtube.com/watch?v=test123test",
output_dir=str(tmp_path),
artist="Test Artist",
@@ -2486,7 +2486,7 @@ class TestFlacFetchAudioFetcherDownloadFromUrl:
mock_manager.download_by_id.return_value = downloaded_path
mock_get_manager.return_value = mock_manager
result = fetcher.download_from_url(
fetcher.download_from_url(
url="https://www.youtube.com/watch?v=dQw4w9WgXcQ",
output_dir=str(tmp_path),
)
@@ -2563,7 +2563,7 @@ class TestRemoteFlacFetchAudioFetcherDownloadFromUrl:
@patch('flacfetch.providers.youtube.YoutubeProvider')
@patch('flacfetch.downloaders.youtube.YoutubeDownloader')
def test_download_from_url_uses_local_flacfetch(
self, mock_yt_downloader, mock_yt_provider, mock_fetch_manager, fetcher, tmp_path
self, mock_yt_downloader, _mock_yt_provider, mock_fetch_manager, fetcher, tmp_path
):
"""Test that download_from_url uses local flacfetch (not remote API)."""
mock_manager_instance = MagicMock()
@@ -2593,7 +2593,7 @@ class TestRemoteFlacFetchAudioFetcherDownloadFromUrl:
@patch('flacfetch.providers.youtube.YoutubeProvider')
@patch('flacfetch.downloaders.youtube.YoutubeDownloader')
def test_download_from_url_extracts_video_id(
self, mock_yt_downloader, mock_yt_provider, mock_fetch_manager, fetcher, tmp_path
self, _mock_yt_downloader, _mock_yt_provider, mock_fetch_manager, fetcher, tmp_path
):
"""Test that video ID is extracted from URL correctly."""
mock_manager_instance = MagicMock()
@@ -2612,7 +2612,7 @@ class TestRemoteFlacFetchAudioFetcherDownloadFromUrl:
@patch('flacfetch.providers.youtube.YoutubeProvider')
@patch('flacfetch.downloaders.youtube.YoutubeDownloader')
def test_download_from_url_raises_on_failure(
self, mock_yt_downloader, mock_yt_provider, mock_fetch_manager, fetcher, tmp_path
self, _mock_yt_downloader, _mock_yt_provider, mock_fetch_manager, fetcher, tmp_path
):
"""Test that DownloadError is raised on failure."""
mock_manager_instance = MagicMock()