Compare commits
46
Commits
58faa83cb3
...
v0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a6ea84637 | ||
|
|
011ff4e178 | ||
|
|
d2d111a5c7 | ||
|
|
9250ff25c3 | ||
|
|
9033881274 | ||
|
|
1ed34e0bbb | ||
|
|
b7a00af2e0 | ||
|
|
2d0d4cfc50 | ||
|
|
b99613f452 | ||
|
|
ec7e364165 | ||
|
|
a0cb034ab5 | ||
|
|
52d7d06d84 | ||
|
|
462a4b80f6 | ||
|
|
12869e3757 | ||
|
|
bf6fb471d9 | ||
|
|
50baa7284e | ||
|
|
a3c39a2069 | ||
|
|
f023bf02a9 | ||
|
|
caf854ccbb | ||
|
|
b0d566f2d6 | ||
|
|
a65ac439dd | ||
|
|
b8d70539ec | ||
|
|
760b5dc90e | ||
|
|
9cec3c3858 | ||
|
|
4f19ae5287 | ||
|
|
4701b578fc | ||
|
|
5b7f30c4b2 | ||
|
|
cc24511b87 | ||
|
|
23c013bbac | ||
|
|
34797b295d | ||
|
|
666e6c5b25 | ||
|
|
c8754076f4 | ||
|
|
f674b63ca9 | ||
|
|
66a9033a64 | ||
|
|
3a97aa2831 | ||
|
|
882aa147c7 | ||
|
|
67fc23e8aa | ||
|
|
727107323c | ||
|
|
27b705b5b6 | ||
|
|
8e7d21d22b | ||
|
|
61caa07e4c | ||
|
|
331003d1c9 | ||
|
|
4a4402f71a | ||
|
|
3e7671453a | ||
|
|
d8ed77b786 | ||
|
|
09d7c2064f |
@@ -1,136 +0,0 @@
|
|||||||
name: Build & Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
tags: ["v*"]
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
env:
|
|
||||||
PYTHON_VERSION: "3.11"
|
|
||||||
NODE_VERSION: "20"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-sidecar:
|
|
||||||
name: Build sidecar (${{ matrix.target }})
|
|
||||||
runs-on: ${{ matrix.runner }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- runner: ubuntu-latest
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
platform: linux
|
|
||||||
- runner: windows-latest
|
|
||||||
target: x86_64-pc-windows-msvc
|
|
||||||
platform: windows
|
|
||||||
- runner: macos-latest
|
|
||||||
target: aarch64-apple-darwin
|
|
||||||
platform: macos
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
- name: Build sidecar
|
|
||||||
working-directory: python
|
|
||||||
run: python build_sidecar.py --cpu-only
|
|
||||||
|
|
||||||
- name: Upload sidecar artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sidecar-${{ matrix.target }}
|
|
||||||
path: python/dist/voice-to-notes-sidecar/
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
build-tauri:
|
|
||||||
name: Build app (${{ matrix.target }})
|
|
||||||
needs: build-sidecar
|
|
||||||
runs-on: ${{ matrix.runner }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- runner: ubuntu-latest
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
platform: linux
|
|
||||||
- runner: windows-latest
|
|
||||||
target: x86_64-pc-windows-msvc
|
|
||||||
platform: windows
|
|
||||||
- runner: macos-latest
|
|
||||||
target: aarch64-apple-darwin
|
|
||||||
platform: macos
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
|
||||||
# Note: 'cache: npm' requires the Gitea instance to have
|
|
||||||
# Actions cache configured. Remove this if caching is unavailable.
|
|
||||||
cache: npm
|
|
||||||
|
|
||||||
- name: Install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Install system dependencies (Linux)
|
|
||||||
if: matrix.platform == 'linux'
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
|
|
||||||
|
|
||||||
- name: Download sidecar artifact
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sidecar-${{ matrix.target }}
|
|
||||||
path: src-tauri/binaries/
|
|
||||||
|
|
||||||
- name: Make sidecar executable (Unix)
|
|
||||||
if: matrix.platform != 'windows'
|
|
||||||
run: chmod +x src-tauri/binaries/voice-to-notes-sidecar-${{ matrix.target }}
|
|
||||||
|
|
||||||
- name: Install npm dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Build Tauri app
|
|
||||||
run: npm run tauri build
|
|
||||||
env:
|
|
||||||
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
|
|
||||||
TAURI_CONFIG: '{"bundle":{"externalBin":["binaries/voice-to-notes-sidecar"]}}'
|
|
||||||
|
|
||||||
- name: Upload app artifacts (Linux)
|
|
||||||
if: matrix.platform == 'linux'
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-${{ matrix.target }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/release/bundle/deb/*.deb
|
|
||||||
src-tauri/target/release/bundle/appimage/*.AppImage
|
|
||||||
retention-days: 30
|
|
||||||
|
|
||||||
- name: Upload app artifacts (Windows)
|
|
||||||
if: matrix.platform == 'windows'
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-${{ matrix.target }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/release/bundle/msi/*.msi
|
|
||||||
src-tauri/target/release/bundle/nsis/*.exe
|
|
||||||
retention-days: 30
|
|
||||||
|
|
||||||
- name: Upload app artifacts (macOS)
|
|
||||||
if: matrix.platform == 'macos'
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-${{ matrix.target }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/release/bundle/dmg/*.dmg
|
|
||||||
src-tauri/target/release/bundle/macos/*.app
|
|
||||||
retention-days: 30
|
|
||||||
@@ -0,0 +1,395 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
bump-version:
|
||||||
|
name: Bump version and tag
|
||||||
|
# Skip if this is a version-bump commit (avoid infinite loop)
|
||||||
|
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 (match version = "x.y.z" in [package] section)
|
||||||
|
sed -i "s/^version = \"${CURRENT}\"/version = \"${NEW_VERSION}\"/" src-tauri/Cargo.toml
|
||||||
|
|
||||||
|
# Update python/pyproject.toml
|
||||||
|
sed -i "s/^version = \".*\"/version = \"${NEW_VERSION}\"/" python/pyproject.toml
|
||||||
|
|
||||||
|
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 python/pyproject.toml
|
||||||
|
git commit -m "chore: bump version to ${NEW_VERSION} [skip ci]"
|
||||||
|
git tag "v${NEW_VERSION}"
|
||||||
|
|
||||||
|
# Push using token for authentication
|
||||||
|
REMOTE_URL=$(git remote get-url origin | sed "s|://|://gitea-actions:${BUILD_TOKEN}@|")
|
||||||
|
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="Voice to Notes ${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 (Linux)
|
||||||
|
needs: bump-version
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: "3.11"
|
||||||
|
NODE_VERSION: "20"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-version.outputs.tag }}
|
||||||
|
|
||||||
|
# ── Python sidecar ──
|
||||||
|
- 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: Install ffmpeg
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y ffmpeg
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
|
- name: Build sidecar
|
||||||
|
working-directory: python
|
||||||
|
run: uv run --python ${{ env.PYTHON_VERSION }} python build_sidecar.py --cpu-only
|
||||||
|
|
||||||
|
- name: Package sidecar for Tauri
|
||||||
|
run: |
|
||||||
|
cd python/dist/voice-to-notes-sidecar && zip -r ../../../src-tauri/sidecar.zip .
|
||||||
|
|
||||||
|
# ── Tauri app ──
|
||||||
|
- 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 install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf xdg-utils
|
||||||
|
|
||||||
|
- name: Install npm dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build Tauri app
|
||||||
|
run: npm run tauri build
|
||||||
|
|
||||||
|
# ── Release ──
|
||||||
|
- 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 }}"
|
||||||
|
RELEASE_NAME="Voice to Notes ${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" | 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 (Windows)
|
||||||
|
needs: bump-version
|
||||||
|
runs-on: windows-latest
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: "3.11"
|
||||||
|
NODE_VERSION: "20"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-version.outputs.tag }}
|
||||||
|
|
||||||
|
# ── Python sidecar ──
|
||||||
|
- 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: Install ffmpeg
|
||||||
|
shell: powershell
|
||||||
|
run: choco install ffmpeg -y
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
shell: powershell
|
||||||
|
run: uv python install ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
|
- name: Build sidecar
|
||||||
|
shell: powershell
|
||||||
|
working-directory: python
|
||||||
|
run: uv run --python ${{ env.PYTHON_VERSION }} python build_sidecar.py --cpu-only
|
||||||
|
|
||||||
|
- name: Package sidecar for Tauri
|
||||||
|
shell: powershell
|
||||||
|
run: |
|
||||||
|
Compress-Archive -Path python\dist\voice-to-notes-sidecar\* -DestinationPath src-tauri\sidecar.zip
|
||||||
|
|
||||||
|
# ── Tauri app ──
|
||||||
|
- 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
|
||||||
|
|
||||||
|
# ── Release ──
|
||||||
|
- 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 }}"
|
||||||
|
$RELEASE_NAME = "Voice to Notes ${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 {}
|
||||||
|
|
||||||
|
# Use curl for streaming upload (Invoke-RestMethod fails on large files)
|
||||||
|
$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" `
|
||||||
|
--data-binary "@$($_.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 (macOS)
|
||||||
|
needs: bump-version
|
||||||
|
runs-on: macos-latest
|
||||||
|
env:
|
||||||
|
PYTHON_VERSION: "3.11"
|
||||||
|
NODE_VERSION: "20"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: ${{ needs.bump-version.outputs.tag }}
|
||||||
|
|
||||||
|
# ── Python sidecar ──
|
||||||
|
- 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: Install ffmpeg
|
||||||
|
run: brew install ffmpeg
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
run: uv python install ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
|
- name: Build sidecar
|
||||||
|
working-directory: python
|
||||||
|
run: uv run --python ${{ env.PYTHON_VERSION }} python build_sidecar.py --cpu-only
|
||||||
|
|
||||||
|
- name: Package sidecar for Tauri
|
||||||
|
run: |
|
||||||
|
cd python/dist/voice-to-notes-sidecar && zip -r ../../../src-tauri/sidecar.zip .
|
||||||
|
|
||||||
|
# ── Tauri app ──
|
||||||
|
- 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
|
||||||
|
|
||||||
|
# ── Release ──
|
||||||
|
- 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 }}"
|
||||||
|
RELEASE_NAME="Voice to Notes ${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
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
name: Build & Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
tags: ["v*"]
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
env:
|
|
||||||
PYTHON_VERSION: "3.11"
|
|
||||||
NODE_VERSION: "20"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-sidecar:
|
|
||||||
name: Build sidecar (${{ matrix.target }})
|
|
||||||
runs-on: ${{ matrix.runner }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- runner: ubuntu-20.04
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
platform: linux
|
|
||||||
- runner: windows-latest
|
|
||||||
target: x86_64-pc-windows-msvc
|
|
||||||
platform: windows
|
|
||||||
- runner: macos-13
|
|
||||||
target: x86_64-apple-darwin
|
|
||||||
platform: macos-intel
|
|
||||||
- runner: macos-14
|
|
||||||
target: aarch64-apple-darwin
|
|
||||||
platform: macos-arm
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: ${{ env.PYTHON_VERSION }}
|
|
||||||
|
|
||||||
- name: Build sidecar
|
|
||||||
working-directory: python
|
|
||||||
run: python build_sidecar.py --cpu-only
|
|
||||||
|
|
||||||
- name: Upload sidecar artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sidecar-${{ matrix.target }}
|
|
||||||
path: python/dist/voice-to-notes-sidecar/
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
build-tauri:
|
|
||||||
name: Build app (${{ matrix.target }})
|
|
||||||
needs: build-sidecar
|
|
||||||
runs-on: ${{ matrix.runner }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- runner: ubuntu-20.04
|
|
||||||
target: x86_64-unknown-linux-gnu
|
|
||||||
platform: linux
|
|
||||||
- runner: windows-latest
|
|
||||||
target: x86_64-pc-windows-msvc
|
|
||||||
platform: windows
|
|
||||||
- runner: macos-13
|
|
||||||
target: x86_64-apple-darwin
|
|
||||||
platform: macos-intel
|
|
||||||
- runner: macos-14
|
|
||||||
target: aarch64-apple-darwin
|
|
||||||
platform: macos-arm
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
|
||||||
cache: npm
|
|
||||||
|
|
||||||
- name: Install Rust stable
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Install system dependencies (Linux)
|
|
||||||
if: matrix.platform == 'linux'
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
|
|
||||||
|
|
||||||
- name: Download sidecar artifact
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sidecar-${{ matrix.target }}
|
|
||||||
path: src-tauri/binaries/
|
|
||||||
|
|
||||||
- name: Make sidecar executable (Unix)
|
|
||||||
if: matrix.platform != 'windows'
|
|
||||||
run: chmod +x src-tauri/binaries/voice-to-notes-sidecar-${{ matrix.target }}
|
|
||||||
|
|
||||||
- name: Install npm dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Build Tauri app
|
|
||||||
run: npm run tauri build
|
|
||||||
env:
|
|
||||||
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
|
|
||||||
TAURI_CONFIG: '{"bundle":{"externalBin":["binaries/voice-to-notes-sidecar"]}}'
|
|
||||||
|
|
||||||
- name: Upload app artifacts (Linux)
|
|
||||||
if: matrix.platform == 'linux'
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-${{ matrix.target }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/release/bundle/deb/*.deb
|
|
||||||
src-tauri/target/release/bundle/appimage/*.AppImage
|
|
||||||
retention-days: 30
|
|
||||||
|
|
||||||
- name: Upload app artifacts (Windows)
|
|
||||||
if: matrix.platform == 'windows'
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-${{ matrix.target }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/release/bundle/msi/*.msi
|
|
||||||
src-tauri/target/release/bundle/nsis/*.exe
|
|
||||||
retention-days: 30
|
|
||||||
|
|
||||||
- name: Upload app artifacts (macOS)
|
|
||||||
if: startsWith(matrix.platform, 'macos')
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-${{ matrix.target }}
|
|
||||||
path: |
|
|
||||||
src-tauri/target/release/bundle/dmg/*.dmg
|
|
||||||
src-tauri/target/release/bundle/macos/*.app
|
|
||||||
retention-days: 30
|
|
||||||
@@ -50,5 +50,6 @@ Thumbs.db
|
|||||||
# Sidecar build artifacts
|
# Sidecar build artifacts
|
||||||
src-tauri/binaries/*
|
src-tauri/binaries/*
|
||||||
!src-tauri/binaries/.gitkeep
|
!src-tauri/binaries/.gitkeep
|
||||||
|
src-tauri/sidecar.zip
|
||||||
python/dist/
|
python/dist/
|
||||||
python/build/
|
python/build/
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "voice-to-notes",
|
"name": "voice-to-notes",
|
||||||
"version": "0.1.0",
|
"version": "0.2.3",
|
||||||
"description": "Desktop app for transcribing audio/video with speaker identification",
|
"description": "Desktop app for transcribing audio/video with speaker identification",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+45
-15
@@ -59,41 +59,72 @@ def get_target_triple() -> str:
|
|||||||
return f"{arch}-unknown-{system}"
|
return f"{arch}-unknown-{system}"
|
||||||
|
|
||||||
|
|
||||||
|
def _has_uv() -> bool:
|
||||||
|
"""Check if uv is available."""
|
||||||
|
try:
|
||||||
|
subprocess.run(["uv", "--version"], capture_output=True, check=True)
|
||||||
|
return True
|
||||||
|
except (FileNotFoundError, subprocess.CalledProcessError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def create_venv_and_install(cpu_only: bool) -> Path:
|
def create_venv_and_install(cpu_only: bool) -> Path:
|
||||||
"""Create a fresh venv and install dependencies."""
|
"""Create a fresh venv and install dependencies.
|
||||||
|
|
||||||
|
Uses uv if available (much faster), falls back to standard venv + pip.
|
||||||
|
"""
|
||||||
venv_dir = BUILD_DIR / "sidecar-venv"
|
venv_dir = BUILD_DIR / "sidecar-venv"
|
||||||
if venv_dir.exists():
|
if venv_dir.exists():
|
||||||
shutil.rmtree(venv_dir)
|
shutil.rmtree(venv_dir)
|
||||||
|
|
||||||
|
use_uv = _has_uv()
|
||||||
|
|
||||||
|
if use_uv:
|
||||||
|
print(f"[build] Creating venv with uv at {venv_dir}")
|
||||||
|
subprocess.run(
|
||||||
|
["uv", "venv", "--python", f"{sys.version_info.major}.{sys.version_info.minor}",
|
||||||
|
str(venv_dir)],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
print(f"[build] Creating venv at {venv_dir}")
|
print(f"[build] Creating venv at {venv_dir}")
|
||||||
subprocess.run([sys.executable, "-m", "venv", str(venv_dir)], check=True)
|
subprocess.run([sys.executable, "-m", "venv", str(venv_dir)], check=True)
|
||||||
|
|
||||||
# Determine pip and python paths inside venv
|
# Determine python path inside venv
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
pip = str(venv_dir / "Scripts" / "pip")
|
python = str(venv_dir / "Scripts" / "python.exe")
|
||||||
python = str(venv_dir / "Scripts" / "python")
|
|
||||||
else:
|
else:
|
||||||
pip = str(venv_dir / "bin" / "pip")
|
|
||||||
python = str(venv_dir / "bin" / "python")
|
python = str(venv_dir / "bin" / "python")
|
||||||
|
|
||||||
# Upgrade pip
|
def pip_install(*args: str) -> None:
|
||||||
subprocess.run([pip, "install", "--upgrade", "pip"], check=True)
|
"""Install packages. Pass package names and flags only, not 'install'."""
|
||||||
|
if use_uv:
|
||||||
|
# Use --python with the venv directory (not the python binary) for uv
|
||||||
|
subprocess.run(
|
||||||
|
["uv", "pip", "install", "--python", str(venv_dir), *args],
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
subprocess.run([python, "-m", "pip", "install", *args], check=True)
|
||||||
|
|
||||||
|
if not use_uv:
|
||||||
|
# Upgrade pip (uv doesn't need this)
|
||||||
|
pip_install("--upgrade", "pip", "setuptools", "wheel")
|
||||||
|
|
||||||
# Install torch (CPU-only to avoid bundling ~2GB of CUDA libs)
|
# Install torch (CPU-only to avoid bundling ~2GB of CUDA libs)
|
||||||
if cpu_only:
|
if cpu_only:
|
||||||
print("[build] Installing PyTorch (CPU-only)")
|
print("[build] Installing PyTorch (CPU-only)")
|
||||||
subprocess.run(
|
pip_install(
|
||||||
[pip, "install", "torch", "torchaudio",
|
"torch", "torchaudio",
|
||||||
"--index-url", "https://download.pytorch.org/whl/cpu"],
|
"--index-url", "https://download.pytorch.org/whl/cpu",
|
||||||
check=True,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("[build] Installing PyTorch (default, may include CUDA)")
|
print("[build] Installing PyTorch (default, may include CUDA)")
|
||||||
subprocess.run([pip, "install", "torch", "torchaudio"], check=True)
|
pip_install("torch", "torchaudio")
|
||||||
|
|
||||||
# Install project and dev deps (includes pyinstaller)
|
# Install project and dev deps (includes pyinstaller)
|
||||||
print("[build] Installing project dependencies")
|
print("[build] Installing project dependencies")
|
||||||
subprocess.run([pip, "install", "-e", f"{SCRIPT_DIR}[dev]"], check=True)
|
pip_install("-e", f"{SCRIPT_DIR}[dev]")
|
||||||
|
|
||||||
return Path(python)
|
return Path(python)
|
||||||
|
|
||||||
@@ -205,10 +236,9 @@ def main() -> None:
|
|||||||
python = create_venv_and_install(cpu_only)
|
python = create_venv_and_install(cpu_only)
|
||||||
output_dir = run_pyinstaller(python)
|
output_dir = run_pyinstaller(python)
|
||||||
download_ffmpeg(output_dir)
|
download_ffmpeg(output_dir)
|
||||||
rename_binary(output_dir, target_triple)
|
|
||||||
|
|
||||||
print(f"\n[build] Done! Sidecar built at: {output_dir}")
|
print(f"\n[build] Done! Sidecar built at: {output_dir}")
|
||||||
print(f"[build] Copy contents to src-tauri/binaries/ for Tauri bundling")
|
print(f"[build] Copy directory to src-tauri/sidecar/ for Tauri resource bundling")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "voice-to-notes"
|
name = "voice-to-notes"
|
||||||
version = "0.1.0"
|
version = "0.2.3"
|
||||||
description = "Python sidecar for Voice to Notes — transcription, diarization, and AI services"
|
description = "Python sidecar for Voice to Notes — transcription, diarization, and AI services"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "voice-to-notes"
|
name = "voice-to-notes"
|
||||||
version = "0.1.0"
|
version = "0.2.3"
|
||||||
description = "Voice to Notes — desktop transcription with speaker identification"
|
description = "Voice to Notes — desktop transcription with speaker identification"
|
||||||
authors = ["Voice to Notes Contributors"]
|
authors = ["Voice to Notes Contributors"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@@ -20,6 +20,7 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
rusqlite = { version = "0.31", features = ["bundled"] }
|
rusqlite = { version = "0.31", features = ["bundled"] }
|
||||||
uuid = { version = "1", features = ["v4", "serde"] }
|
uuid = { version = "1", features = ["v4", "serde"] }
|
||||||
|
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
tauri-plugin-dialog = "2.6.0"
|
tauri-plugin-dialog = "2.6.0"
|
||||||
|
|||||||
@@ -1,3 +1,21 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
|
// Ensure sidecar.zip exists so tauri-build doesn't fail.
|
||||||
|
// CI replaces this placeholder with the real PyInstaller sidecar archive.
|
||||||
|
let zip_path = std::path::Path::new("sidecar.zip");
|
||||||
|
if !zip_path.exists() {
|
||||||
|
// Minimal valid zip (empty archive): end-of-central-directory record
|
||||||
|
let empty_zip: [u8; 22] = [
|
||||||
|
0x50, 0x4b, 0x05, 0x06, // EOCD signature
|
||||||
|
0x00, 0x00, // disk number
|
||||||
|
0x00, 0x00, // disk with central dir
|
||||||
|
0x00, 0x00, // entries on this disk
|
||||||
|
0x00, 0x00, // total entries
|
||||||
|
0x00, 0x00, 0x00, 0x00, // central dir size
|
||||||
|
0x00, 0x00, 0x00, 0x00, // central dir offset
|
||||||
|
0x00, 0x00, // comment length
|
||||||
|
];
|
||||||
|
std::fs::write(zip_path, empty_zip).expect("Failed to create placeholder sidecar.zip");
|
||||||
|
}
|
||||||
|
|
||||||
tauri_build::build()
|
tauri_build::build()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,110 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fs;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
use crate::db::models::Project;
|
use crate::db::models::Project;
|
||||||
use crate::db::queries;
|
use crate::db::queries;
|
||||||
use crate::state::AppState;
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
// ── File-based project types ────────────────────────────────────
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct ProjectFile {
|
||||||
|
pub version: u32,
|
||||||
|
pub name: String,
|
||||||
|
pub audio_file: String,
|
||||||
|
pub created_at: String,
|
||||||
|
pub segments: Vec<ProjectFileSegment>,
|
||||||
|
pub speakers: Vec<ProjectFileSpeaker>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct ProjectFileSegment {
|
||||||
|
pub text: String,
|
||||||
|
pub start_ms: i64,
|
||||||
|
pub end_ms: i64,
|
||||||
|
pub speaker: Option<String>,
|
||||||
|
pub is_edited: bool,
|
||||||
|
pub words: Vec<ProjectFileWord>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct ProjectFileWord {
|
||||||
|
pub word: String,
|
||||||
|
pub start_ms: i64,
|
||||||
|
pub end_ms: i64,
|
||||||
|
pub confidence: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct ProjectFileSpeaker {
|
||||||
|
pub label: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
|
pub color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Input types for save_project_transcript ──────────────────────
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct WordInput {
|
||||||
|
pub word: String,
|
||||||
|
pub start_ms: i64,
|
||||||
|
pub end_ms: i64,
|
||||||
|
pub confidence: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct SegmentInput {
|
||||||
|
pub text: String,
|
||||||
|
pub start_ms: i64,
|
||||||
|
pub end_ms: i64,
|
||||||
|
pub speaker: Option<String>, // speaker label, not id
|
||||||
|
pub words: Vec<WordInput>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct SpeakerInput {
|
||||||
|
pub label: String,
|
||||||
|
pub color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Output types for load_project_transcript ─────────────────────
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct WordOutput {
|
||||||
|
pub word: String,
|
||||||
|
pub start_ms: i64,
|
||||||
|
pub end_ms: i64,
|
||||||
|
pub confidence: Option<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct SegmentOutput {
|
||||||
|
pub id: String,
|
||||||
|
pub text: String,
|
||||||
|
pub start_ms: i64,
|
||||||
|
pub end_ms: i64,
|
||||||
|
pub speaker: Option<String>, // speaker label
|
||||||
|
pub words: Vec<WordOutput>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct SpeakerOutput {
|
||||||
|
pub id: String,
|
||||||
|
pub label: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
|
pub color: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct ProjectTranscript {
|
||||||
|
pub file_path: String,
|
||||||
|
pub segments: Vec<SegmentOutput>,
|
||||||
|
pub speakers: Vec<SpeakerOutput>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Commands ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn create_project(name: String, state: State<AppState>) -> Result<Project, String> {
|
pub fn create_project(name: String, state: State<AppState>) -> Result<Project, String> {
|
||||||
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
||||||
@@ -21,3 +122,176 @@ pub fn list_projects(state: State<AppState>) -> Result<Vec<Project>, String> {
|
|||||||
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
||||||
queries::list_projects(&conn).map_err(|e| e.to_string())
|
queries::list_projects(&conn).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn delete_project(id: String, state: State<AppState>) -> Result<(), String> {
|
||||||
|
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
||||||
|
queries::delete_project(&conn, &id).map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn update_segment(
|
||||||
|
segment_id: String,
|
||||||
|
new_text: String,
|
||||||
|
state: State<AppState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
||||||
|
queries::update_segment_text(&conn, &segment_id, &new_text).map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn save_project_transcript(
|
||||||
|
project_id: String,
|
||||||
|
file_path: String,
|
||||||
|
segments: Vec<SegmentInput>,
|
||||||
|
speakers: Vec<SpeakerInput>,
|
||||||
|
state: State<AppState>,
|
||||||
|
) -> Result<Project, String> {
|
||||||
|
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// 1. Create media file entry
|
||||||
|
let media_file =
|
||||||
|
queries::create_media_file(&conn, &project_id, &file_path).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// 2. Create speaker entries and build label -> id map
|
||||||
|
let mut speaker_map = std::collections::HashMap::new();
|
||||||
|
for speaker_input in &speakers {
|
||||||
|
let speaker = queries::create_speaker(
|
||||||
|
&conn,
|
||||||
|
&project_id,
|
||||||
|
&speaker_input.label,
|
||||||
|
Some(&speaker_input.color),
|
||||||
|
)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
speaker_map.insert(speaker_input.label.clone(), speaker.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Create segments with words
|
||||||
|
for (index, seg_input) in segments.iter().enumerate() {
|
||||||
|
let speaker_id = seg_input
|
||||||
|
.speaker
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|label| speaker_map.get(label));
|
||||||
|
|
||||||
|
let segment = queries::create_segment(
|
||||||
|
&conn,
|
||||||
|
&project_id,
|
||||||
|
&media_file.id,
|
||||||
|
speaker_id.map(|s| s.as_str()),
|
||||||
|
seg_input.start_ms,
|
||||||
|
seg_input.end_ms,
|
||||||
|
&seg_input.text,
|
||||||
|
index as i32,
|
||||||
|
)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// Create words for this segment
|
||||||
|
for (word_index, word_input) in seg_input.words.iter().enumerate() {
|
||||||
|
queries::create_word(
|
||||||
|
&conn,
|
||||||
|
&segment.id,
|
||||||
|
&word_input.word,
|
||||||
|
word_input.start_ms,
|
||||||
|
word_input.end_ms,
|
||||||
|
Some(word_input.confidence),
|
||||||
|
word_index as i32,
|
||||||
|
)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Return updated project info
|
||||||
|
queries::get_project(&conn, &project_id)
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.ok_or_else(|| "Project not found".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn load_project_transcript(
|
||||||
|
project_id: String,
|
||||||
|
state: State<AppState>,
|
||||||
|
) -> Result<Option<ProjectTranscript>, String> {
|
||||||
|
let conn = state.db.lock().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// 1. Get media files for the project
|
||||||
|
let media_files =
|
||||||
|
queries::get_media_files_for_project(&conn, &project_id).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
let media_file = match media_files.first() {
|
||||||
|
Some(mf) => mf,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. Get speakers for the project and build id -> label map
|
||||||
|
let speakers =
|
||||||
|
queries::get_speakers_for_project(&conn, &project_id).map_err(|e| e.to_string())?;
|
||||||
|
let speaker_label_map: std::collections::HashMap<String, String> = speakers
|
||||||
|
.iter()
|
||||||
|
.map(|s| (s.id.clone(), s.label.clone()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// 3. Get segments for the media file
|
||||||
|
let db_segments =
|
||||||
|
queries::get_segments_for_media(&conn, &media_file.id).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
// 4. Build output segments with nested words
|
||||||
|
let mut segment_outputs = Vec::with_capacity(db_segments.len());
|
||||||
|
for seg in &db_segments {
|
||||||
|
let words = queries::get_words_for_segment(&conn, &seg.id).map_err(|e| e.to_string())?;
|
||||||
|
let word_outputs: Vec<WordOutput> = words
|
||||||
|
.into_iter()
|
||||||
|
.map(|w| WordOutput {
|
||||||
|
word: w.word,
|
||||||
|
start_ms: w.start_ms,
|
||||||
|
end_ms: w.end_ms,
|
||||||
|
confidence: w.confidence,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let speaker_label = seg
|
||||||
|
.speaker_id
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|sid| speaker_label_map.get(sid))
|
||||||
|
.cloned();
|
||||||
|
|
||||||
|
segment_outputs.push(SegmentOutput {
|
||||||
|
id: seg.id.clone(),
|
||||||
|
text: seg.text.clone(),
|
||||||
|
start_ms: seg.start_ms,
|
||||||
|
end_ms: seg.end_ms,
|
||||||
|
speaker: speaker_label,
|
||||||
|
words: word_outputs,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Build speaker outputs
|
||||||
|
let speaker_outputs: Vec<SpeakerOutput> = speakers
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| SpeakerOutput {
|
||||||
|
id: s.id,
|
||||||
|
label: s.label,
|
||||||
|
display_name: s.display_name,
|
||||||
|
color: s.color,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(Some(ProjectTranscript {
|
||||||
|
file_path: media_file.file_path.clone(),
|
||||||
|
segments: segment_outputs,
|
||||||
|
speakers: speaker_outputs,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── File-based project commands ─────────────────────────────────
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn save_project_file(path: String, project: ProjectFile) -> Result<(), String> {
|
||||||
|
let json = serde_json::to_string_pretty(&project).map_err(|e| e.to_string())?;
|
||||||
|
fs::write(&path, json).map_err(|e| format!("Failed to save project: {e}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn load_project_file(path: String) -> Result<ProjectFile, String> {
|
||||||
|
let json = fs::read_to_string(&path).map_err(|e| format!("Failed to read project: {e}"))?;
|
||||||
|
serde_json::from_str(&json).map_err(|e| format!("Failed to parse project: {e}"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -85,6 +85,57 @@ pub fn delete_project(conn: &Connection, id: &str) -> Result<(), DatabaseError>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Media Files ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
pub fn create_media_file(
|
||||||
|
conn: &Connection,
|
||||||
|
project_id: &str,
|
||||||
|
file_path: &str,
|
||||||
|
) -> Result<MediaFile, DatabaseError> {
|
||||||
|
let id = Uuid::new_v4().to_string();
|
||||||
|
let now = Utc::now().to_rfc3339();
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO media_files (id, project_id, file_path, created_at) VALUES (?1, ?2, ?3, ?4)",
|
||||||
|
params![id, project_id, file_path, now],
|
||||||
|
)?;
|
||||||
|
Ok(MediaFile {
|
||||||
|
id,
|
||||||
|
project_id: project_id.to_string(),
|
||||||
|
file_path: file_path.to_string(),
|
||||||
|
file_hash: None,
|
||||||
|
duration_ms: None,
|
||||||
|
sample_rate: None,
|
||||||
|
channels: None,
|
||||||
|
format: None,
|
||||||
|
file_size: None,
|
||||||
|
created_at: now,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_media_files_for_project(
|
||||||
|
conn: &Connection,
|
||||||
|
project_id: &str,
|
||||||
|
) -> Result<Vec<MediaFile>, DatabaseError> {
|
||||||
|
let mut stmt = conn.prepare(
|
||||||
|
"SELECT id, project_id, file_path, file_hash, duration_ms, sample_rate, channels, format, file_size, created_at FROM media_files WHERE project_id = ?1 ORDER BY created_at",
|
||||||
|
)?;
|
||||||
|
let rows = stmt.query_map(params![project_id], |row| {
|
||||||
|
Ok(MediaFile {
|
||||||
|
id: row.get(0)?,
|
||||||
|
project_id: row.get(1)?,
|
||||||
|
file_path: row.get(2)?,
|
||||||
|
file_hash: row.get(3)?,
|
||||||
|
duration_ms: row.get(4)?,
|
||||||
|
sample_rate: row.get(5)?,
|
||||||
|
channels: row.get(6)?,
|
||||||
|
format: row.get(7)?,
|
||||||
|
file_size: row.get(8)?,
|
||||||
|
created_at: row.get(9)?,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
Ok(rows.collect::<Result<Vec<_>, _>>()?)
|
||||||
|
}
|
||||||
|
|
||||||
// ── Speakers ──────────────────────────────────────────────────────
|
// ── Speakers ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
pub fn create_speaker(
|
pub fn create_speaker(
|
||||||
@@ -194,6 +245,39 @@ pub fn reassign_speaker(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Segments (create) ────────────────────────────────────────────
|
||||||
|
|
||||||
|
pub fn create_segment(
|
||||||
|
conn: &Connection,
|
||||||
|
project_id: &str,
|
||||||
|
media_file_id: &str,
|
||||||
|
speaker_id: Option<&str>,
|
||||||
|
start_ms: i64,
|
||||||
|
end_ms: i64,
|
||||||
|
text: &str,
|
||||||
|
segment_index: i32,
|
||||||
|
) -> Result<Segment, DatabaseError> {
|
||||||
|
let id = Uuid::new_v4().to_string();
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO segments (id, project_id, media_file_id, speaker_id, start_ms, end_ms, text, is_edited, segment_index) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, 0, ?8)",
|
||||||
|
params![id, project_id, media_file_id, speaker_id, start_ms, end_ms, text, segment_index],
|
||||||
|
)?;
|
||||||
|
Ok(Segment {
|
||||||
|
id,
|
||||||
|
project_id: project_id.to_string(),
|
||||||
|
media_file_id: media_file_id.to_string(),
|
||||||
|
speaker_id: speaker_id.map(String::from),
|
||||||
|
start_ms,
|
||||||
|
end_ms,
|
||||||
|
text: text.to_string(),
|
||||||
|
original_text: None,
|
||||||
|
confidence: None,
|
||||||
|
is_edited: false,
|
||||||
|
edited_at: None,
|
||||||
|
segment_index,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ── Words ─────────────────────────────────────────────────────────
|
// ── Words ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
pub fn get_words_for_segment(
|
pub fn get_words_for_segment(
|
||||||
@@ -217,6 +301,31 @@ pub fn get_words_for_segment(
|
|||||||
Ok(rows.collect::<Result<Vec<_>, _>>()?)
|
Ok(rows.collect::<Result<Vec<_>, _>>()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_word(
|
||||||
|
conn: &Connection,
|
||||||
|
segment_id: &str,
|
||||||
|
word: &str,
|
||||||
|
start_ms: i64,
|
||||||
|
end_ms: i64,
|
||||||
|
confidence: Option<f64>,
|
||||||
|
word_index: i32,
|
||||||
|
) -> Result<Word, DatabaseError> {
|
||||||
|
let id = Uuid::new_v4().to_string();
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO words (id, segment_id, word, start_ms, end_ms, confidence, word_index) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
|
||||||
|
params![id, segment_id, word, start_ms, end_ms, confidence, word_index],
|
||||||
|
)?;
|
||||||
|
Ok(Word {
|
||||||
|
id,
|
||||||
|
segment_id: segment_id.to_string(),
|
||||||
|
word: word.to_string(),
|
||||||
|
start_ms,
|
||||||
|
end_ms,
|
||||||
|
confidence,
|
||||||
|
word_index,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
+18
-1
@@ -9,7 +9,10 @@ use tauri::Manager;
|
|||||||
|
|
||||||
use commands::ai::{ai_chat, ai_configure, ai_list_providers};
|
use commands::ai::{ai_chat, ai_configure, ai_list_providers};
|
||||||
use commands::export::export_transcript;
|
use commands::export::export_transcript;
|
||||||
use commands::project::{create_project, get_project, list_projects};
|
use commands::project::{
|
||||||
|
create_project, delete_project, get_project, list_projects, load_project_file,
|
||||||
|
load_project_transcript, save_project_file, save_project_transcript, update_segment,
|
||||||
|
};
|
||||||
use commands::settings::{load_settings, save_settings};
|
use commands::settings::{load_settings, save_settings};
|
||||||
use commands::system::{get_data_dir, llama_list_models, llama_start, llama_status, llama_stop};
|
use commands::system::{get_data_dir, llama_list_models, llama_start, llama_status, llama_stop};
|
||||||
use commands::transcribe::{download_diarize_model, run_pipeline, transcribe_file};
|
use commands::transcribe::{download_diarize_model, run_pipeline, transcribe_file};
|
||||||
@@ -24,6 +27,14 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.manage(app_state)
|
.manage(app_state)
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
|
// Tell the sidecar manager where Tauri placed bundled resources
|
||||||
|
// and where to extract the sidecar archive
|
||||||
|
if let (Ok(resource_dir), Ok(data_dir)) =
|
||||||
|
(app.path().resource_dir(), app.path().app_local_data_dir())
|
||||||
|
{
|
||||||
|
sidecar::init_dirs(resource_dir, data_dir);
|
||||||
|
}
|
||||||
|
|
||||||
// Set the webview background to match the app's dark theme
|
// Set the webview background to match the app's dark theme
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
let _ = window.set_background_color(Some(Color(10, 10, 35, 255)));
|
let _ = window.set_background_color(Some(Color(10, 10, 35, 255)));
|
||||||
@@ -34,6 +45,12 @@ pub fn run() {
|
|||||||
create_project,
|
create_project,
|
||||||
get_project,
|
get_project,
|
||||||
list_projects,
|
list_projects,
|
||||||
|
delete_project,
|
||||||
|
save_project_transcript,
|
||||||
|
load_project_transcript,
|
||||||
|
update_segment,
|
||||||
|
save_project_file,
|
||||||
|
load_project_file,
|
||||||
transcribe_file,
|
transcribe_file,
|
||||||
run_pipeline,
|
run_pipeline,
|
||||||
download_diarize_model,
|
download_diarize_model,
|
||||||
|
|||||||
+234
-32
@@ -2,11 +2,27 @@ pub mod ipc;
|
|||||||
pub mod messages;
|
pub mod messages;
|
||||||
|
|
||||||
use std::io::{BufRead, BufReader, Write};
|
use std::io::{BufRead, BufReader, Write};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||||
use std::sync::{Mutex, OnceLock};
|
use std::sync::{Mutex, OnceLock};
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
use crate::sidecar::messages::IPCMessage;
|
use crate::sidecar::messages::IPCMessage;
|
||||||
|
|
||||||
|
/// Resource directory set by the Tauri app during setup.
|
||||||
|
static RESOURCE_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||||
|
/// App data directory for extracting the sidecar archive.
|
||||||
|
static DATA_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||||
|
|
||||||
|
/// Initialize directories for sidecar resolution.
|
||||||
|
/// Must be called from the Tauri setup before any sidecar operations.
|
||||||
|
pub fn init_dirs(resource_dir: PathBuf, data_dir: PathBuf) {
|
||||||
|
RESOURCE_DIR.set(resource_dir).ok();
|
||||||
|
DATA_DIR.set(data_dir).ok();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the global sidecar manager singleton.
|
/// Get the global sidecar manager singleton.
|
||||||
pub fn sidecar() -> &'static SidecarManager {
|
pub fn sidecar() -> &'static SidecarManager {
|
||||||
static INSTANCE: OnceLock<SidecarManager> = OnceLock::new();
|
static INSTANCE: OnceLock<SidecarManager> = OnceLock::new();
|
||||||
@@ -41,37 +57,131 @@ impl SidecarManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the frozen sidecar binary path (production mode).
|
/// Resolve the frozen sidecar binary path (production mode).
|
||||||
fn resolve_sidecar_path() -> Result<std::path::PathBuf, String> {
|
///
|
||||||
let exe = std::env::current_exe().map_err(|e| format!("Cannot get current exe: {e}"))?;
|
/// First checks if the sidecar is already extracted to the app data directory.
|
||||||
let exe_dir = exe
|
/// If not, looks for `sidecar.zip` in the Tauri resource directory and extracts it.
|
||||||
.parent()
|
fn resolve_sidecar_path() -> Result<PathBuf, String> {
|
||||||
.ok_or_else(|| "Cannot get exe parent directory".to_string())?;
|
|
||||||
|
|
||||||
let binary_name = if cfg!(target_os = "windows") {
|
let binary_name = if cfg!(target_os = "windows") {
|
||||||
"voice-to-notes-sidecar.exe"
|
"voice-to-notes-sidecar.exe"
|
||||||
} else {
|
} else {
|
||||||
"voice-to-notes-sidecar"
|
"voice-to-notes-sidecar"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tauri places externalBin next to the app binary
|
// Versioned extraction directory prevents stale sidecar after app updates
|
||||||
let path = exe_dir.join(binary_name);
|
let extract_dir = DATA_DIR
|
||||||
if path.exists() {
|
.get()
|
||||||
return Ok(path);
|
.ok_or("App data directory not initialized")?
|
||||||
|
.join(format!("sidecar-{}", env!("CARGO_PKG_VERSION")));
|
||||||
|
|
||||||
|
let binary_path = extract_dir.join(binary_name);
|
||||||
|
|
||||||
|
// Already extracted — use it directly
|
||||||
|
if binary_path.exists() {
|
||||||
|
return Ok(binary_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also check inside a subdirectory (onedir PyInstaller output)
|
// Find sidecar.zip in resource dir or next to exe
|
||||||
let subdir_path = exe_dir.join("voice-to-notes-sidecar").join(binary_name);
|
let zip_path = Self::find_sidecar_zip()?;
|
||||||
if subdir_path.exists() {
|
Self::extract_zip(&zip_path, &extract_dir)?;
|
||||||
return Ok(subdir_path);
|
|
||||||
|
if !binary_path.exists() {
|
||||||
|
return Err(format!(
|
||||||
|
"Sidecar binary not found after extraction at {}",
|
||||||
|
binary_path.display()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make executable on Unix
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
if let Ok(meta) = std::fs::metadata(&binary_path) {
|
||||||
|
let mut perms = meta.permissions();
|
||||||
|
perms.set_mode(0o755);
|
||||||
|
let _ = std::fs::set_permissions(&binary_path, perms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(binary_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Locate the bundled sidecar.zip archive.
|
||||||
|
fn find_sidecar_zip() -> Result<PathBuf, String> {
|
||||||
|
let mut candidates: Vec<PathBuf> = Vec::new();
|
||||||
|
|
||||||
|
if let Some(resource_dir) = RESOURCE_DIR.get() {
|
||||||
|
candidates.push(resource_dir.join("sidecar.zip"));
|
||||||
|
}
|
||||||
|
if let Ok(exe) = std::env::current_exe() {
|
||||||
|
if let Some(exe_dir) = exe.parent() {
|
||||||
|
candidates.push(exe_dir.join("sidecar.zip"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for path in &candidates {
|
||||||
|
if path.exists() {
|
||||||
|
return Ok(path.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(format!(
|
Err(format!(
|
||||||
"Sidecar binary not found. Looked for:\n {}\n {}",
|
"Sidecar archive not found. Checked:\n{}",
|
||||||
path.display(),
|
candidates
|
||||||
subdir_path.display(),
|
.iter()
|
||||||
|
.map(|p| format!(" {}", p.display()))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n"),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extract a zip archive to the given directory.
|
||||||
|
fn extract_zip(zip_path: &Path, dest: &Path) -> Result<(), String> {
|
||||||
|
eprintln!(
|
||||||
|
"[sidecar-rs] Extracting sidecar from {} to {}",
|
||||||
|
zip_path.display(),
|
||||||
|
dest.display()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Clean destination so we don't mix old and new files
|
||||||
|
if dest.exists() {
|
||||||
|
std::fs::remove_dir_all(dest)
|
||||||
|
.map_err(|e| format!("Failed to clean extraction dir: {e}"))?;
|
||||||
|
}
|
||||||
|
std::fs::create_dir_all(dest)
|
||||||
|
.map_err(|e| format!("Failed to create extraction dir: {e}"))?;
|
||||||
|
|
||||||
|
let file =
|
||||||
|
std::fs::File::open(zip_path).map_err(|e| format!("Cannot open sidecar zip: {e}"))?;
|
||||||
|
let mut archive =
|
||||||
|
zip::ZipArchive::new(file).map_err(|e| format!("Invalid sidecar zip: {e}"))?;
|
||||||
|
|
||||||
|
for i in 0..archive.len() {
|
||||||
|
let mut entry = archive
|
||||||
|
.by_index(i)
|
||||||
|
.map_err(|e| format!("Zip entry error: {e}"))?;
|
||||||
|
|
||||||
|
let name = entry.name().to_string();
|
||||||
|
let outpath = dest.join(&name);
|
||||||
|
|
||||||
|
if entry.is_dir() {
|
||||||
|
std::fs::create_dir_all(&outpath)
|
||||||
|
.map_err(|e| format!("Cannot create dir {}: {e}", outpath.display()))?;
|
||||||
|
} else {
|
||||||
|
if let Some(parent) = outpath.parent() {
|
||||||
|
std::fs::create_dir_all(parent)
|
||||||
|
.map_err(|e| format!("Cannot create dir {}: {e}", parent.display()))?;
|
||||||
|
}
|
||||||
|
let mut outfile = std::fs::File::create(&outpath)
|
||||||
|
.map_err(|e| format!("Cannot create {}: {e}", outpath.display()))?;
|
||||||
|
std::io::copy(&mut entry, &mut outfile)
|
||||||
|
.map_err(|e| format!("Write error for {}: {e}", name))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eprintln!("[sidecar-rs] Sidecar extracted successfully");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Find a working Python command for the current platform.
|
/// Find a working Python command for the current platform.
|
||||||
fn find_python_command() -> &'static str {
|
fn find_python_command() -> &'static str {
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
@@ -114,15 +224,8 @@ impl SidecarManager {
|
|||||||
if Self::is_dev_mode() {
|
if Self::is_dev_mode() {
|
||||||
self.start_python_dev()
|
self.start_python_dev()
|
||||||
} else {
|
} else {
|
||||||
match Self::resolve_sidecar_path() {
|
let path = Self::resolve_sidecar_path()?;
|
||||||
Ok(path) => self.start_binary(&path),
|
self.start_binary(&path)
|
||||||
Err(e) => {
|
|
||||||
eprintln!(
|
|
||||||
"[sidecar-rs] Frozen binary not found ({e}), falling back to dev mode"
|
|
||||||
);
|
|
||||||
self.start_python_dev()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,10 +234,28 @@ impl SidecarManager {
|
|||||||
self.stop().ok();
|
self.stop().ok();
|
||||||
eprintln!("[sidecar-rs] Starting frozen sidecar: {}", path.display());
|
eprintln!("[sidecar-rs] Starting frozen sidecar: {}", path.display());
|
||||||
|
|
||||||
let child = Command::new(path)
|
// Log sidecar stderr to a file for diagnostics
|
||||||
.stdin(Stdio::piped())
|
let stderr_cfg = if let Some(data_dir) = DATA_DIR.get() {
|
||||||
|
let log_path = data_dir.join("sidecar.log");
|
||||||
|
eprintln!("[sidecar-rs] Sidecar stderr → {}", log_path.display());
|
||||||
|
match std::fs::File::create(&log_path) {
|
||||||
|
Ok(f) => Stdio::from(f),
|
||||||
|
Err(_) => Stdio::inherit(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Stdio::inherit()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut cmd = Command::new(path);
|
||||||
|
cmd.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(stderr_cfg);
|
||||||
|
|
||||||
|
// Hide the console window on Windows (CREATE_NO_WINDOW = 0x08000000)
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
cmd.creation_flags(0x08000000);
|
||||||
|
|
||||||
|
let child = cmd
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|e| format!("Failed to start sidecar binary: {e}"))?;
|
.map_err(|e| format!("Failed to start sidecar binary: {e}"))?;
|
||||||
|
|
||||||
@@ -200,7 +321,22 @@ impl SidecarManager {
|
|||||||
.read_line(&mut line)
|
.read_line(&mut line)
|
||||||
.map_err(|e| format!("Read error: {e}"))?;
|
.map_err(|e| format!("Read error: {e}"))?;
|
||||||
if bytes == 0 {
|
if bytes == 0 {
|
||||||
return Err("Sidecar closed stdout before sending ready".to_string());
|
// Try to get the exit code for diagnostics
|
||||||
|
let exit_info = {
|
||||||
|
let mut proc = self.process.lock().map_err(|e| e.to_string())?;
|
||||||
|
if let Some(ref mut child) = *proc {
|
||||||
|
match child.try_wait() {
|
||||||
|
Ok(Some(status)) => format!(" (exit status: {status})"),
|
||||||
|
_ => String::new(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return Err(format!(
|
||||||
|
"Sidecar closed stdout before sending ready{exit_info}. \
|
||||||
|
The Python sidecar may have crashed on startup — check app logs for details."
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let trimmed = line.trim();
|
let trimmed = line.trim();
|
||||||
if trimmed.is_empty() {
|
if trimmed.is_empty() {
|
||||||
@@ -230,11 +366,46 @@ impl SidecarManager {
|
|||||||
|
|
||||||
/// Send a message and receive the response, calling a callback for intermediate messages.
|
/// Send a message and receive the response, calling a callback for intermediate messages.
|
||||||
/// Intermediate messages include progress, pipeline.segment, and pipeline.speaker_update.
|
/// Intermediate messages include progress, pipeline.segment, and pipeline.speaker_update.
|
||||||
|
///
|
||||||
|
/// If the sidecar has crashed (broken pipe), automatically restarts it and retries once.
|
||||||
pub fn send_and_receive_with_progress<F>(
|
pub fn send_and_receive_with_progress<F>(
|
||||||
&self,
|
&self,
|
||||||
msg: &IPCMessage,
|
msg: &IPCMessage,
|
||||||
on_intermediate: F,
|
on_intermediate: F,
|
||||||
) -> Result<IPCMessage, String>
|
) -> Result<IPCMessage, String>
|
||||||
|
where
|
||||||
|
F: Fn(&IPCMessage),
|
||||||
|
{
|
||||||
|
match self.send_and_receive_inner(msg, &on_intermediate) {
|
||||||
|
Ok(response) => Ok(response),
|
||||||
|
Err(e)
|
||||||
|
if e.contains("Write error")
|
||||||
|
|| e.contains("closed stdout")
|
||||||
|
|| e.contains("not available") =>
|
||||||
|
{
|
||||||
|
eprintln!("[sidecar-rs] Sidecar communication failed ({e}), restarting...");
|
||||||
|
self.cleanup_handles();
|
||||||
|
// Stop any zombie process
|
||||||
|
{
|
||||||
|
let mut proc = self.process.lock().map_err(|e| e.to_string())?;
|
||||||
|
if let Some(ref mut child) = proc.take() {
|
||||||
|
let _ = child.kill();
|
||||||
|
let _ = child.wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.ensure_running()?;
|
||||||
|
self.send_and_receive_inner(msg, &on_intermediate)
|
||||||
|
}
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inner implementation of send_and_receive.
|
||||||
|
fn send_and_receive_inner<F>(
|
||||||
|
&self,
|
||||||
|
msg: &IPCMessage,
|
||||||
|
on_intermediate: &F,
|
||||||
|
) -> Result<IPCMessage, String>
|
||||||
where
|
where
|
||||||
F: Fn(&IPCMessage),
|
F: Fn(&IPCMessage),
|
||||||
{
|
{
|
||||||
@@ -320,8 +491,39 @@ impl SidecarManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_running(&self) -> bool {
|
pub fn is_running(&self) -> bool {
|
||||||
let proc = self.process.lock().ok();
|
let mut proc = match self.process.lock() {
|
||||||
proc.map_or(false, |p| p.is_some())
|
Ok(p) => p,
|
||||||
|
Err(_) => return false,
|
||||||
|
};
|
||||||
|
if let Some(ref mut child) = *proc {
|
||||||
|
// Check if the process has exited
|
||||||
|
match child.try_wait() {
|
||||||
|
Ok(Some(_status)) => {
|
||||||
|
// Process has exited — clean up handles
|
||||||
|
eprintln!("[sidecar-rs] Sidecar process has exited");
|
||||||
|
drop(proc);
|
||||||
|
let _ = self.cleanup_handles();
|
||||||
|
false
|
||||||
|
}
|
||||||
|
Ok(None) => true, // Still running
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clean up stdin/stdout/process handles after the sidecar has exited.
|
||||||
|
fn cleanup_handles(&self) {
|
||||||
|
if let Ok(mut s) = self.stdin.lock() {
|
||||||
|
*s = None;
|
||||||
|
}
|
||||||
|
if let Ok(mut r) = self.reader.lock() {
|
||||||
|
*r = None;
|
||||||
|
}
|
||||||
|
if let Ok(mut p) = self.process.lock() {
|
||||||
|
*p = None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Voice to Notes",
|
"productName": "Voice to Notes",
|
||||||
"version": "0.1.0",
|
"version": "0.2.3",
|
||||||
"identifier": "com.voicetonotes.app",
|
"identifier": "com.voicetonotes.app",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
"active": true,
|
"active": true,
|
||||||
"targets": "all",
|
"targets": ["deb", "nsis", "msi", "dmg"],
|
||||||
"icon": [
|
"icon": [
|
||||||
"icons/32x32.png",
|
"icons/32x32.png",
|
||||||
"icons/128x128.png",
|
"icons/128x128.png",
|
||||||
@@ -42,14 +42,12 @@
|
|||||||
"category": "Utility",
|
"category": "Utility",
|
||||||
"shortDescription": "Transcribe audio/video with speaker identification",
|
"shortDescription": "Transcribe audio/video with speaker identification",
|
||||||
"longDescription": "Voice to Notes is a desktop application that transcribes audio and video recordings with speaker identification, synchronized playback, and AI-powered analysis. Export to SRT, WebVTT, ASS captions, or plain text.",
|
"longDescription": "Voice to Notes is a desktop application that transcribes audio and video recordings with speaker identification, synchronized playback, and AI-powered analysis. Export to SRT, WebVTT, ASS captions, or plain text.",
|
||||||
|
"resources": ["sidecar.zip"],
|
||||||
"copyright": "Voice to Notes Contributors",
|
"copyright": "Voice to Notes Contributors",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"linux": {
|
"linux": {
|
||||||
"deb": {
|
"deb": {
|
||||||
"depends": []
|
"depends": []
|
||||||
},
|
|
||||||
"appimage": {
|
|
||||||
"bundleMediaFramework": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"windows": {
|
"windows": {
|
||||||
|
|||||||
@@ -88,6 +88,88 @@
|
|||||||
messages = [];
|
messages = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatMarkdown(text: string): string {
|
||||||
|
// Split into lines for block-level processing
|
||||||
|
const lines = text.split('\n');
|
||||||
|
const result: string[] = [];
|
||||||
|
let inList = false;
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
let line = lines[i];
|
||||||
|
|
||||||
|
// Headers
|
||||||
|
if (line.startsWith('### ')) {
|
||||||
|
if (inList) { result.push('</ul>'); inList = false; }
|
||||||
|
const content = applyInlineFormatting(line.slice(4));
|
||||||
|
result.push(`<h4>${content}</h4>`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.startsWith('## ')) {
|
||||||
|
if (inList) { result.push('</ul>'); inList = false; }
|
||||||
|
const content = applyInlineFormatting(line.slice(3));
|
||||||
|
result.push(`<h3>${content}</h3>`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.startsWith('# ')) {
|
||||||
|
if (inList) { result.push('</ul>'); inList = false; }
|
||||||
|
const content = applyInlineFormatting(line.slice(2));
|
||||||
|
result.push(`<h2>${content}</h2>`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// List items (- or *)
|
||||||
|
if (/^[\-\*] /.test(line)) {
|
||||||
|
if (!inList) { result.push('<ul>'); inList = true; }
|
||||||
|
const content = applyInlineFormatting(line.slice(2));
|
||||||
|
result.push(`<li>${content}</li>`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Numbered list items
|
||||||
|
if (/^\d+\.\s/.test(line)) {
|
||||||
|
if (!inList) { result.push('<ol>'); inList = true; }
|
||||||
|
const content = applyInlineFormatting(line.replace(/^\d+\.\s/, ''));
|
||||||
|
result.push(`<li>${content}</li>`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-list line: close any open list
|
||||||
|
if (inList) {
|
||||||
|
// Check if previous list was ordered or unordered
|
||||||
|
const lastOpen = result.findLast(r => r === '<ul>' || r === '<ol>');
|
||||||
|
result.push(lastOpen === '<ol>' ? '</ol>' : '</ul>');
|
||||||
|
inList = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty line = paragraph break
|
||||||
|
if (line.trim() === '') {
|
||||||
|
result.push('<br>');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regular text line
|
||||||
|
result.push(applyInlineFormatting(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close any trailing open list
|
||||||
|
if (inList) {
|
||||||
|
const lastOpen = result.findLast(r => r === '<ul>' || r === '<ol>');
|
||||||
|
result.push(lastOpen === '<ol>' ? '</ol>' : '</ul>');
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyInlineFormatting(text: string): string {
|
||||||
|
// Code blocks (backtick) — process first to avoid conflicts
|
||||||
|
text = text.replace(/`([^`]+)`/g, '<code>$1</code>');
|
||||||
|
// Bold (**text**)
|
||||||
|
text = text.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
||||||
|
// Italic (*text*) — only single asterisks not already consumed by bold
|
||||||
|
text = text.replace(/\*([^*]+)\*/g, '<em>$1</em>');
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
// Quick action buttons
|
// Quick action buttons
|
||||||
async function summarize() {
|
async function summarize() {
|
||||||
inputText = 'Please summarize this transcript in bullet points.';
|
inputText = 'Please summarize this transcript in bullet points.';
|
||||||
@@ -122,7 +204,11 @@
|
|||||||
{:else}
|
{:else}
|
||||||
{#each messages as msg}
|
{#each messages as msg}
|
||||||
<div class="message {msg.role}">
|
<div class="message {msg.role}">
|
||||||
|
{#if msg.role === 'assistant'}
|
||||||
|
<div class="message-content">{@html formatMarkdown(msg.content)}</div>
|
||||||
|
{:else}
|
||||||
<div class="message-content">{msg.content}</div>
|
<div class="message-content">{msg.content}</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{#if isLoading}
|
{#if isLoading}
|
||||||
@@ -192,47 +278,101 @@
|
|||||||
}
|
}
|
||||||
.empty-state {
|
.empty-state {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #666;
|
color: #888;
|
||||||
font-size: 0.8rem;
|
font-size: 0.85rem;
|
||||||
padding: 1rem 0;
|
padding: 2rem 1rem;
|
||||||
|
}
|
||||||
|
.empty-state p {
|
||||||
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
.quick-actions {
|
.quick-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.75rem;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin-top: 0.5rem;
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
.quick-btn {
|
.quick-btn {
|
||||||
background: rgba(233, 69, 96, 0.15);
|
background: rgba(233, 69, 96, 0.15);
|
||||||
border: 1px solid rgba(233, 69, 96, 0.3);
|
border: 1px solid rgba(233, 69, 96, 0.3);
|
||||||
color: #e94560;
|
color: #e94560;
|
||||||
padding: 0.3rem 0.6rem;
|
padding: 0.45rem 0.85rem;
|
||||||
border-radius: 4px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.75rem;
|
font-size: 0.8rem;
|
||||||
|
transition: background 0.15s;
|
||||||
}
|
}
|
||||||
.quick-btn:hover {
|
.quick-btn:hover {
|
||||||
background: rgba(233, 69, 96, 0.25);
|
background: rgba(233, 69, 96, 0.25);
|
||||||
}
|
}
|
||||||
.message {
|
.message {
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.75rem;
|
||||||
padding: 0.5rem 0.75rem;
|
padding: 0.75rem 1rem;
|
||||||
border-radius: 6px;
|
border-radius: 8px;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
line-height: 1.4;
|
line-height: 1.55;
|
||||||
}
|
}
|
||||||
.message.user {
|
.message.user {
|
||||||
background: rgba(233, 69, 96, 0.15);
|
background: rgba(233, 69, 96, 0.15);
|
||||||
margin-left: 1rem;
|
border-left: 3px solid rgba(233, 69, 96, 0.4);
|
||||||
}
|
}
|
||||||
.message.assistant {
|
.message.assistant {
|
||||||
background: rgba(255, 255, 255, 0.05);
|
background: rgba(255, 255, 255, 0.05);
|
||||||
margin-right: 1rem;
|
border-left: 3px solid rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
.message.loading {
|
.message.loading {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Markdown styles inside assistant messages */
|
||||||
|
.message.assistant :global(h2) {
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0.6rem 0 0.3rem;
|
||||||
|
color: #f0f0f0;
|
||||||
|
}
|
||||||
|
.message.assistant :global(h3) {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0.5rem 0 0.25rem;
|
||||||
|
color: #e8e8e8;
|
||||||
|
}
|
||||||
|
.message.assistant :global(h4) {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin: 0.4rem 0 0.2rem;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
.message.assistant :global(strong) {
|
||||||
|
color: #f0f0f0;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.message.assistant :global(em) {
|
||||||
|
color: #ccc;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.message.assistant :global(code) {
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
color: #e94560;
|
||||||
|
padding: 0.1rem 0.35rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
|
||||||
|
}
|
||||||
|
.message.assistant :global(ul),
|
||||||
|
.message.assistant :global(ol) {
|
||||||
|
margin: 0.35rem 0;
|
||||||
|
padding-left: 1.3rem;
|
||||||
|
}
|
||||||
|
.message.assistant :global(li) {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
.message.assistant :global(br) {
|
||||||
|
display: block;
|
||||||
|
content: '';
|
||||||
|
margin-top: 0.35rem;
|
||||||
|
}
|
||||||
.chat-input {
|
.chat-input {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
|||||||
@@ -60,12 +60,14 @@
|
|||||||
function finishEditing(segmentId: string) {
|
function finishEditing(segmentId: string) {
|
||||||
const trimmed = editText.trim();
|
const trimmed = editText.trim();
|
||||||
if (trimmed) {
|
if (trimmed) {
|
||||||
// Update the segment text in the store
|
|
||||||
segments.update(segs => segs.map(s => {
|
segments.update(segs => segs.map(s => {
|
||||||
if (s.id !== segmentId) return s;
|
if (s.id !== segmentId) return s;
|
||||||
|
const newWordTexts = trimmed.split(/\s+/);
|
||||||
|
const newWords = redistributeWords(s, newWordTexts);
|
||||||
return {
|
return {
|
||||||
...s,
|
...s,
|
||||||
text: trimmed,
|
text: trimmed,
|
||||||
|
words: newWords,
|
||||||
original_text: s.original_text ?? s.text,
|
original_text: s.original_text ?? s.text,
|
||||||
is_edited: true,
|
is_edited: true,
|
||||||
edited_at: new Date().toISOString(),
|
edited_at: new Date().toISOString(),
|
||||||
@@ -76,6 +78,106 @@
|
|||||||
editingSegmentId = null;
|
editingSegmentId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redistribute word timing after an edit.
|
||||||
|
*
|
||||||
|
* Uses a diff-like alignment between old and new word lists:
|
||||||
|
* - Unchanged words keep their original timing
|
||||||
|
* - Spelling fixes (same position, same count) keep timing
|
||||||
|
* - Split words (1 old → N new) divide the original time range proportionally
|
||||||
|
* - Inserted words with no match get interpolated timing
|
||||||
|
*/
|
||||||
|
function redistributeWords(segment: Segment, newWordTexts: string[]): Word[] {
|
||||||
|
const oldWords = segment.words;
|
||||||
|
|
||||||
|
// Same word count — preserve per-word timing (spelling fixes)
|
||||||
|
if (newWordTexts.length === oldWords.length) {
|
||||||
|
return oldWords.map((w, i) => ({ ...w, word: newWordTexts[i] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Align old words to new words using a simple greedy match.
|
||||||
|
// Build a mapping: for each old word, which new words does it cover?
|
||||||
|
const oldTexts = oldWords.map(w => w.word.toLowerCase());
|
||||||
|
const newTexts = newWordTexts.map(w => w.toLowerCase());
|
||||||
|
|
||||||
|
// Walk both lists, greedily matching old words to new words
|
||||||
|
const result: Word[] = [];
|
||||||
|
let oldIdx = 0;
|
||||||
|
let newIdx = 0;
|
||||||
|
|
||||||
|
while (newIdx < newTexts.length) {
|
||||||
|
if (oldIdx < oldTexts.length && oldTexts[oldIdx] === newTexts[newIdx]) {
|
||||||
|
// Exact match — keep original timing
|
||||||
|
result.push({ ...oldWords[oldIdx], word: newWordTexts[newIdx], word_index: newIdx });
|
||||||
|
oldIdx++;
|
||||||
|
newIdx++;
|
||||||
|
} else if (oldIdx < oldTexts.length) {
|
||||||
|
// Check if old word was split into multiple new words.
|
||||||
|
// E.g., "gonna" → "going to": see if concatenating upcoming new words
|
||||||
|
// matches the old word (or close enough — just check if old word's chars
|
||||||
|
// are consumed by the next few new words).
|
||||||
|
let splitCount = 0;
|
||||||
|
let combined = '';
|
||||||
|
for (let k = newIdx; k < newTexts.length && k - newIdx < 5; k++) {
|
||||||
|
combined += (k > newIdx ? '' : '') + newTexts[k];
|
||||||
|
if (combined.length >= oldTexts[oldIdx].length) {
|
||||||
|
splitCount = k - newIdx + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (splitCount > 1) {
|
||||||
|
// Split: distribute the old word's time range proportionally
|
||||||
|
const ow = oldWords[oldIdx];
|
||||||
|
const totalDuration = ow.end_ms - ow.start_ms;
|
||||||
|
for (let k = 0; k < splitCount; k++) {
|
||||||
|
const fraction = 1 / splitCount;
|
||||||
|
result.push({
|
||||||
|
id: `${segment.id}-word-${newIdx + k}`,
|
||||||
|
segment_id: segment.id,
|
||||||
|
word: newWordTexts[newIdx + k],
|
||||||
|
start_ms: Math.round(ow.start_ms + totalDuration * fraction * k),
|
||||||
|
end_ms: Math.round(ow.start_ms + totalDuration * fraction * (k + 1)),
|
||||||
|
confidence: ow.confidence,
|
||||||
|
word_index: newIdx + k,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
oldIdx++;
|
||||||
|
newIdx += splitCount;
|
||||||
|
} else {
|
||||||
|
// No match found — interpolate timing from neighbors
|
||||||
|
const prevEnd = result.length > 0 ? result[result.length - 1].end_ms : segment.start_ms;
|
||||||
|
const nextStart = oldIdx < oldWords.length ? oldWords[oldIdx].start_ms : segment.end_ms;
|
||||||
|
result.push({
|
||||||
|
id: `${segment.id}-word-${newIdx}`,
|
||||||
|
segment_id: segment.id,
|
||||||
|
word: newWordTexts[newIdx],
|
||||||
|
start_ms: prevEnd,
|
||||||
|
end_ms: nextStart,
|
||||||
|
confidence: 1.0,
|
||||||
|
word_index: newIdx,
|
||||||
|
});
|
||||||
|
newIdx++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No more old words — use end of segment
|
||||||
|
const prevEnd = result.length > 0 ? result[result.length - 1].end_ms : segment.start_ms;
|
||||||
|
result.push({
|
||||||
|
id: `${segment.id}-word-${newIdx}`,
|
||||||
|
segment_id: segment.id,
|
||||||
|
word: newWordTexts[newIdx],
|
||||||
|
start_ms: prevEnd,
|
||||||
|
end_ms: segment.end_ms,
|
||||||
|
confidence: 1.0,
|
||||||
|
word_index: newIdx,
|
||||||
|
});
|
||||||
|
newIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
function handleEditKeydown(e: KeyboardEvent, segmentId: string) {
|
function handleEditKeydown(e: KeyboardEvent, segmentId: string) {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
editingSegmentId = null;
|
editingSegmentId = null;
|
||||||
|
|||||||
+152
-9
@@ -18,6 +18,11 @@
|
|||||||
let audioUrl = $state('');
|
let audioUrl = $state('');
|
||||||
let showSettings = $state(false);
|
let showSettings = $state(false);
|
||||||
|
|
||||||
|
// Project management state
|
||||||
|
let currentProjectPath = $state<string | null>(null);
|
||||||
|
let currentProjectName = $state('');
|
||||||
|
let audioFilePath = $state('');
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
@@ -44,8 +49,8 @@
|
|||||||
|
|
||||||
// Close export dropdown on outside click
|
// Close export dropdown on outside click
|
||||||
function handleClickOutside(e: MouseEvent) {
|
function handleClickOutside(e: MouseEvent) {
|
||||||
if (showExportMenu) {
|
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
if (showExportMenu) {
|
||||||
if (!target.closest('.export-dropdown')) {
|
if (!target.closest('.export-dropdown')) {
|
||||||
showExportMenu = false;
|
showExportMenu = false;
|
||||||
}
|
}
|
||||||
@@ -70,11 +75,136 @@
|
|||||||
// Speaker color palette for auto-assignment
|
// Speaker color palette for auto-assignment
|
||||||
const speakerColors = ['#e94560', '#4ecdc4', '#ffe66d', '#a8e6cf', '#ff8b94', '#c7ceea', '#ffd93d', '#6bcb77'];
|
const speakerColors = ['#e94560', '#4ecdc4', '#ffe66d', '#a8e6cf', '#ff8b94', '#c7ceea', '#ffd93d', '#6bcb77'];
|
||||||
|
|
||||||
|
async function saveProject() {
|
||||||
|
const defaultName = currentProjectName || 'Untitled';
|
||||||
|
const outputPath = await save({
|
||||||
|
defaultPath: `${defaultName}.vtn`,
|
||||||
|
filters: [{ name: 'Voice to Notes Project', extensions: ['vtn'] }],
|
||||||
|
});
|
||||||
|
if (!outputPath) return;
|
||||||
|
|
||||||
|
const projectData = {
|
||||||
|
version: 1,
|
||||||
|
name: outputPath.split(/[\\/]/).pop()?.replace('.vtn', '') || defaultName,
|
||||||
|
audio_file: audioFilePath,
|
||||||
|
created_at: new Date().toISOString(),
|
||||||
|
segments: $segments.map(seg => {
|
||||||
|
const speaker = $speakers.find(s => s.id === seg.speaker_id);
|
||||||
|
return {
|
||||||
|
text: seg.text,
|
||||||
|
start_ms: seg.start_ms,
|
||||||
|
end_ms: seg.end_ms,
|
||||||
|
speaker: speaker?.label ?? null,
|
||||||
|
is_edited: seg.is_edited,
|
||||||
|
words: seg.words.map(w => ({
|
||||||
|
word: w.word,
|
||||||
|
start_ms: w.start_ms,
|
||||||
|
end_ms: w.end_ms,
|
||||||
|
confidence: w.confidence ?? 0,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
speakers: $speakers.map(s => ({
|
||||||
|
label: s.label,
|
||||||
|
display_name: s.display_name,
|
||||||
|
color: s.color || '#e94560',
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await invoke('save_project_file', { path: outputPath, project: projectData });
|
||||||
|
currentProjectPath = outputPath;
|
||||||
|
currentProjectName = projectData.name;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to save project:', err);
|
||||||
|
alert(`Failed to save: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openProject() {
|
||||||
|
const filePath = await open({
|
||||||
|
filters: [{ name: 'Voice to Notes Project', extensions: ['vtn'] }],
|
||||||
|
multiple: false,
|
||||||
|
});
|
||||||
|
if (!filePath) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const project = await invoke<{
|
||||||
|
version: number;
|
||||||
|
name: string;
|
||||||
|
audio_file: string;
|
||||||
|
segments: Array<{
|
||||||
|
text: string;
|
||||||
|
start_ms: number;
|
||||||
|
end_ms: number;
|
||||||
|
speaker: string | null;
|
||||||
|
is_edited: boolean;
|
||||||
|
words: Array<{ word: string; start_ms: number; end_ms: number; confidence: number }>;
|
||||||
|
}>;
|
||||||
|
speakers: Array<{ label: string; display_name: string | null; color: string }>;
|
||||||
|
}>('load_project_file', { path: filePath });
|
||||||
|
|
||||||
|
// Rebuild speakers
|
||||||
|
const newSpeakers: Speaker[] = project.speakers.map((s, idx) => ({
|
||||||
|
id: `speaker-${idx}`,
|
||||||
|
project_id: '',
|
||||||
|
label: s.label,
|
||||||
|
display_name: s.display_name,
|
||||||
|
color: s.color,
|
||||||
|
}));
|
||||||
|
speakers.set(newSpeakers);
|
||||||
|
|
||||||
|
const speakerLookup = new Map(newSpeakers.map(s => [s.label, s.id]));
|
||||||
|
|
||||||
|
// Rebuild segments
|
||||||
|
const newSegments: Segment[] = project.segments.map((seg, idx) => ({
|
||||||
|
id: `seg-${idx}`,
|
||||||
|
project_id: '',
|
||||||
|
media_file_id: '',
|
||||||
|
speaker_id: seg.speaker ? (speakerLookup.get(seg.speaker) ?? null) : null,
|
||||||
|
start_ms: seg.start_ms,
|
||||||
|
end_ms: seg.end_ms,
|
||||||
|
text: seg.text,
|
||||||
|
original_text: null,
|
||||||
|
confidence: null,
|
||||||
|
is_edited: seg.is_edited,
|
||||||
|
edited_at: null,
|
||||||
|
segment_index: idx,
|
||||||
|
words: seg.words.map((w, widx) => ({
|
||||||
|
id: `word-${idx}-${widx}`,
|
||||||
|
segment_id: `seg-${idx}`,
|
||||||
|
word: w.word,
|
||||||
|
start_ms: w.start_ms,
|
||||||
|
end_ms: w.end_ms,
|
||||||
|
confidence: w.confidence,
|
||||||
|
word_index: widx,
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
segments.set(newSegments);
|
||||||
|
|
||||||
|
// Load audio
|
||||||
|
audioFilePath = project.audio_file;
|
||||||
|
audioUrl = convertFileSrc(project.audio_file);
|
||||||
|
waveformPlayer?.loadAudio(audioUrl);
|
||||||
|
|
||||||
|
currentProjectPath = filePath as string;
|
||||||
|
currentProjectName = project.name;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load project:', err);
|
||||||
|
alert(`Failed to load project: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleWordClick(timeMs: number) {
|
function handleWordClick(timeMs: number) {
|
||||||
console.log('[voice-to-notes] Word clicked, seeking to', timeMs, 'ms');
|
console.log('[voice-to-notes] Word clicked, seeking to', timeMs, 'ms');
|
||||||
waveformPlayer?.seekTo(timeMs);
|
waveformPlayer?.seekTo(timeMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleTextEdit(segmentId: string, newText: string) {
|
||||||
|
// In-memory store is already updated by TranscriptEditor.
|
||||||
|
// Changes persist when user saves the project file.
|
||||||
|
}
|
||||||
|
|
||||||
async function handleFileImport() {
|
async function handleFileImport() {
|
||||||
const filePath = await open({
|
const filePath = await open({
|
||||||
multiple: false,
|
multiple: false,
|
||||||
@@ -86,7 +216,8 @@
|
|||||||
});
|
});
|
||||||
if (!filePath) return;
|
if (!filePath) return;
|
||||||
|
|
||||||
// Convert file path to asset URL for wavesurfer
|
// Track the original file path and convert to asset URL for wavesurfer
|
||||||
|
audioFilePath = filePath;
|
||||||
audioUrl = convertFileSrc(filePath);
|
audioUrl = convertFileSrc(filePath);
|
||||||
waveformPlayer?.loadAudio(audioUrl);
|
waveformPlayer?.loadAudio(audioUrl);
|
||||||
|
|
||||||
@@ -245,6 +376,11 @@
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
segments.set(newSegments);
|
segments.set(newSegments);
|
||||||
|
|
||||||
|
// Set project name from audio file name (user can save explicitly)
|
||||||
|
const fileName = filePath.split(/[\\/]/).pop() || 'Untitled';
|
||||||
|
currentProjectName = fileName.replace(/\.[^.]+$/, '');
|
||||||
|
currentProjectPath = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Pipeline failed:', err);
|
console.error('Pipeline failed:', err);
|
||||||
alert(`Pipeline failed: ${err}`);
|
alert(`Pipeline failed: ${err}`);
|
||||||
@@ -316,8 +452,15 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="app-shell">
|
<div class="app-shell">
|
||||||
<div class="app-header">
|
<div class="app-header">
|
||||||
<h1>Voice to Notes</h1>
|
|
||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
|
<button class="settings-btn" onclick={openProject} disabled={isTranscribing}>
|
||||||
|
Open Project
|
||||||
|
</button>
|
||||||
|
{#if $segments.length > 0}
|
||||||
|
<button class="settings-btn" onclick={saveProject}>
|
||||||
|
Save Project
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
<button class="import-btn" onclick={handleFileImport} disabled={isTranscribing}>
|
<button class="import-btn" onclick={handleFileImport} disabled={isTranscribing}>
|
||||||
{#if isTranscribing}
|
{#if isTranscribing}
|
||||||
Processing...
|
Processing...
|
||||||
@@ -350,7 +493,7 @@
|
|||||||
<div class="workspace">
|
<div class="workspace">
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<WaveformPlayer bind:this={waveformPlayer} {audioUrl} />
|
<WaveformPlayer bind:this={waveformPlayer} {audioUrl} />
|
||||||
<TranscriptEditor onWordClick={handleWordClick} />
|
<TranscriptEditor onWordClick={handleWordClick} onTextEdit={handleTextEdit} />
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar-right">
|
<div class="sidebar-right">
|
||||||
<SpeakerManager />
|
<SpeakerManager />
|
||||||
@@ -381,10 +524,6 @@
|
|||||||
background: #0f3460;
|
background: #0f3460;
|
||||||
color: #e0e0e0;
|
color: #e0e0e0;
|
||||||
}
|
}
|
||||||
h1 {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
.import-btn {
|
.import-btn {
|
||||||
background: #e94560;
|
background: #e94560;
|
||||||
border: none;
|
border: none;
|
||||||
@@ -421,10 +560,14 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
}
|
}
|
||||||
.settings-btn:hover {
|
.settings-btn:hover:not(:disabled) {
|
||||||
background: rgba(255,255,255,0.05);
|
background: rgba(255,255,255,0.05);
|
||||||
border-color: #e94560;
|
border-color: #e94560;
|
||||||
}
|
}
|
||||||
|
.settings-btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
.export-dropdown {
|
.export-dropdown {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user