Archived
Compare commits
4
Commits
v1.4.0
...
25d2a55efb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25d2a55efb | ||
|
|
af534bf768 | ||
|
|
9ff883e2e3 | ||
|
|
bb8a8c251d |
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"Bash(python3:*)",
|
||||||
|
"Bash(node --check:*)",
|
||||||
|
"Bash(ls:*)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,414 @@
|
|||||||
|
name: Build Sidecars
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'client/**'
|
||||||
|
- 'server/**'
|
||||||
|
- 'backend/**'
|
||||||
|
- 'pyproject.toml'
|
||||||
|
- 'local-transcription-headless.spec'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bump-sidecar-version:
|
||||||
|
name: Bump sidecar version and tag
|
||||||
|
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.bump.outputs.version }}
|
||||||
|
tag: ${{ steps.bump.outputs.tag }}
|
||||||
|
has_changes: ${{ steps.check_changes.outputs.has_changes }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: Check for backend changes
|
||||||
|
id: check_changes
|
||||||
|
run: |
|
||||||
|
# If triggered by workflow_dispatch, always build
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
# Check if relevant files changed in this commit
|
||||||
|
CHANGED=$(git diff --name-only HEAD~1 HEAD -- client/ server/ backend/ pyproject.toml local-transcription-headless.spec 2>/dev/null || echo "")
|
||||||
|
if [ -n "$CHANGED" ]; then
|
||||||
|
echo "has_changes=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Backend changes detected: $CHANGED"
|
||||||
|
else
|
||||||
|
echo "has_changes=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "No backend changes detected, skipping sidecar build"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Configure git
|
||||||
|
if: steps.check_changes.outputs.has_changes == 'true'
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@gitea.local"
|
||||||
|
|
||||||
|
- name: Bump sidecar patch version
|
||||||
|
if: steps.check_changes.outputs.has_changes == 'true'
|
||||||
|
id: bump
|
||||||
|
run: |
|
||||||
|
# Read current version from pyproject.toml
|
||||||
|
CURRENT=$(grep '^version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
|
||||||
|
echo "Current sidecar version: ${CURRENT}"
|
||||||
|
|
||||||
|
# Increment patch number
|
||||||
|
MAJOR=$(echo "${CURRENT}" | cut -d. -f1)
|
||||||
|
MINOR=$(echo "${CURRENT}" | cut -d. -f2)
|
||||||
|
PATCH=$(echo "${CURRENT}" | cut -d. -f3)
|
||||||
|
NEW_PATCH=$((PATCH + 1))
|
||||||
|
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
|
||||||
|
echo "New sidecar version: ${NEW_VERSION}"
|
||||||
|
|
||||||
|
# Update pyproject.toml
|
||||||
|
sed -i "s/^version = \"${CURRENT}\"/version = \"${NEW_VERSION}\"/" pyproject.toml
|
||||||
|
|
||||||
|
# Update version.py
|
||||||
|
sed -i "s/__version__ = \"${CURRENT}\"/__version__ = \"${NEW_VERSION}\"/" version.py
|
||||||
|
sed -i "s/__version_info__ = .*/__version_info__ = (${MAJOR}, ${MINOR}, ${NEW_PATCH})/" version.py
|
||||||
|
|
||||||
|
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
echo "tag=sidecar-v${NEW_VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Commit and tag
|
||||||
|
if: steps.check_changes.outputs.has_changes == 'true'
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
NEW_VERSION="${{ steps.bump.outputs.version }}"
|
||||||
|
TAG="${{ steps.bump.outputs.tag }}"
|
||||||
|
git add pyproject.toml version.py
|
||||||
|
git commit -m "chore: bump sidecar version to ${NEW_VERSION} [skip ci]"
|
||||||
|
git tag "${TAG}"
|
||||||
|
|
||||||
|
REMOTE_URL=$(git remote get-url origin | sed "s|://|://gitea-actions:${BUILD_TOKEN}@|")
|
||||||
|
git pull --rebase "${REMOTE_URL}" main || true
|
||||||
|
git push "${REMOTE_URL}" HEAD:main
|
||||||
|
git push "${REMOTE_URL}" "${TAG}"
|
||||||
|
|
||||||
|
- name: Create Gitea release
|
||||||
|
if: steps.check_changes.outputs.has_changes == 'true'
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
REPO_API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${{ steps.bump.outputs.tag }}"
|
||||||
|
VERSION="${{ steps.bump.outputs.version }}"
|
||||||
|
RELEASE_NAME="Sidecar v${VERSION}"
|
||||||
|
|
||||||
|
curl -s -X POST \
|
||||||
|
-H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\": \"${TAG}\", \"name\": \"${RELEASE_NAME}\", \"body\": \"Automated sidecar build.\", \"draft\": false, \"prerelease\": false}" \
|
||||||
|
"${REPO_API}/releases"
|
||||||
|
echo "Created release: ${RELEASE_NAME}"
|
||||||
|
|
||||||
|
# ── Linux sidecar (CUDA + CPU) ──
|
||||||
|
|
||||||
|
build-sidecar-linux:
|
||||||
|
name: Build Sidecar (Linux)
|
||||||
|
needs: bump-sidecar-version
|
||||||
|
if: needs.bump-sidecar-version.outputs.has_changes == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: "3.11"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-sidecar-version.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
run: |
|
||||||
|
if command -v uv &> /dev/null; then
|
||||||
|
echo "uv already installed: $(uv --version)"
|
||||||
|
else
|
||||||
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||||
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y portaudio19-dev
|
||||||
|
|
||||||
|
- name: Build sidecar (CUDA)
|
||||||
|
run: |
|
||||||
|
uv sync
|
||||||
|
uv run pyinstaller local-transcription-headless.spec
|
||||||
|
|
||||||
|
- name: Package sidecar (CUDA)
|
||||||
|
run: |
|
||||||
|
cd dist/local-transcription-backend && zip -r ../../sidecar-linux-x86_64-cuda.zip .
|
||||||
|
|
||||||
|
- name: Build sidecar (CPU)
|
||||||
|
run: |
|
||||||
|
rm -rf dist/local-transcription-backend build/
|
||||||
|
# Install CPU-only PyTorch
|
||||||
|
uv pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu --force-reinstall
|
||||||
|
uv run pyinstaller local-transcription-headless.spec
|
||||||
|
|
||||||
|
- name: Package sidecar (CPU)
|
||||||
|
run: |
|
||||||
|
cd dist/local-transcription-backend && zip -r ../../sidecar-linux-x86_64-cpu.zip .
|
||||||
|
|
||||||
|
- name: Upload to sidecar release
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
sudo apt-get install -y jq
|
||||||
|
REPO_API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${{ needs.bump-sidecar-version.outputs.tag }}"
|
||||||
|
|
||||||
|
echo "Waiting for sidecar release ${TAG} to be available..."
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
RELEASE_JSON=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/tags/${TAG}")
|
||||||
|
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty')
|
||||||
|
|
||||||
|
if [ -n "${RELEASE_ID}" ] && [ "${RELEASE_ID}" != "null" ]; then
|
||||||
|
echo "Found sidecar release: ${TAG} (ID: ${RELEASE_ID})"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Attempt ${i}/30: Release not ready yet, retrying in 10s..."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
|
echo "ERROR: Failed to find sidecar release for tag ${TAG} after 30 attempts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in sidecar-*.zip; do
|
||||||
|
filename=$(basename "$file")
|
||||||
|
encoded_name=$(echo "$filename" | sed 's/ /%20/g')
|
||||||
|
echo "Uploading ${filename} ($(du -h "$file" | cut -f1))..."
|
||||||
|
|
||||||
|
ASSET_ID=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets" | jq -r ".[] | select(.name == \"${filename}\") | .id // empty")
|
||||||
|
if [ -n "${ASSET_ID}" ]; then
|
||||||
|
curl -s -X DELETE -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
-T "$file" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets?name=${encoded_name}")
|
||||||
|
echo "Upload response: HTTP ${HTTP_CODE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ── Windows sidecar (CUDA + CPU) ──
|
||||||
|
|
||||||
|
build-sidecar-windows:
|
||||||
|
name: Build Sidecar (Windows)
|
||||||
|
needs: bump-sidecar-version
|
||||||
|
if: needs.bump-sidecar-version.outputs.has_changes == 'true'
|
||||||
|
runs-on: windows-latest
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: "3.11"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-sidecar-version.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
if (Get-Command uv -ErrorAction SilentlyContinue) {
|
||||||
|
Write-Host "uv already installed: $(uv --version)"
|
||||||
|
} else {
|
||||||
|
irm https://astral.sh/uv/install.ps1 | iex
|
||||||
|
echo "$env:USERPROFILE\.local\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
shell: powershell
|
||||||
|
run: uv python install ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
|
- name: Install 7-Zip
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
if (-not (Get-Command 7z -ErrorAction SilentlyContinue)) {
|
||||||
|
choco install 7zip -y
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Build sidecar (CUDA)
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
uv sync
|
||||||
|
uv run pyinstaller local-transcription-headless.spec
|
||||||
|
|
||||||
|
- name: Package sidecar (CUDA)
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
7z a -tzip -mx=5 sidecar-windows-x86_64-cuda.zip .\dist\local-transcription-backend\*
|
||||||
|
|
||||||
|
- name: Build sidecar (CPU)
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Remove-Item -Recurse -Force dist\local-transcription-backend, build -ErrorAction SilentlyContinue
|
||||||
|
uv pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu --force-reinstall
|
||||||
|
uv run pyinstaller local-transcription-headless.spec
|
||||||
|
|
||||||
|
- name: Package sidecar (CPU)
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
7z a -tzip -mx=5 sidecar-windows-x86_64-cpu.zip .\dist\local-transcription-backend\*
|
||||||
|
|
||||||
|
- name: Upload to sidecar release
|
||||||
|
shell: powershell
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
$REPO_API = "${{ github.server_url }}/api/v1/repos/${{ github.repository }}"
|
||||||
|
$Headers = @{ "Authorization" = "token $env:BUILD_TOKEN" }
|
||||||
|
$TAG = "${{ needs.bump-sidecar-version.outputs.tag }}"
|
||||||
|
|
||||||
|
Write-Host "Waiting for sidecar release ${TAG} to be available..."
|
||||||
|
$RELEASE_ID = $null
|
||||||
|
|
||||||
|
for ($i = 1; $i -le 30; $i++) {
|
||||||
|
try {
|
||||||
|
$release = Invoke-RestMethod -Uri "${REPO_API}/releases/tags/${TAG}" -Headers $Headers -ErrorAction Stop
|
||||||
|
$RELEASE_ID = $release.id
|
||||||
|
|
||||||
|
if ($RELEASE_ID) {
|
||||||
|
Write-Host "Found sidecar release: ${TAG} (ID: ${RELEASE_ID})"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
Write-Host "Attempt ${i}/30: Release not ready yet, retrying in 10s..."
|
||||||
|
Start-Sleep -Seconds 10
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $RELEASE_ID) {
|
||||||
|
Write-Host "ERROR: Failed to find sidecar release for tag ${TAG} after 30 attempts."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Get-ChildItem -Path . -Filter "sidecar-*.zip" | ForEach-Object {
|
||||||
|
$filename = $_.Name
|
||||||
|
$encodedName = [System.Uri]::EscapeDataString($filename)
|
||||||
|
$size = [math]::Round($_.Length / 1MB, 1)
|
||||||
|
Write-Host "Uploading ${filename} (${size} MB)..."
|
||||||
|
|
||||||
|
try {
|
||||||
|
$assets = Invoke-RestMethod -Uri "${REPO_API}/releases/${RELEASE_ID}/assets" -Headers $Headers
|
||||||
|
$existing = $assets | Where-Object { $_.name -eq $filename }
|
||||||
|
if ($existing) {
|
||||||
|
Invoke-RestMethod -Uri "${REPO_API}/releases/${RELEASE_ID}/assets/$($existing.id)" -Method Delete -Headers $Headers
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
$uploadUrl = "${REPO_API}/releases/${RELEASE_ID}/assets?name=${encodedName}"
|
||||||
|
$result = curl.exe --fail --silent --show-error `
|
||||||
|
-X POST `
|
||||||
|
-H "Authorization: token $env:BUILD_TOKEN" `
|
||||||
|
-H "Content-Type: application/octet-stream" `
|
||||||
|
-T "$($_.FullName)" `
|
||||||
|
"$uploadUrl" 2>&1
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "Upload successful: ${filename}"
|
||||||
|
} else {
|
||||||
|
Write-Host "WARNING: Upload failed for ${filename}: ${result}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ── macOS sidecar (CPU only — no CUDA on macOS) ──
|
||||||
|
|
||||||
|
build-sidecar-macos:
|
||||||
|
name: Build Sidecar (macOS)
|
||||||
|
needs: bump-sidecar-version
|
||||||
|
if: needs.bump-sidecar-version.outputs.has_changes == 'true'
|
||||||
|
runs-on: macos-latest
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: "3.11"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-sidecar-version.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Install uv
|
||||||
|
run: |
|
||||||
|
if command -v uv &> /dev/null; then
|
||||||
|
echo "uv already installed: $(uv --version)"
|
||||||
|
else
|
||||||
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||||
|
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: brew install portaudio
|
||||||
|
|
||||||
|
- name: Build sidecar (CPU)
|
||||||
|
run: |
|
||||||
|
# Install CPU-only PyTorch for macOS (MPS support included in default torch)
|
||||||
|
uv sync
|
||||||
|
uv pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu --force-reinstall
|
||||||
|
uv run pyinstaller local-transcription-headless.spec
|
||||||
|
|
||||||
|
- name: Package sidecar (CPU)
|
||||||
|
run: |
|
||||||
|
cd dist/local-transcription-backend && zip -r ../../sidecar-macos-aarch64-cpu.zip .
|
||||||
|
|
||||||
|
- name: Upload to sidecar release
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
which jq || brew install jq
|
||||||
|
REPO_API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${{ needs.bump-sidecar-version.outputs.tag }}"
|
||||||
|
|
||||||
|
echo "Waiting for sidecar release ${TAG} to be available..."
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
RELEASE_JSON=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/tags/${TAG}")
|
||||||
|
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty')
|
||||||
|
|
||||||
|
if [ -n "${RELEASE_ID}" ] && [ "${RELEASE_ID}" != "null" ]; then
|
||||||
|
echo "Found sidecar release: ${TAG} (ID: ${RELEASE_ID})"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Attempt ${i}/30: Release not ready yet, retrying in 10s..."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
|
echo "ERROR: Failed to find sidecar release for tag ${TAG} after 30 attempts."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in sidecar-*.zip; do
|
||||||
|
filename=$(basename "$file")
|
||||||
|
encoded_name=$(echo "$filename" | sed 's/ /%20/g')
|
||||||
|
echo "Uploading ${filename} ($(du -h "$file" | cut -f1))..."
|
||||||
|
|
||||||
|
ASSET_ID=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets" | jq -r ".[] | select(.name == \"${filename}\") | .id // empty")
|
||||||
|
if [ -n "${ASSET_ID}" ]; then
|
||||||
|
curl -s -X DELETE -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
-T "$file" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets?name=${encoded_name}")
|
||||||
|
echo "Upload response: HTTP ${HTTP_CODE}"
|
||||||
|
done
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bump-version:
|
||||||
|
name: Bump version and tag
|
||||||
|
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
new_version: ${{ steps.bump.outputs.new_version }}
|
||||||
|
tag: ${{ steps.bump.outputs.tag }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Configure git
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@gitea.local"
|
||||||
|
|
||||||
|
- name: Bump patch version
|
||||||
|
id: bump
|
||||||
|
run: |
|
||||||
|
# Read current version from package.json
|
||||||
|
CURRENT=$(grep '"version"' package.json | head -1 | sed 's/.*"version": *"\([^"]*\)".*/\1/')
|
||||||
|
echo "Current version: ${CURRENT}"
|
||||||
|
|
||||||
|
# Increment patch number
|
||||||
|
MAJOR=$(echo "${CURRENT}" | cut -d. -f1)
|
||||||
|
MINOR=$(echo "${CURRENT}" | cut -d. -f2)
|
||||||
|
PATCH=$(echo "${CURRENT}" | cut -d. -f3)
|
||||||
|
NEW_PATCH=$((PATCH + 1))
|
||||||
|
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
|
||||||
|
echo "New version: ${NEW_VERSION}"
|
||||||
|
|
||||||
|
# Update package.json
|
||||||
|
sed -i "s/\"version\": \"${CURRENT}\"/\"version\": \"${NEW_VERSION}\"/" package.json
|
||||||
|
|
||||||
|
# Update src-tauri/tauri.conf.json
|
||||||
|
sed -i "s/\"version\": \"${CURRENT}\"/\"version\": \"${NEW_VERSION}\"/" src-tauri/tauri.conf.json
|
||||||
|
|
||||||
|
# Update src-tauri/Cargo.toml
|
||||||
|
sed -i "s/^version = \"${CURRENT}\"/version = \"${NEW_VERSION}\"/" src-tauri/Cargo.toml
|
||||||
|
|
||||||
|
# Update version.py
|
||||||
|
sed -i "s/__version__ = \"${CURRENT}\"/__version__ = \"${NEW_VERSION}\"/" version.py
|
||||||
|
sed -i "s/__version_info__ = .*/__version_info__ = (${MAJOR}, ${MINOR}, ${NEW_PATCH})/" version.py
|
||||||
|
|
||||||
|
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
echo "tag=v${NEW_VERSION}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Commit and tag
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
NEW_VERSION="${{ steps.bump.outputs.new_version }}"
|
||||||
|
git add package.json src-tauri/tauri.conf.json src-tauri/Cargo.toml version.py
|
||||||
|
git commit -m "chore: bump version to ${NEW_VERSION} [skip ci]"
|
||||||
|
git tag "v${NEW_VERSION}"
|
||||||
|
|
||||||
|
REMOTE_URL=$(git remote get-url origin | sed "s|://|://gitea-actions:${BUILD_TOKEN}@|")
|
||||||
|
git pull --rebase "${REMOTE_URL}" main || true
|
||||||
|
git push "${REMOTE_URL}" HEAD:main
|
||||||
|
git push "${REMOTE_URL}" "v${NEW_VERSION}"
|
||||||
|
|
||||||
|
- name: Create Gitea release
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
REPO_API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${{ steps.bump.outputs.tag }}"
|
||||||
|
RELEASE_NAME="Local Transcription ${TAG}"
|
||||||
|
|
||||||
|
curl -s -X POST \
|
||||||
|
-H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\": \"${TAG}\", \"name\": \"${RELEASE_NAME}\", \"body\": \"Automated build.\", \"draft\": false, \"prerelease\": false}" \
|
||||||
|
"${REPO_API}/releases"
|
||||||
|
echo "Created release: ${RELEASE_NAME}"
|
||||||
|
|
||||||
|
# ── Platform builds (run after version bump) ──
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
name: Build App (Linux)
|
||||||
|
needs: bump-version
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
NODE_VERSION: "20"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-version.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
|
||||||
|
- name: Install Rust stable
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
||||||
|
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xdg-utils rpm
|
||||||
|
|
||||||
|
- name: Install npm dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build Tauri app
|
||||||
|
run: npm run tauri build
|
||||||
|
|
||||||
|
- name: Upload to release
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
sudo apt-get install -y jq
|
||||||
|
REPO_API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${{ needs.bump-version.outputs.tag }}"
|
||||||
|
echo "Release tag: ${TAG}"
|
||||||
|
|
||||||
|
RELEASE_ID=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/tags/${TAG}" | jq -r '.id // empty')
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
|
echo "ERROR: Failed to find release for tag ${TAG}."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
|
find src-tauri/target/release/bundle -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.AppImage" \) | while IFS= read -r file; do
|
||||||
|
filename=$(basename "$file")
|
||||||
|
encoded_name=$(echo "$filename" | sed 's/ /%20/g')
|
||||||
|
echo "Uploading ${filename} ($(du -h "$file" | cut -f1))..."
|
||||||
|
|
||||||
|
ASSET_ID=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets" | jq -r ".[] | select(.name == \"${filename}\") | .id // empty")
|
||||||
|
if [ -n "${ASSET_ID}" ]; then
|
||||||
|
curl -s -X DELETE -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
-T "$file" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets?name=${encoded_name}")
|
||||||
|
echo "Upload response: HTTP ${HTTP_CODE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
name: Build App (Windows)
|
||||||
|
needs: bump-version
|
||||||
|
runs-on: windows-latest
|
||||||
|
env:
|
||||||
|
NODE_VERSION: "20"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-version.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
|
||||||
|
- name: Install Rust stable
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
if (Get-Command rustup -ErrorAction SilentlyContinue) {
|
||||||
|
rustup default stable
|
||||||
|
} else {
|
||||||
|
Invoke-WebRequest -Uri https://win.rustup.rs/x86_64 -OutFile rustup-init.exe
|
||||||
|
.\rustup-init.exe -y --default-toolchain stable
|
||||||
|
echo "$env:USERPROFILE\.cargo\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Install npm dependencies
|
||||||
|
shell: powershell
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build Tauri app
|
||||||
|
shell: powershell
|
||||||
|
run: npm run tauri build
|
||||||
|
|
||||||
|
- name: Upload to release
|
||||||
|
shell: powershell
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
$REPO_API = "${{ github.server_url }}/api/v1/repos/${{ github.repository }}"
|
||||||
|
$Headers = @{ "Authorization" = "token $env:BUILD_TOKEN" }
|
||||||
|
$TAG = "${{ needs.bump-version.outputs.tag }}"
|
||||||
|
Write-Host "Release tag: ${TAG}"
|
||||||
|
|
||||||
|
$release = Invoke-RestMethod -Uri "${REPO_API}/releases/tags/${TAG}" -Headers $Headers -ErrorAction Stop
|
||||||
|
$RELEASE_ID = $release.id
|
||||||
|
Write-Host "Release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
|
Get-ChildItem -Path src-tauri\target\release\bundle -Recurse -Include *.msi,*-setup.exe | ForEach-Object {
|
||||||
|
$filename = $_.Name
|
||||||
|
$encodedName = [System.Uri]::EscapeDataString($filename)
|
||||||
|
$size = [math]::Round($_.Length / 1MB, 1)
|
||||||
|
Write-Host "Uploading ${filename} (${size} MB)..."
|
||||||
|
|
||||||
|
try {
|
||||||
|
$assets = Invoke-RestMethod -Uri "${REPO_API}/releases/${RELEASE_ID}/assets" -Headers $Headers
|
||||||
|
$existing = $assets | Where-Object { $_.name -eq $filename }
|
||||||
|
if ($existing) {
|
||||||
|
Invoke-RestMethod -Uri "${REPO_API}/releases/${RELEASE_ID}/assets/$($existing.id)" -Method Delete -Headers $Headers
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
$uploadUrl = "${REPO_API}/releases/${RELEASE_ID}/assets?name=${encodedName}"
|
||||||
|
$result = curl.exe --fail --silent --show-error `
|
||||||
|
-X POST `
|
||||||
|
-H "Authorization: token $env:BUILD_TOKEN" `
|
||||||
|
-H "Content-Type: application/octet-stream" `
|
||||||
|
-T "$($_.FullName)" `
|
||||||
|
"$uploadUrl" 2>&1
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "Upload successful: ${filename}"
|
||||||
|
} else {
|
||||||
|
Write-Host "WARNING: Upload failed for ${filename}: ${result}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
name: Build App (macOS)
|
||||||
|
needs: bump-version
|
||||||
|
runs-on: macos-latest
|
||||||
|
env:
|
||||||
|
NODE_VERSION: "20"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-version.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
|
||||||
|
- name: Install Rust stable
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
||||||
|
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Install system dependencies
|
||||||
|
run: brew install --quiet create-dmg || true
|
||||||
|
|
||||||
|
- name: Install npm dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build Tauri app
|
||||||
|
run: npm run tauri build
|
||||||
|
|
||||||
|
- name: Upload to release
|
||||||
|
env:
|
||||||
|
BUILD_TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||||
|
run: |
|
||||||
|
which jq || brew install jq
|
||||||
|
REPO_API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
TAG="${{ needs.bump-version.outputs.tag }}"
|
||||||
|
echo "Release tag: ${TAG}"
|
||||||
|
|
||||||
|
RELEASE_ID=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/tags/${TAG}" | jq -r '.id // empty')
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
|
echo "ERROR: Failed to find release for tag ${TAG}."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
|
find src-tauri/target/release/bundle -type f -name "*.dmg" | while IFS= read -r file; do
|
||||||
|
filename=$(basename "$file")
|
||||||
|
encoded_name=$(echo "$filename" | sed 's/ /%20/g')
|
||||||
|
echo "Uploading ${filename} ($(du -h "$file" | cut -f1))..."
|
||||||
|
|
||||||
|
ASSET_ID=$(curl -s -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets" | jq -r ".[] | select(.name == \"${filename}\") | .id // empty")
|
||||||
|
if [ -n "${ASSET_ID}" ]; then
|
||||||
|
curl -s -X DELETE -H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets/${ASSET_ID}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${BUILD_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
-T "$file" \
|
||||||
|
"${REPO_API}/releases/${RELEASE_ID}/assets?name=${encoded_name}")
|
||||||
|
echo "Upload response: HTTP ${HTTP_CODE}"
|
||||||
|
done
|
||||||
@@ -54,3 +54,12 @@ models/
|
|||||||
|
|
||||||
# PyInstaller
|
# PyInstaller
|
||||||
*.spec.lock
|
*.spec.lock
|
||||||
|
|
||||||
|
# Node.js
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Vite / Svelte build output
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# Tauri
|
||||||
|
src-tauri/target/
|
||||||
|
|||||||
@@ -0,0 +1,574 @@
|
|||||||
|
# Deepgram Proxy Service — Build Plan
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
Build a standalone hosted service that acts as a Deepgram proxy for the Local Transcription
|
||||||
|
desktop app. Users can either provide their own Deepgram API key (BYOK) or use the managed
|
||||||
|
service with prepaid credits purchased via Stripe.
|
||||||
|
|
||||||
|
This is a **separate repository** from `local-transcription`. The desktop app will be updated
|
||||||
|
in a second phase to support both modes.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Repository Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
transcription-proxy/
|
||||||
|
├── src/
|
||||||
|
│ ├── server.js # Express app entry point
|
||||||
|
│ ├── config.js # Environment config loader
|
||||||
|
│ ├── db/
|
||||||
|
│ │ ├── index.js # node-postgres pool setup
|
||||||
|
│ │ └── migrations/ # SQL migration files (numbered)
|
||||||
|
│ │ ├── 001_users.sql
|
||||||
|
│ │ ├── 002_credits.sql
|
||||||
|
│ │ ├── 003_sessions.sql
|
||||||
|
│ │ └── 004_usage_ledger.sql
|
||||||
|
│ ├── middleware/
|
||||||
|
│ │ ├── auth.js # JWT verification middleware
|
||||||
|
│ │ └── rateLimit.js # Per-user rate limiting
|
||||||
|
│ ├── routes/
|
||||||
|
│ │ ├── auth.js # POST /auth/register, /auth/login, /auth/refresh
|
||||||
|
│ │ ├── billing.js # POST /billing/checkout, GET /billing/balance
|
||||||
|
│ │ └── account.js # GET /account/me, GET /account/usage
|
||||||
|
│ ├── websocket/
|
||||||
|
│ │ └── proxy.js # WebSocket proxy handler (core feature)
|
||||||
|
│ └── webhooks/
|
||||||
|
│ └── stripe.js # POST /webhooks/stripe
|
||||||
|
├── web/ # Simple frontend dashboard
|
||||||
|
│ ├── index.html # Landing / login page
|
||||||
|
│ ├── dashboard.html # Balance, usage history, buy credits
|
||||||
|
│ └── assets/
|
||||||
|
│ ├── app.js
|
||||||
|
│ └── style.css
|
||||||
|
├── .env.example
|
||||||
|
├── package.json
|
||||||
|
├── docker-compose.yml # Postgres + app for local dev
|
||||||
|
└── CLAUDE.md # This file (after renaming)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Technology Stack
|
||||||
|
|
||||||
|
- **Runtime**: Node.js 20+
|
||||||
|
- **Framework**: Express 4
|
||||||
|
- **WebSocket**: `ws` library (not socket.io — keep it lean)
|
||||||
|
- **Database**: PostgreSQL 15+ via `pg` (node-postgres)
|
||||||
|
- **Auth**: JWT via `jsonwebtoken`, passwords hashed with `bcrypt`
|
||||||
|
- **Payments**: Stripe Node SDK (`stripe`)
|
||||||
|
- **Environment**: `dotenv`
|
||||||
|
- **Dev tooling**: `nodemon` for dev, no TypeScript (keep it simple)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Database Schema
|
||||||
|
|
||||||
|
Run migrations in order. Use a simple `schema_migrations` table to track applied migrations.
|
||||||
|
|
||||||
|
### 001_users.sql
|
||||||
|
```sql
|
||||||
|
CREATE TABLE schema_migrations (
|
||||||
|
version INTEGER PRIMARY KEY,
|
||||||
|
applied_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE users (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
email TEXT UNIQUE NOT NULL,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
stripe_customer_id TEXT UNIQUE,
|
||||||
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 002_credits.sql
|
||||||
|
```sql
|
||||||
|
CREATE TABLE credit_balance (
|
||||||
|
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
seconds_remaining INTEGER NOT NULL DEFAULT 0,
|
||||||
|
updated_at TIMESTAMPTZ DEFAULT NOW()
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 003_sessions.sql
|
||||||
|
```sql
|
||||||
|
CREATE TABLE transcription_sessions (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id),
|
||||||
|
mode TEXT NOT NULL CHECK (mode IN ('managed', 'byok')),
|
||||||
|
started_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
ended_at TIMESTAMPTZ,
|
||||||
|
seconds_used INTEGER NOT NULL DEFAULT 0,
|
||||||
|
deepgram_model TEXT,
|
||||||
|
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'completed', 'terminated'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_sessions_user_id ON transcription_sessions(user_id);
|
||||||
|
CREATE INDEX idx_sessions_started_at ON transcription_sessions(started_at);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 004_usage_ledger.sql
|
||||||
|
```sql
|
||||||
|
CREATE TABLE usage_ledger (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id),
|
||||||
|
session_id UUID REFERENCES transcription_sessions(id),
|
||||||
|
recorded_at TIMESTAMPTZ DEFAULT NOW(),
|
||||||
|
seconds INTEGER NOT NULL,
|
||||||
|
description TEXT -- e.g. 'session_usage', 'credit_purchase', 'manual_adjustment'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_ledger_user_id ON usage_ledger(user_id);
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Environment Variables (.env.example)
|
||||||
|
|
||||||
|
```env
|
||||||
|
# Server
|
||||||
|
PORT=3000
|
||||||
|
NODE_ENV=development
|
||||||
|
|
||||||
|
# Database
|
||||||
|
DATABASE_URL=postgresql://user:password@localhost:5432/transcription_proxy
|
||||||
|
|
||||||
|
# Auth
|
||||||
|
JWT_SECRET=changeme_use_long_random_string
|
||||||
|
JWT_EXPIRY=7d
|
||||||
|
|
||||||
|
# Stripe
|
||||||
|
STRIPE_SECRET_KEY=sk_test_...
|
||||||
|
STRIPE_WEBHOOK_SECRET=whsec_...
|
||||||
|
|
||||||
|
# Deepgram
|
||||||
|
DEEPGRAM_API_KEY=your_deepgram_key_here
|
||||||
|
|
||||||
|
# Pricing (seconds per dollar — adjust for your margin)
|
||||||
|
# Default: 1000 seconds per $1 = $0.006/min managed cost covered + margin
|
||||||
|
CREDITS_PER_DOLLAR=1000
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 1 — Core Server & Auth
|
||||||
|
|
||||||
|
### Goals
|
||||||
|
- Working Express app with Postgres connection
|
||||||
|
- Migration runner
|
||||||
|
- User registration and login
|
||||||
|
- JWT middleware
|
||||||
|
|
||||||
|
### Tasks
|
||||||
|
|
||||||
|
1. **Scaffold project**
|
||||||
|
- `npm init`, install dependencies: `express ws pg jsonwebtoken bcrypt stripe dotenv`
|
||||||
|
- Dev dependencies: `nodemon`
|
||||||
|
- Add `start` and `dev` scripts to package.json
|
||||||
|
|
||||||
|
2. **Database connection** (`src/db/index.js`)
|
||||||
|
- Export a `pg.Pool` instance using `DATABASE_URL`
|
||||||
|
- Export a `migrate()` function that reads `src/db/migrations/*.sql` in order,
|
||||||
|
checks `schema_migrations` table, and applies unapplied ones
|
||||||
|
- Call `migrate()` on server startup before listening
|
||||||
|
|
||||||
|
3. **Auth routes** (`src/routes/auth.js`)
|
||||||
|
- `POST /auth/register` — validate email/password, hash password with bcrypt (cost 12),
|
||||||
|
insert user, insert empty credit_balance row, return JWT
|
||||||
|
- `POST /auth/login` — verify credentials, return JWT + refresh token
|
||||||
|
- `POST /auth/refresh` — validate refresh token, return new JWT
|
||||||
|
- Passwords: minimum 8 characters, validate email format
|
||||||
|
|
||||||
|
4. **JWT middleware** (`src/middleware/auth.js`)
|
||||||
|
- Verify `Authorization: Bearer <token>` header
|
||||||
|
- Attach `req.user = { id, email }` on success
|
||||||
|
- Return 401 on failure
|
||||||
|
- Export as `requireAuth` middleware
|
||||||
|
|
||||||
|
5. **Basic health check**
|
||||||
|
- `GET /health` returns `{ status: 'ok', db: 'connected' }`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 2 — Billing & Credits
|
||||||
|
|
||||||
|
### Goals
|
||||||
|
- Stripe Checkout session creation for credit purchases
|
||||||
|
- Webhook handler to fulfill purchases
|
||||||
|
- Balance endpoint
|
||||||
|
|
||||||
|
### Payment Methods
|
||||||
|
|
||||||
|
Use **Stripe Dynamic Payment Methods** — do NOT hardcode `payment_method_types` in the
|
||||||
|
Checkout Session. Instead, leave it unset and manage everything from the Stripe Dashboard.
|
||||||
|
|
||||||
|
Enable the following in the Stripe Dashboard under Settings → Payment Methods:
|
||||||
|
- **Cards** (Visa, Mastercard, Amex, Discover) — on by default
|
||||||
|
- **PayPal** — enable manually
|
||||||
|
- **Apple Pay** — on by default, shows automatically on Safari/iOS
|
||||||
|
- **Google Pay** — enable manually (one toggle)
|
||||||
|
- **Cash App Pay** — enable manually (popular with streaming audiences)
|
||||||
|
- **Link** — Stripe's saved payment network, on by default
|
||||||
|
|
||||||
|
Stripe will automatically show the most relevant methods to each user based on their
|
||||||
|
location and device. No code changes are needed to add or remove methods in future —
|
||||||
|
it's all dashboard config.
|
||||||
|
|
||||||
|
### Credit Packages
|
||||||
|
|
||||||
|
Define these as constants in `src/config.js`:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
CREDIT_PACKAGES: [
|
||||||
|
{ id: 'pack_500', label: '500 minutes', seconds: 30000, price_cents: 300 },
|
||||||
|
{ id: 'pack_1200', label: '1200 minutes', seconds: 72000, price_cents: 600 },
|
||||||
|
{ id: 'pack_3000', label: '3000 minutes', seconds: 180000, price_cents: 1200 },
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Adjust pricing to cover Deepgram costs ($0.006/min = $0.0001/sec) plus margin and
|
||||||
|
Stripe fees (~2.9% + $0.30).
|
||||||
|
|
||||||
|
### Tasks
|
||||||
|
|
||||||
|
1. **Stripe customer creation**
|
||||||
|
- On user registration, create a Stripe customer and store `stripe_customer_id`
|
||||||
|
- Do this asynchronously (don't block registration response)
|
||||||
|
|
||||||
|
2. **Billing routes** (`src/routes/billing.js`)
|
||||||
|
- `GET /billing/packages` — return credit package list (no auth required)
|
||||||
|
- `POST /billing/checkout` — requires auth, accepts `{ package_id }`,
|
||||||
|
creates Stripe Checkout Session using dynamic payment methods (do NOT pass
|
||||||
|
`payment_method_types` — omitting it enables dynamic methods automatically),
|
||||||
|
include `payment_intent_data.metadata` containing `user_id` and `package_id`,
|
||||||
|
returns `{ checkout_url }`
|
||||||
|
- `GET /billing/balance` — requires auth, returns `{ seconds_remaining, minutes_remaining }`
|
||||||
|
|
||||||
|
3. **Stripe webhook** (`src/webhooks/stripe.js`)
|
||||||
|
- Mount at `POST /webhooks/stripe` with raw body (use `express.raw()` for this route only)
|
||||||
|
- Verify signature with `stripe.webhooks.constructEvent()`
|
||||||
|
- Handle `checkout.session.completed`:
|
||||||
|
- Extract `user_id` and `package_id` from metadata
|
||||||
|
- Add seconds to `credit_balance`
|
||||||
|
- Insert row into `usage_ledger` with description `'credit_purchase'`
|
||||||
|
- Handle `payment_intent.payment_failed`: log it (no action needed for prepaid)
|
||||||
|
|
||||||
|
4. **Success/cancel pages**
|
||||||
|
- Stripe Checkout redirects to `GET /billing/success?session_id=...` and `/billing/cancel`
|
||||||
|
- These can be simple HTML responses or redirects to the web dashboard
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 3 — WebSocket Proxy (Core Feature)
|
||||||
|
|
||||||
|
This is the most critical component. The proxy sits between the desktop client and Deepgram,
|
||||||
|
forwarding audio while tracking usage in real time.
|
||||||
|
|
||||||
|
### Connection Flow
|
||||||
|
|
||||||
|
```
|
||||||
|
Client connects → validate JWT → check credit balance → open Deepgram upstream
|
||||||
|
↓
|
||||||
|
Audio chunks arrive → forward to Deepgram → record usage every 5 seconds
|
||||||
|
↓
|
||||||
|
Transcription arrives from Deepgram → forward to client
|
||||||
|
↓
|
||||||
|
Client disconnects (or credits exhausted) → close upstream → finalize session
|
||||||
|
```
|
||||||
|
|
||||||
|
### WebSocket Protocol
|
||||||
|
|
||||||
|
**Client connects to**: `wss://your-domain/ws/transcribe`
|
||||||
|
|
||||||
|
**Client sends as first message** (JSON):
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "auth",
|
||||||
|
"token": "<JWT>",
|
||||||
|
"config": {
|
||||||
|
"model": "nova-2",
|
||||||
|
"language": "en-US",
|
||||||
|
"interim_results": true,
|
||||||
|
"endpointing": 300
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**After auth success, client sends**: raw audio binary frames (PCM 16kHz mono)
|
||||||
|
|
||||||
|
**Server sends to client**:
|
||||||
|
```json
|
||||||
|
{ "type": "ready" }
|
||||||
|
{ "type": "transcript", "text": "...", "is_final": true, "confidence": 0.98 }
|
||||||
|
{ "type": "error", "code": "insufficient_credits", "message": "..." }
|
||||||
|
{ "type": "credits_low", "seconds_remaining": 300 }
|
||||||
|
{ "type": "session_end", "seconds_used": 120 }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tasks (`src/websocket/proxy.js`)
|
||||||
|
|
||||||
|
1. **Upgrade handler**
|
||||||
|
- Attach to the HTTP server using `ws.Server({ noServer: true })`
|
||||||
|
- In `server.on('upgrade', ...)`, route `/ws/transcribe` to this handler
|
||||||
|
|
||||||
|
2. **Auth handshake**
|
||||||
|
- First message must be `{ type: 'auth', token: '...' }` — received within 5 seconds
|
||||||
|
or connection is terminated
|
||||||
|
- Verify JWT, load user's credit balance from DB
|
||||||
|
- If balance is 0 or negative, send `insufficient_credits` error and close
|
||||||
|
|
||||||
|
3. **Deepgram upstream connection**
|
||||||
|
- Open a WebSocket to Deepgram's streaming API:
|
||||||
|
`wss://api.deepgram.com/v1/listen?model=nova-2&language=en-US&interim_results=true`
|
||||||
|
- Auth header: `Authorization: Token <DEEPGRAM_API_KEY>`
|
||||||
|
- Use query params from client's `config` object (whitelist allowed params)
|
||||||
|
|
||||||
|
4. **Audio forwarding**
|
||||||
|
- All binary messages from client → forward directly to Deepgram upstream
|
||||||
|
- All messages from Deepgram → parse JSON, reformat, forward to client
|
||||||
|
|
||||||
|
5. **Usage tracking**
|
||||||
|
- Create a `transcription_sessions` row on connection
|
||||||
|
- Maintain an in-memory `secondsUsed` counter per connection
|
||||||
|
- Deepgram sends `{ type: 'Results', duration: X }` in responses — use this for
|
||||||
|
accurate second counting
|
||||||
|
- Every 10 seconds (or on disconnect), write current `secondsUsed` to DB:
|
||||||
|
- Update `transcription_sessions.seconds_used`
|
||||||
|
- Decrement `credit_balance.seconds_remaining`
|
||||||
|
- Insert into `usage_ledger`
|
||||||
|
- If `seconds_remaining` hits 0: send `insufficient_credits`, close connection
|
||||||
|
|
||||||
|
6. **Cleanup on disconnect**
|
||||||
|
- Mark session as `completed`, set `ended_at`
|
||||||
|
- Do final usage flush to DB
|
||||||
|
- Close Deepgram upstream if still open
|
||||||
|
|
||||||
|
7. **Error handling**
|
||||||
|
- If Deepgram upstream closes unexpectedly, notify client and close
|
||||||
|
- If client sends malformed data, log and continue (don't crash)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 4 — Account Routes & Rate Limiting
|
||||||
|
|
||||||
|
### Tasks
|
||||||
|
|
||||||
|
1. **Account routes** (`src/routes/account.js`)
|
||||||
|
- `GET /account/me` — returns `{ email, credits: { seconds_remaining, minutes_remaining }, created_at }`
|
||||||
|
- `GET /account/usage` — returns last 30 days of `usage_ledger` entries grouped by day,
|
||||||
|
plus list of last 10 sessions with duration
|
||||||
|
|
||||||
|
2. **Rate limiting** (`src/middleware/rateLimit.js`)
|
||||||
|
- Use in-memory rate limiting (no Redis needed at this scale)
|
||||||
|
- Auth endpoints: max 10 requests per minute per IP
|
||||||
|
- WebSocket connections: max 2 concurrent connections per user
|
||||||
|
(store active connections in a `Map<userId, Set<ws>>`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 5 — Web Dashboard
|
||||||
|
|
||||||
|
A simple, functional HTML/CSS/JS dashboard. No framework — vanilla JS is fine.
|
||||||
|
This is a developer-friendly streamer tool, not a consumer SaaS, so clean and
|
||||||
|
functional beats flashy.
|
||||||
|
|
||||||
|
### Pages
|
||||||
|
|
||||||
|
**`/` (Landing / Login)**
|
||||||
|
- Brief product description (what this is, why it exists)
|
||||||
|
- Login form and link to register
|
||||||
|
- Link to GitHub/Gitea repo
|
||||||
|
|
||||||
|
**`/dashboard` (Post-login)**
|
||||||
|
- Current credit balance (minutes remaining, prominently displayed)
|
||||||
|
- "Buy Credits" section showing the three packages with Stripe Checkout buttons
|
||||||
|
- Usage chart: last 30 days bar chart (vanilla canvas or a small CDN chart lib)
|
||||||
|
- Recent sessions table: date, duration, status
|
||||||
|
|
||||||
|
**`/register`**
|
||||||
|
- Registration form
|
||||||
|
|
||||||
|
### Implementation Notes
|
||||||
|
- Store JWT in `localStorage`, attach as `Authorization` header on API calls
|
||||||
|
- Redirect to `/` if JWT missing or expired
|
||||||
|
- Keep CSS minimal but readable — this is a utility dashboard
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 6 — Desktop App Integration
|
||||||
|
|
||||||
|
Changes needed in the `local-transcription` Python repo.
|
||||||
|
|
||||||
|
### New file: `client/remote_transcription.py`
|
||||||
|
|
||||||
|
This module replaces `transcription_engine_realtime.py` when remote mode is active.
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Pseudocode / spec for Claude Code to implement
|
||||||
|
|
||||||
|
class RemoteTranscriptionEngine:
|
||||||
|
"""
|
||||||
|
Connects to the transcription proxy WebSocket and streams audio.
|
||||||
|
Provides the same callback interface as the local engine so the
|
||||||
|
rest of the app doesn't need to change.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, config, on_transcript_callback):
|
||||||
|
# config contains: server_url, auth_token (or byok_api_key), model
|
||||||
|
...
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
# Open WebSocket connection
|
||||||
|
# Send auth message
|
||||||
|
# Start audio capture thread (reuse existing audio_capture.py)
|
||||||
|
...
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
# Close WebSocket gracefully
|
||||||
|
...
|
||||||
|
|
||||||
|
def _on_audio_chunk(self, audio_data):
|
||||||
|
# Called by audio_capture.py with raw PCM data
|
||||||
|
# Send as binary WebSocket frame
|
||||||
|
...
|
||||||
|
|
||||||
|
def _on_server_message(self, message):
|
||||||
|
# Parse JSON from server
|
||||||
|
# On type='transcript': call on_transcript_callback
|
||||||
|
# On type='credits_low': trigger UI warning
|
||||||
|
# On type='error': surface to user
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
### BYOK Mode
|
||||||
|
|
||||||
|
When user provides their own Deepgram key, connect directly to Deepgram instead of the proxy:
|
||||||
|
- Endpoint: `wss://api.deepgram.com/v1/listen?...`
|
||||||
|
- Auth: `Authorization: Token <user_key>`
|
||||||
|
- No session tracking (Deepgram handles billing directly to the user)
|
||||||
|
- Same `RemoteTranscriptionEngine` class, just different URL and auth header
|
||||||
|
|
||||||
|
### Settings Changes (`gui/settings_dialog_qt.py`)
|
||||||
|
|
||||||
|
Add a new "Transcription Mode" section:
|
||||||
|
|
||||||
|
```
|
||||||
|
Transcription Mode:
|
||||||
|
○ Local (Whisper) [existing behavior]
|
||||||
|
○ Remote - Managed [requires login]
|
||||||
|
○ Remote - BYOK [requires Deepgram API key]
|
||||||
|
|
||||||
|
[If Managed selected]:
|
||||||
|
Server URL: [____________]
|
||||||
|
[Login / Register] [View Balance: 420 min remaining]
|
||||||
|
|
||||||
|
[If BYOK selected]:
|
||||||
|
Deepgram API Key: [____________]
|
||||||
|
Model: [nova-2 ▼]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config additions (`config/default_config.yaml`)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
remote:
|
||||||
|
mode: local # local | managed | byok
|
||||||
|
server_url: "" # proxy server URL for managed mode
|
||||||
|
auth_token: "" # JWT stored after login
|
||||||
|
byok_api_key: "" # Deepgram key for BYOK mode
|
||||||
|
deepgram_model: nova-2
|
||||||
|
language: en-US
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Build & Deployment Notes
|
||||||
|
|
||||||
|
### Docker Compose (local dev)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:15
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: transcription_proxy
|
||||||
|
POSTGRES_USER: user
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- pgdata:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgresql://user:password@db:5432/transcription_proxy
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- /app/node_modules
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata:
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Deployment
|
||||||
|
|
||||||
|
This service is a good fit for deployment on AnHonestHost WHP as a containerized app,
|
||||||
|
or on a small DigitalOcean/Linode VPS. Requirements are light:
|
||||||
|
- 512MB RAM is sufficient
|
||||||
|
- Postgres can be the same instance as other services or managed (e.g., Supabase free tier)
|
||||||
|
- Needs a public domain with SSL for WebSocket (`wss://`) to work from desktop clients
|
||||||
|
|
||||||
|
Reverse proxy config (Nginx or HAProxy) should:
|
||||||
|
- Proxy HTTP → `localhost:3000`
|
||||||
|
- Pass `Upgrade` and `Connection` headers for WebSocket support
|
||||||
|
- Set `proxy_read_timeout 3600` (sessions can be long)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Implementation Order
|
||||||
|
|
||||||
|
Build and test in this sequence:
|
||||||
|
|
||||||
|
1. Project scaffold + DB connection + migrations
|
||||||
|
2. Auth (register/login/JWT) — test with curl
|
||||||
|
3. Stripe billing + webhook — test with Stripe CLI (`stripe listen`)
|
||||||
|
4. WebSocket proxy — test with a simple browser WebSocket client first
|
||||||
|
5. Usage tracking and credit decrement
|
||||||
|
6. Account/usage routes
|
||||||
|
7. Web dashboard
|
||||||
|
8. Desktop app integration (separate PR in local-transcription repo)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Key Decisions & Rationale
|
||||||
|
|
||||||
|
| Decision | Choice | Reason |
|
||||||
|
|---|---|---|
|
||||||
|
| Credits model | Prepaid | No surprise charges, simpler billing, better for irregular streamer usage |
|
||||||
|
| WebSocket library | `ws` | Lightweight, no abstraction overhead, plays well with raw binary audio |
|
||||||
|
| Auth | JWT (stateless) | Desktop app holds token locally; no session store needed |
|
||||||
|
| DB driver | `node-postgres` (pg) | No ORM overhead; schema is simple enough for raw SQL |
|
||||||
|
| Migrations | Raw SQL files | No dependency on Knex/Prisma; easy to inspect and reason about |
|
||||||
|
| Rate limiting | In-memory | Redis is overkill for this scale; single-process Node is fine initially |
|
||||||
|
| Frontend | Vanilla JS | Dashboard is simple utility UI; no framework justified |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What This Plan Does NOT Cover (Future Work)
|
||||||
|
|
||||||
|
- OAuth / social login
|
||||||
|
- Admin panel for managing users
|
||||||
|
- Refund / credit adjustment tooling
|
||||||
|
- Email verification
|
||||||
|
- Password reset flow
|
||||||
|
- Multi-language support beyond Deepgram's defaults
|
||||||
|
- Analytics / aggregated usage reporting
|
||||||
|
- Self-hosted Whisper inference as a third backend option
|
||||||
Binary file not shown.
@@ -1,19 +1,22 @@
|
|||||||
# Local Transcription for Streamers
|
# Local Transcription
|
||||||
|
|
||||||
A local speech-to-text application designed for streamers that provides real-time transcription using Whisper or similar models. Multiple users can run the application locally and sync their transcriptions to a centralized web stream that can be easily captured in OBS or other streaming software.
|
A real-time speech-to-text desktop application for streamers. Run locally on your machine with GPU or CPU, display transcriptions via OBS browser source, and optionally sync with other users through a multi-user server.
|
||||||
|
|
||||||
|
**Version 1.4.0**
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Standalone Desktop Application**: Use locally with built-in GUI display - no server required
|
- **Real-Time Transcription**: Live speech-to-text using Whisper models with minimal latency
|
||||||
- **Local Transcription**: Run Whisper (or compatible models) locally on your machine
|
- **Standalone Desktop App**: PySide6/Qt GUI that works without any server
|
||||||
- **CPU/GPU Support**: Choose between CPU or GPU processing based on your hardware
|
- **CPU & GPU Support**: Automatic detection of CUDA (NVIDIA), MPS (Apple Silicon), or CPU fallback
|
||||||
- **Real-time Processing**: Live audio transcription with minimal latency
|
- **Advanced Voice Detection**: Dual-layer VAD (WebRTC + Silero) for accurate speech detection
|
||||||
|
- **OBS Integration**: Built-in web server for browser source capture at `http://localhost:8080`
|
||||||
|
- **Multi-User Sync**: Optional Node.js server to sync transcriptions across multiple users
|
||||||
|
- **Custom Fonts**: Support for system fonts, web-safe fonts, Google Fonts, and custom font files
|
||||||
|
- **Customizable Colors**: User-configurable colors for name, text, and background
|
||||||
- **Noise Suppression**: Built-in audio preprocessing to reduce background noise
|
- **Noise Suppression**: Built-in audio preprocessing to reduce background noise
|
||||||
- **User Configuration**: Set your display name and preferences through the GUI
|
- **Auto-Updates**: Automatic update checking with release notes display
|
||||||
- **Optional Multi-user Sync**: Connect to a server to sync transcriptions with other users
|
- **Cross-Platform**: Builds available for Windows and Linux
|
||||||
- **OBS Integration**: Web-based output designed for easy browser source capture
|
|
||||||
- **Privacy-First**: All processing happens locally; only transcription text is shared
|
|
||||||
- **Customizable**: Configure model size, language, and streaming settings
|
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
@@ -27,468 +30,195 @@ uv sync
|
|||||||
uv run python main.py
|
uv run python main.py
|
||||||
```
|
```
|
||||||
|
|
||||||
### Building Standalone Executables
|
### Using Pre-Built Executables
|
||||||
|
|
||||||
To create standalone executables for distribution:
|
Download the latest release from the [releases page](https://repo.anhonesthost.net/streamer-tools/local-transcription/releases) and run the executable for your platform.
|
||||||
|
|
||||||
|
### Building from Source
|
||||||
|
|
||||||
**Linux:**
|
**Linux:**
|
||||||
```bash
|
```bash
|
||||||
./build.sh
|
./build.sh
|
||||||
|
# Output: dist/LocalTranscription/LocalTranscription
|
||||||
```
|
```
|
||||||
|
|
||||||
**Windows:**
|
**Windows:**
|
||||||
```cmd
|
```cmd
|
||||||
build.bat
|
build.bat
|
||||||
|
# Output: dist\LocalTranscription\LocalTranscription.exe
|
||||||
```
|
```
|
||||||
|
|
||||||
For detailed build instructions, see [BUILD.md](BUILD.md).
|
For detailed build instructions, see [BUILD.md](BUILD.md).
|
||||||
|
|
||||||
## Architecture Overview
|
## Usage
|
||||||
|
|
||||||
The application can run in two modes:
|
### Standalone Mode
|
||||||
|
|
||||||
### Standalone Mode (No Server Required):
|
1. Launch the application
|
||||||
1. **Desktop Application**: Captures audio, performs speech-to-text, and displays transcriptions locally in a GUI window
|
2. Select your microphone from the audio device dropdown
|
||||||
|
3. Choose a Whisper model (smaller = faster, larger = more accurate):
|
||||||
|
- `tiny.en` / `tiny` - Fastest, good for quick captions
|
||||||
|
- `base.en` / `base` - Balanced speed and accuracy
|
||||||
|
- `small.en` / `small` - Better accuracy
|
||||||
|
- `medium.en` / `medium` - High accuracy
|
||||||
|
- `large-v3` - Best accuracy (requires more resources)
|
||||||
|
4. Click **Start** to begin transcription
|
||||||
|
5. Transcriptions appear in the main window and at `http://localhost:8080`
|
||||||
|
|
||||||
### Multi-user Sync Mode (Optional):
|
### OBS Browser Source Setup
|
||||||
1. **Local Transcription Client**: Captures audio, performs speech-to-text, and sends results to the web server
|
|
||||||
2. **Centralized Web Server**: Aggregates transcriptions from multiple clients and serves a web stream
|
|
||||||
3. **Web Stream Interface**: Browser-accessible page displaying synchronized transcriptions (for OBS capture)
|
|
||||||
|
|
||||||
## Use Cases
|
1. Start the Local Transcription app
|
||||||
|
2. In OBS, add a **Browser** source
|
||||||
|
3. Set URL to `http://localhost:8080`
|
||||||
|
4. Set dimensions (e.g., 1920x300)
|
||||||
|
5. Check "Shutdown source when not visible" for performance
|
||||||
|
|
||||||
- **Multi-language Streams**: Multiple translators transcribing in different languages
|
### Multi-User Mode (Optional)
|
||||||
- **Accessibility**: Provide real-time captions for viewers
|
|
||||||
- **Collaborative Podcasts**: Multiple hosts with separate transcriptions
|
|
||||||
- **Gaming Commentary**: Track who said what in multiplayer sessions
|
|
||||||
|
|
||||||
---
|
For syncing transcriptions across multiple users (e.g., multi-host streams or translation teams):
|
||||||
|
|
||||||
## Implementation Plan
|
1. Deploy the Node.js server (see [server/nodejs/README.md](server/nodejs/README.md))
|
||||||
|
2. In the app settings, enable **Server Sync**
|
||||||
|
3. Enter the server URL (e.g., `http://your-server:3000/api/send`)
|
||||||
|
4. Set a room name and passphrase (shared with other users)
|
||||||
|
5. In OBS, use the server's display URL with your room name:
|
||||||
|
```
|
||||||
|
http://your-server:3000/display?room=YOURROOM×tamps=true&maxlines=50
|
||||||
|
```
|
||||||
|
|
||||||
### Phase 1: Standalone Desktop Application
|
## Configuration
|
||||||
|
|
||||||
**Objective**: Build a fully functional standalone transcription app with GUI that works without any server
|
Settings are stored at `~/.local-transcription/config.yaml` and can be modified through the GUI settings panel.
|
||||||
|
|
||||||
#### Components:
|
### Key Settings
|
||||||
1. **Audio Capture Module**
|
|
||||||
- Capture system audio or microphone input
|
|
||||||
- Support multiple audio sources (virtual audio cables, physical devices)
|
|
||||||
- Real-time audio buffering with configurable chunk sizes
|
|
||||||
- **Noise Suppression**: Preprocess audio to reduce background noise
|
|
||||||
- Libraries: `pyaudio`, `sounddevice`, `noisereduce`, `webrtcvad`
|
|
||||||
|
|
||||||
2. **Noise Suppression Engine**
|
| Setting | Description | Default |
|
||||||
- Real-time noise reduction using RNNoise or noisereduce
|
|---------|-------------|---------|
|
||||||
- Adjustable noise reduction strength
|
| `transcription.model` | Whisper model to use | `base.en` |
|
||||||
- Optional VAD (Voice Activity Detection) to skip silent segments
|
| `transcription.device` | Processing device (auto/cuda/cpu) | `auto` |
|
||||||
- Libraries: `noisereduce`, `rnnoise-python`, `webrtcvad`
|
| `transcription.enable_realtime_transcription` | Show preview while speaking | `false` |
|
||||||
|
| `transcription.silero_sensitivity` | VAD sensitivity (0-1, lower = more sensitive) | `0.4` |
|
||||||
|
| `transcription.post_speech_silence_duration` | Silence before finalizing (seconds) | `0.3` |
|
||||||
|
| `transcription.continuous_mode` | Fast speaker mode for quick talkers | `false` |
|
||||||
|
| `display.show_timestamps` | Show timestamps with transcriptions | `true` |
|
||||||
|
| `display.fade_after_seconds` | Fade out time (0 = never) | `10` |
|
||||||
|
| `display.font_source` | Font type (System Font/Web-Safe/Google Font/Custom File) | `System Font` |
|
||||||
|
| `web_server.port` | Local web server port | `8080` |
|
||||||
|
|
||||||
3. **Transcription Engine**
|
See [config/default_config.yaml](config/default_config.yaml) for all available options.
|
||||||
- Integrate OpenAI Whisper (or alternatives: faster-whisper, whisper.cpp)
|
|
||||||
- Support multiple model sizes (tiny, base, small, medium, large)
|
|
||||||
- CPU and GPU inference options
|
|
||||||
- Model management and automatic downloading
|
|
||||||
- Libraries: `openai-whisper`, `faster-whisper`, `torch`
|
|
||||||
|
|
||||||
4. **Device Selection**
|
|
||||||
- Auto-detect available compute devices (CPU, CUDA, MPS for Mac)
|
|
||||||
- Allow user to specify preferred device via GUI
|
|
||||||
- Graceful fallback if GPU unavailable
|
|
||||||
- Display device status and performance metrics
|
|
||||||
|
|
||||||
5. **Desktop GUI Application**
|
|
||||||
- Cross-platform GUI using PyQt6, Tkinter, or CustomTkinter
|
|
||||||
- Main transcription display window (scrolling text area)
|
|
||||||
- Settings panel for configuration
|
|
||||||
- User name input field
|
|
||||||
- Audio input device selector
|
|
||||||
- Model size selector
|
|
||||||
- CPU/GPU toggle
|
|
||||||
- Start/Stop transcription button
|
|
||||||
- Optional: System tray integration
|
|
||||||
- Libraries: `PyQt6`, `customtkinter`, or `tkinter`
|
|
||||||
|
|
||||||
6. **Local Display**
|
|
||||||
- Real-time transcription display in GUI window
|
|
||||||
- Scrolling text with timestamps
|
|
||||||
- User name/label shown with transcriptions
|
|
||||||
- Copy transcription to clipboard
|
|
||||||
- Optional: Save transcription to file (TXT, SRT, VTT)
|
|
||||||
|
|
||||||
#### Tasks:
|
|
||||||
- [ ] Set up project structure and dependencies
|
|
||||||
- [ ] Implement audio capture with device selection
|
|
||||||
- [ ] Add noise suppression and VAD preprocessing
|
|
||||||
- [ ] Integrate Whisper model loading and inference
|
|
||||||
- [ ] Add CPU/GPU device detection and selection logic
|
|
||||||
- [ ] Create real-time audio buffer processing pipeline
|
|
||||||
- [ ] Design and implement GUI layout (main window)
|
|
||||||
- [ ] Add settings panel with user name configuration
|
|
||||||
- [ ] Implement local transcription display area
|
|
||||||
- [ ] Add start/stop controls and status indicators
|
|
||||||
- [ ] Test transcription accuracy and latency
|
|
||||||
- [ ] Test noise suppression effectiveness
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Phase 2: Web Server and Sync System
|
|
||||||
|
|
||||||
**Objective**: Create a centralized server to aggregate and serve transcriptions
|
|
||||||
|
|
||||||
#### Components:
|
|
||||||
1. **Web Server**
|
|
||||||
- FastAPI or Flask-based REST API
|
|
||||||
- WebSocket support for real-time updates
|
|
||||||
- User/client registration and management
|
|
||||||
- Libraries: `fastapi`, `uvicorn`, `websockets`
|
|
||||||
|
|
||||||
2. **Transcription Aggregator**
|
|
||||||
- Receive transcription chunks from multiple clients
|
|
||||||
- Associate transcriptions with user IDs/names
|
|
||||||
- Timestamp management and synchronization
|
|
||||||
- Buffer management for smooth streaming
|
|
||||||
|
|
||||||
3. **Database/Storage** (Optional)
|
|
||||||
- Store transcription history (SQLite for simplicity)
|
|
||||||
- Session management
|
|
||||||
- Export functionality (SRT, VTT, TXT formats)
|
|
||||||
|
|
||||||
#### API Endpoints:
|
|
||||||
- `POST /api/register` - Register a new client
|
|
||||||
- `POST /api/transcription` - Submit transcription chunk
|
|
||||||
- `WS /api/stream` - WebSocket for real-time transcription stream
|
|
||||||
- `GET /stream` - Web page for OBS browser source
|
|
||||||
|
|
||||||
#### Tasks:
|
|
||||||
- [ ] Set up FastAPI server with CORS support
|
|
||||||
- [ ] Implement WebSocket handler for real-time streaming
|
|
||||||
- [ ] Create client registration system
|
|
||||||
- [ ] Build transcription aggregation logic
|
|
||||||
- [ ] Add timestamp synchronization
|
|
||||||
- [ ] Create data models for clients and transcriptions
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Phase 3: Client-Server Communication (Optional Multi-user Mode)
|
|
||||||
|
|
||||||
**Objective**: Add optional server connectivity to enable multi-user transcription sync
|
|
||||||
|
|
||||||
#### Components:
|
|
||||||
1. **HTTP/WebSocket Client**
|
|
||||||
- Register client with server on startup
|
|
||||||
- Send transcription chunks as they're generated
|
|
||||||
- Handle connection drops and reconnection
|
|
||||||
- Libraries: `requests`, `websockets`
|
|
||||||
|
|
||||||
2. **Configuration System**
|
|
||||||
- Config file for server URL, API keys, user settings
|
|
||||||
- Model preferences (size, language)
|
|
||||||
- Audio input settings
|
|
||||||
- Format: YAML or JSON
|
|
||||||
|
|
||||||
3. **Status Monitoring**
|
|
||||||
- Connection status indicator
|
|
||||||
- Transcription queue health
|
|
||||||
- Error handling and logging
|
|
||||||
|
|
||||||
#### Tasks:
|
|
||||||
- [ ] Add "Enable Server Sync" toggle to GUI
|
|
||||||
- [ ] Add server URL configuration field in settings
|
|
||||||
- [ ] Implement WebSocket client for sending transcriptions
|
|
||||||
- [ ] Add configuration file support (YAML/JSON)
|
|
||||||
- [ ] Create connection management with auto-reconnect
|
|
||||||
- [ ] Add local logging and error handling
|
|
||||||
- [ ] Add server connection status indicator to GUI
|
|
||||||
- [ ] Allow app to function normally if server is unavailable
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Phase 4: Web Stream Interface (OBS Integration)
|
|
||||||
|
|
||||||
**Objective**: Create a web page that displays synchronized transcriptions for OBS
|
|
||||||
|
|
||||||
#### Components:
|
|
||||||
1. **Web Frontend**
|
|
||||||
- HTML/CSS/JavaScript page for displaying transcriptions
|
|
||||||
- Responsive design with customizable styling
|
|
||||||
- Auto-scroll with configurable retention window
|
|
||||||
- Libraries: Vanilla JS or lightweight framework (Alpine.js, htmx)
|
|
||||||
|
|
||||||
2. **Styling Options**
|
|
||||||
- Customizable fonts, colors, sizes
|
|
||||||
- Background transparency for OBS chroma key
|
|
||||||
- User name/ID display options
|
|
||||||
- Timestamp display (optional)
|
|
||||||
|
|
||||||
3. **Display Modes**
|
|
||||||
- Scrolling captions (like live TV captions)
|
|
||||||
- Multi-user panel view (separate sections per user)
|
|
||||||
- Overlay mode (minimal UI for transparency)
|
|
||||||
|
|
||||||
#### Tasks:
|
|
||||||
- [ ] Create HTML template for transcription display
|
|
||||||
- [ ] Implement WebSocket client in JavaScript
|
|
||||||
- [ ] Add CSS styling with OBS-friendly transparency
|
|
||||||
- [ ] Create customization controls (URL parameters or UI)
|
|
||||||
- [ ] Test with OBS browser source
|
|
||||||
- [ ] Add configurable retention/scroll behavior
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Phase 5: Advanced Features
|
|
||||||
|
|
||||||
**Objective**: Enhance functionality and user experience
|
|
||||||
|
|
||||||
#### Features:
|
|
||||||
1. **Language Detection**
|
|
||||||
- Auto-detect spoken language
|
|
||||||
- Multi-language support in single stream
|
|
||||||
- Language selector in GUI
|
|
||||||
|
|
||||||
2. **Speaker Diarization** (Optional)
|
|
||||||
- Identify different speakers
|
|
||||||
- Label transcriptions by speaker
|
|
||||||
- Useful for multi-host streams
|
|
||||||
|
|
||||||
3. **Profanity Filtering**
|
|
||||||
- Optional word filtering/replacement
|
|
||||||
- Customizable filter lists
|
|
||||||
- Toggle in GUI settings
|
|
||||||
|
|
||||||
4. **Advanced Noise Profiles**
|
|
||||||
- Save and load custom noise profiles
|
|
||||||
- Adaptive noise suppression
|
|
||||||
- Different profiles for different environments
|
|
||||||
|
|
||||||
5. **Export Functionality**
|
|
||||||
- Save transcriptions in multiple formats (TXT, SRT, VTT, JSON)
|
|
||||||
- Export button in GUI
|
|
||||||
- Automatic session saving
|
|
||||||
|
|
||||||
6. **Hotkey Support**
|
|
||||||
- Global hotkeys to start/stop transcription
|
|
||||||
- Mute/unmute hotkey
|
|
||||||
- Quick save hotkey
|
|
||||||
|
|
||||||
7. **Docker Support**
|
|
||||||
- Containerized server deployment
|
|
||||||
- Docker Compose for easy multi-component setup
|
|
||||||
- Pre-built images for easy deployment
|
|
||||||
|
|
||||||
8. **Themes and Customization**
|
|
||||||
- Dark/light theme toggle
|
|
||||||
- Customizable font sizes and colors for display
|
|
||||||
- OBS-friendly transparent overlay mode
|
|
||||||
|
|
||||||
#### Tasks:
|
|
||||||
- [ ] Add language detection and multi-language support
|
|
||||||
- [ ] Implement speaker diarization
|
|
||||||
- [ ] Create optional profanity filter
|
|
||||||
- [ ] Add export functionality (SRT, VTT, plain text, JSON)
|
|
||||||
- [ ] Implement global hotkey support
|
|
||||||
- [ ] Create Docker containers for server component
|
|
||||||
- [ ] Add theme customization options
|
|
||||||
- [ ] Create advanced noise profile management
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Technology Stack
|
|
||||||
|
|
||||||
### Local Client:
|
|
||||||
- **Python 3.9+**
|
|
||||||
- **GUI**: PyQt6 / CustomTkinter / tkinter
|
|
||||||
- **Audio**: PyAudio / sounddevice
|
|
||||||
- **Noise Suppression**: noisereduce / rnnoise-python
|
|
||||||
- **VAD**: webrtcvad
|
|
||||||
- **ML Framework**: PyTorch (for Whisper)
|
|
||||||
- **Transcription**: openai-whisper / faster-whisper
|
|
||||||
- **Networking**: websockets, requests (optional for server sync)
|
|
||||||
- **Config**: PyYAML / json
|
|
||||||
|
|
||||||
### Server:
|
|
||||||
- **Backend**: FastAPI / Flask
|
|
||||||
- **WebSocket**: python-websockets / FastAPI WebSockets
|
|
||||||
- **Server**: Uvicorn / Gunicorn
|
|
||||||
- **Database** (optional): SQLite / PostgreSQL
|
|
||||||
- **CORS**: fastapi-cors
|
|
||||||
|
|
||||||
### Web Interface:
|
|
||||||
- **Frontend**: HTML5, CSS3, JavaScript (ES6+)
|
|
||||||
- **Real-time**: WebSocket API
|
|
||||||
- **Styling**: CSS Grid/Flexbox for layout
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
local-transcription/
|
local-transcription/
|
||||||
| |||||||