Compare commits
12 Commits
3dff04ad95
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 22744bf0bd | |||
| 29c8ad0d60 | |||
| fff57ef774 | |||
| 95fcca4147 | |||
| 238bf47844 | |||
| 147c60fd64 | |||
| 1088edecd6 | |||
| b1c1a7bd6e | |||
| cdc551924e | |||
| 71a480dd80 | |||
| e5a3efc701 | |||
| ef52519d4d |
@@ -8,6 +8,7 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
||||||
|
GOPRIVATE: git.daviestechlabs.io
|
||||||
REGISTRY: gitea-http.gitea.svc.cluster.local:3000/daviestechlabs
|
REGISTRY: gitea-http.gitea.svc.cluster.local:3000/daviestechlabs
|
||||||
REGISTRY_HOST: gitea-http.gitea.svc.cluster.local:3000
|
REGISTRY_HOST: gitea-http.gitea.svc.cluster.local:3000
|
||||||
IMAGE_NAME: tts-module
|
IMAGE_NAME: tts-module
|
||||||
@@ -26,6 +27,9 @@ jobs:
|
|||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
|
- name: Configure private modules
|
||||||
|
run: git config --global url."https://gitea-actions:${{ secrets.DISPATCH_TOKEN }}@git.daviestechlabs.io/".insteadOf "https://git.daviestechlabs.io/"
|
||||||
|
|
||||||
- name: Run go vet
|
- name: Run go vet
|
||||||
run: go vet ./...
|
run: go vet ./...
|
||||||
|
|
||||||
@@ -50,6 +54,9 @@ jobs:
|
|||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
cache: true
|
cache: true
|
||||||
|
|
||||||
|
- name: Configure private modules
|
||||||
|
run: git config --global url."https://gitea-actions:${{ secrets.DISPATCH_TOKEN }}@git.daviestechlabs.io/".insteadOf "https://git.daviestechlabs.io/"
|
||||||
|
|
||||||
- name: Verify dependencies
|
- name: Verify dependencies
|
||||||
run: go mod verify
|
run: go mod verify
|
||||||
|
|
||||||
@@ -114,42 +121,19 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Configure insecure registry
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
buildkitd-config-inline: |
|
|
||||||
[registry."gitea-http.gitea.svc.cluster.local:3000"]
|
|
||||||
http = true
|
|
||||||
insecure = true
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
if: vars.DOCKERHUB_USERNAME != ''
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Configure Docker for insecure registry
|
|
||||||
run: |
|
run: |
|
||||||
sudo mkdir -p /etc/docker
|
sudo mkdir -p /etc/docker
|
||||||
echo '{"insecure-registries": ["${{ env.REGISTRY_HOST }}"]}' | sudo tee /etc/docker/daemon.json
|
echo '{"insecure-registries": ["${{ env.REGISTRY_HOST }}"]}' | sudo tee /etc/docker/daemon.json
|
||||||
sudo systemctl restart docker || sudo service docker restart || true
|
sudo kill -SIGHUP "$(pidof dockerd)" || true
|
||||||
sleep 2
|
sleep 3
|
||||||
|
|
||||||
- name: Login to Gitea Registry
|
- name: Login to Gitea Registry
|
||||||
run: |
|
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "${{ env.REGISTRY_HOST }}" -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
AUTH=$(echo -n "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_TOKEN }}" | base64 -w0)
|
|
||||||
mkdir -p ~/.docker
|
- name: Login to Docker Hub
|
||||||
cat > ~/.docker/config.json << EOF
|
if: vars.DOCKERHUB_USERNAME != ''
|
||||||
{
|
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ vars.DOCKERHUB_USERNAME }}" --password-stdin
|
||||||
"auths": {
|
|
||||||
"${{ env.REGISTRY_HOST }}": {
|
|
||||||
"auth": "$AUTH"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
echo "Auth configured for ${{ env.REGISTRY_HOST }}"
|
|
||||||
|
|
||||||
- name: Extract metadata
|
- name: Extract metadata
|
||||||
id: meta
|
id: meta
|
||||||
@@ -157,19 +141,25 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
tags: |
|
tags: |
|
||||||
type=semver,pattern={{version}},value=${{ needs.release.outputs.version }}
|
type=raw,value=${{ needs.release.outputs.version }}
|
||||||
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.version }}
|
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
run: |
|
||||||
with:
|
# Build with all tags
|
||||||
context: .
|
TAGS=""
|
||||||
push: true
|
while IFS= read -r tag; do
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
[ -n "$tag" ] && TAGS="$TAGS -t $tag"
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
done <<< "${{ steps.meta.outputs.tags }}"
|
||||||
cache-from: type=gha
|
docker build $TAGS \
|
||||||
cache-to: type=gha,mode=max
|
--label "org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}" \
|
||||||
|
--label "org.opencontainers.image.revision=${{ gitea.sha }}" \
|
||||||
|
.
|
||||||
|
# Push each tag
|
||||||
|
while IFS= read -r tag; do
|
||||||
|
[ -n "$tag" ] && docker push "$tag"
|
||||||
|
done <<< "${{ steps.meta.outputs.tags }}"
|
||||||
|
|
||||||
|
|
||||||
notify:
|
notify:
|
||||||
name: Notify
|
name: Notify
|
||||||
|
|||||||
@@ -1,201 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
env:
|
|
||||||
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
|
||||||
REGISTRY: gitea-http.gitea.svc.cluster.local:3000/daviestechlabs
|
|
||||||
REGISTRY_HOST: gitea-http.gitea.svc.cluster.local:3000
|
|
||||||
IMAGE_NAME: tts-module
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
name: Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up uv
|
|
||||||
run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
run: uv python install 3.12
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: uv sync --frozen --extra dev
|
|
||||||
|
|
||||||
- name: Run ruff check
|
|
||||||
run: uv run ruff check .
|
|
||||||
|
|
||||||
- name: Run ruff format check
|
|
||||||
run: uv run ruff format --check .
|
|
||||||
|
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up uv
|
|
||||||
run: curl -LsSf https://astral.sh/uv/install.sh | sh && echo "$HOME/.local/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
run: uv python install 3.12
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: uv sync --frozen --extra dev
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: uv run pytest -v
|
|
||||||
|
|
||||||
release:
|
|
||||||
name: Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [lint, test]
|
|
||||||
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
|
||||||
outputs:
|
|
||||||
version: ${{ steps.version.outputs.version }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Determine version bump
|
|
||||||
id: version
|
|
||||||
run: |
|
|
||||||
# Get latest tag or default to v0.0.0
|
|
||||||
LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
||||||
VERSION=${LATEST#v}
|
|
||||||
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
|
|
||||||
|
|
||||||
# Check commit message for keywords
|
|
||||||
MSG="${{ gitea.event.head_commit.message }}"
|
|
||||||
if echo "$MSG" | grep -qiE "^major:|BREAKING CHANGE"; then
|
|
||||||
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
|
|
||||||
BUMP="major"
|
|
||||||
elif echo "$MSG" | grep -qiE "^(minor:|feat:)"; then
|
|
||||||
MINOR=$((MINOR + 1)); PATCH=0
|
|
||||||
BUMP="minor"
|
|
||||||
else
|
|
||||||
PATCH=$((PATCH + 1))
|
|
||||||
BUMP="patch"
|
|
||||||
fi
|
|
||||||
|
|
||||||
NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
|
|
||||||
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "bump=$BUMP" >> $GITHUB_OUTPUT
|
|
||||||
echo "Bumping $LATEST → $NEW_VERSION ($BUMP)"
|
|
||||||
|
|
||||||
- name: Create and push tag
|
|
||||||
run: |
|
|
||||||
git config user.name "gitea-actions[bot]"
|
|
||||||
git config user.email "actions@git.daviestechlabs.io"
|
|
||||||
git tag -a ${{ steps.version.outputs.version }} -m "Release ${{ steps.version.outputs.version }}"
|
|
||||||
git push origin ${{ steps.version.outputs.version }}
|
|
||||||
|
|
||||||
docker:
|
|
||||||
name: Docker Build & Push
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [lint, test, release]
|
|
||||||
if: gitea.ref == 'refs/heads/main' && gitea.event_name == 'push'
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
buildkitd-config-inline: |
|
|
||||||
[registry."gitea-http.gitea.svc.cluster.local:3000"]
|
|
||||||
http = true
|
|
||||||
insecure = true
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
if: vars.DOCKERHUB_USERNAME != ''
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Configure Docker for insecure registry
|
|
||||||
run: |
|
|
||||||
sudo mkdir -p /etc/docker
|
|
||||||
echo '{"insecure-registries": ["${{ env.REGISTRY_HOST }}"]}' | sudo tee /etc/docker/daemon.json
|
|
||||||
sudo systemctl restart docker || sudo service docker restart || true
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
- name: Login to Gitea Registry
|
|
||||||
run: |
|
|
||||||
AUTH=$(echo -n "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_TOKEN }}" | base64 -w0)
|
|
||||||
mkdir -p ~/.docker
|
|
||||||
cat > ~/.docker/config.json << EOF
|
|
||||||
{
|
|
||||||
"auths": {
|
|
||||||
"${{ env.REGISTRY_HOST }}": {
|
|
||||||
"auth": "$AUTH"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
echo "Auth configured for ${{ env.REGISTRY_HOST }}"
|
|
||||||
|
|
||||||
- name: Extract metadata
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
||||||
tags: |
|
|
||||||
type=semver,pattern={{version}},value=${{ needs.release.outputs.version }}
|
|
||||||
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.version }}
|
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|
||||||
notify:
|
|
||||||
name: Notify
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [lint, test, release, docker]
|
|
||||||
if: always()
|
|
||||||
steps:
|
|
||||||
- name: Notify on success
|
|
||||||
if: needs.lint.result == 'success' && needs.test.result == 'success'
|
|
||||||
run: |
|
|
||||||
curl -s \
|
|
||||||
-H "Title: ✅ CI Passed: ${{ gitea.repository }}" \
|
|
||||||
-H "Priority: default" \
|
|
||||||
-H "Tags: white_check_mark,github" \
|
|
||||||
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
||||||
-d "Branch: ${{ gitea.ref_name }}
|
|
||||||
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
|
||||||
Release: ${{ needs.release.result == 'success' && needs.release.outputs.version || 'skipped' }}
|
|
||||||
Docker: ${{ needs.docker.result }}" \
|
|
||||||
${{ env.NTFY_URL }}/gitea-ci
|
|
||||||
|
|
||||||
- name: Notify on failure
|
|
||||||
if: needs.lint.result == 'failure' || needs.test.result == 'failure'
|
|
||||||
run: |
|
|
||||||
curl -s \
|
|
||||||
-H "Title: ❌ CI Failed: ${{ gitea.repository }}" \
|
|
||||||
-H "Priority: high" \
|
|
||||||
-H "Tags: x,github" \
|
|
||||||
-H "Click: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
||||||
-d "Branch: ${{ gitea.ref_name }}
|
|
||||||
Commit: ${{ gitea.event.head_commit.message || gitea.sha }}
|
|
||||||
Lint: ${{ needs.lint.result }}
|
|
||||||
Test: ${{ needs.test.result }}" \
|
|
||||||
${{ env.NTFY_URL }}/gitea-ci
|
|
||||||
60
.gitea/workflows/update-dependency.yml
Normal file
60
.gitea/workflows/update-dependency.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
name: Update handler-base
|
||||||
|
|
||||||
|
on:
|
||||||
|
repository_dispatch:
|
||||||
|
types: [handler-base-release]
|
||||||
|
|
||||||
|
env:
|
||||||
|
NTFY_URL: http://ntfy.observability.svc.cluster.local:80
|
||||||
|
GOPRIVATE: git.daviestechlabs.io
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update:
|
||||||
|
name: Update handler-base dependency
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.DISPATCH_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Configure Git
|
||||||
|
run: |
|
||||||
|
git config user.name "gitea-actions[bot]"
|
||||||
|
git config user.email "actions@git.daviestechlabs.io"
|
||||||
|
git config --global url."https://gitea-actions:${{ secrets.DISPATCH_TOKEN }}@git.daviestechlabs.io/".insteadOf "https://git.daviestechlabs.io/"
|
||||||
|
|
||||||
|
- name: Update handler-base
|
||||||
|
run: |
|
||||||
|
VERSION="${{ gitea.event.client_payload.version }}"
|
||||||
|
echo "Updating handler-base to ${VERSION}"
|
||||||
|
go get git.daviestechlabs.io/daviestechlabs/handler-base@${VERSION}
|
||||||
|
go mod tidy
|
||||||
|
|
||||||
|
- name: Commit and push
|
||||||
|
run: |
|
||||||
|
VERSION="${{ gitea.event.client_payload.version }}"
|
||||||
|
if git diff --quiet go.mod go.sum; then
|
||||||
|
echo "No changes to commit"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
git add go.mod go.sum
|
||||||
|
git commit -m "chore(deps): bump handler-base to ${VERSION}"
|
||||||
|
git push
|
||||||
|
|
||||||
|
- name: Notify
|
||||||
|
if: success()
|
||||||
|
run: |
|
||||||
|
VERSION="${{ gitea.event.client_payload.version }}"
|
||||||
|
curl -s \
|
||||||
|
-H "Title: 📦 Dep Update: ${{ gitea.repository }}" \
|
||||||
|
-H "Priority: default" \
|
||||||
|
-H "Tags: package,github" \
|
||||||
|
-d "handler-base updated to ${VERSION}" \
|
||||||
|
${{ env.NTFY_URL }}/gitea-ci
|
||||||
@@ -4,11 +4,14 @@ FROM golang:1.25-alpine AS builder
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install ca-certificates for HTTPS
|
# Install ca-certificates for HTTPS
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates git
|
||||||
|
|
||||||
|
ENV GOPRIVATE=git.daviestechlabs.io
|
||||||
|
ENV GONOSUMCHECK=git.daviestechlabs.io
|
||||||
|
|
||||||
# Copy go mod files
|
# Copy go mod files
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN --mount=type=secret,id=netrc,target=/root/.netrc go mod download
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|||||||
68
e2e_test.go
68
e2e_test.go
@@ -12,7 +12,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ────────────────────────────────────────────────────────────────────────────
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
@@ -24,13 +24,13 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
|||||||
audioSize := 65536
|
audioSize := 65536
|
||||||
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload map[string]any
|
var payload map[string]any
|
||||||
json.NewDecoder(r.Body).Decode(&payload)
|
_ = json.NewDecoder(r.Body).Decode(&payload)
|
||||||
if payload["text"] == nil || payload["text"] == "" {
|
if payload["text"] == nil || payload["text"] == "" {
|
||||||
w.WriteHeader(400)
|
w.WriteHeader(400)
|
||||||
w.Write([]byte("empty text"))
|
_, _ = w.Write([]byte("empty text"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(make([]byte, audioSize))
|
_, _ = w.Write(make([]byte, audioSize))
|
||||||
}))
|
}))
|
||||||
defer xttsSrv.Close()
|
defer xttsSrv.Close()
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
audioBytes, _ := io.ReadAll(resp.Body)
|
audioBytes, _ := io.ReadAll(resp.Body)
|
||||||
if len(audioBytes) != audioSize {
|
if len(audioBytes) != audioSize {
|
||||||
@@ -67,21 +67,21 @@ func TestSynthesisE2E_StreamChunks(t *testing.T) {
|
|||||||
|
|
||||||
// Verify typed chunk struct
|
// Verify typed chunk struct
|
||||||
msg := messages.TTSAudioChunk{
|
msg := messages.TTSAudioChunk{
|
||||||
SessionID: "test-session",
|
SessionId: "test-session",
|
||||||
ChunkIndex: chunkIdx,
|
ChunkIndex: int32(chunkIdx),
|
||||||
TotalChunks: totalChunks,
|
TotalChunks: int32(totalChunks),
|
||||||
Audio: chunk,
|
Audio: chunk,
|
||||||
IsLast: isLast,
|
IsLast: isLast,
|
||||||
SampleRate: 24000,
|
SampleRate: 24000,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round-trip through msgpack
|
// Round-trip through msgpack
|
||||||
data, _ := msgpack.Marshal(&msg)
|
data, _ := proto.Marshal(&msg)
|
||||||
var decoded messages.TTSAudioChunk
|
var decoded messages.TTSAudioChunk
|
||||||
msgpack.Unmarshal(data, &decoded)
|
_ = proto.Unmarshal(data, &decoded)
|
||||||
|
|
||||||
if decoded.SessionID != "test-session" {
|
if decoded.SessionId != "test-session" {
|
||||||
t.Errorf("chunk %d: session = %v", chunkIdx, decoded.SessionID)
|
t.Errorf("chunk %d: session = %v", chunkIdx, decoded.SessionId)
|
||||||
}
|
}
|
||||||
if decoded.IsLast != isLast {
|
if decoded.IsLast != isLast {
|
||||||
t.Errorf("chunk %d: is_last = %v, want %v", chunkIdx, decoded.IsLast, isLast)
|
t.Errorf("chunk %d: is_last = %v, want %v", chunkIdx, decoded.IsLast, isLast)
|
||||||
@@ -96,15 +96,15 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
// Set up voice registry with temp dir
|
// Set up voice registry with temp dir
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
voiceDir := filepath.Join(dir, "custom-en")
|
voiceDir := filepath.Join(dir, "custom-en")
|
||||||
os.MkdirAll(voiceDir, 0o755)
|
_ = os.MkdirAll(voiceDir, 0o755)
|
||||||
info := map[string]string{
|
info := map[string]string{
|
||||||
"name": "custom-en", "language": "en",
|
"name": "custom-en", "language": "en",
|
||||||
"type": "coqui-tts", "created_at": "2024-06-01",
|
"type": "coqui-tts", "created_at": "2024-06-01",
|
||||||
}
|
}
|
||||||
infoData, _ := json.Marshal(info)
|
infoData, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake-model"), 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake-model"), 0o644)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "config.json"), []byte("{}"), 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "config.json"), []byte("{}"), 0o644)
|
||||||
|
|
||||||
registry := newVoiceRegistry(dir)
|
registry := newVoiceRegistry(dir)
|
||||||
count := registry.refresh()
|
count := registry.refresh()
|
||||||
@@ -115,7 +115,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
// XTTS mock that validates custom voice fields
|
// XTTS mock that validates custom voice fields
|
||||||
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload map[string]any
|
var payload map[string]any
|
||||||
json.NewDecoder(r.Body).Decode(&payload)
|
_ = json.NewDecoder(r.Body).Decode(&payload)
|
||||||
|
|
||||||
// When custom voice is used, model_path should be set
|
// When custom voice is used, model_path should be set
|
||||||
if payload["model_path"] == nil {
|
if payload["model_path"] == nil {
|
||||||
@@ -124,7 +124,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
if payload["config_path"] == nil {
|
if payload["config_path"] == nil {
|
||||||
t.Error("expected config_path for voice with config")
|
t.Error("expected config_path for voice with config")
|
||||||
}
|
}
|
||||||
w.Write(make([]byte, 4000))
|
_, _ = w.Write(make([]byte, 4000))
|
||||||
}))
|
}))
|
||||||
defer xttsSrv.Close()
|
defer xttsSrv.Close()
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("status = %d, want 200", resp.StatusCode)
|
t.Errorf("status = %d, want 200", resp.StatusCode)
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ func TestSynthesisE2E_CustomVoice(t *testing.T) {
|
|||||||
func TestSynthesisE2E_XTTSError(t *testing.T) {
|
func TestSynthesisE2E_XTTSError(t *testing.T) {
|
||||||
failSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
failSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(503)
|
w.WriteHeader(503)
|
||||||
w.Write([]byte("model not loaded"))
|
_, _ = w.Write([]byte("model not loaded"))
|
||||||
}))
|
}))
|
||||||
defer failSrv.Close()
|
defer failSrv.Close()
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ func TestSynthesisE2E_XTTSError(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 503 {
|
if resp.StatusCode != 503 {
|
||||||
t.Errorf("status = %d, want 503", resp.StatusCode)
|
t.Errorf("status = %d, want 503", resp.StatusCode)
|
||||||
}
|
}
|
||||||
@@ -182,11 +182,11 @@ func TestVoiceRegistryMultiple(t *testing.T) {
|
|||||||
// Create 3 voices
|
// Create 3 voices
|
||||||
for _, name := range []string{"alice", "bob", "charlie"} {
|
for _, name := range []string{"alice", "bob", "charlie"} {
|
||||||
vDir := filepath.Join(dir, name)
|
vDir := filepath.Join(dir, name)
|
||||||
os.MkdirAll(vDir, 0o755)
|
_ = os.MkdirAll(vDir, 0o755)
|
||||||
info := map[string]string{"name": name, "language": "en"}
|
info := map[string]string{"name": name, "language": "en"}
|
||||||
data, _ := json.Marshal(info)
|
data, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
||||||
os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
registry := newVoiceRegistry(dir)
|
registry := newVoiceRegistry(dir)
|
||||||
@@ -216,7 +216,7 @@ func TestVoiceRegistryMultiple(t *testing.T) {
|
|||||||
|
|
||||||
func BenchmarkSynthesisRoundtrip(b *testing.B) {
|
func BenchmarkSynthesisRoundtrip(b *testing.B) {
|
||||||
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
xttsSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(make([]byte, 16000))
|
_, _ = w.Write(make([]byte, 16000))
|
||||||
}))
|
}))
|
||||||
defer xttsSrv.Close()
|
defer xttsSrv.Close()
|
||||||
|
|
||||||
@@ -227,8 +227,8 @@ func BenchmarkSynthesisRoundtrip(b *testing.B) {
|
|||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
resp, _ := client.Post(xttsSrv.URL+"/v1/audio/speech", "application/json",
|
resp, _ := client.Post(xttsSrv.URL+"/v1/audio/speech", "application/json",
|
||||||
bytes.NewReader(body))
|
bytes.NewReader(body))
|
||||||
io.ReadAll(resp.Body)
|
_, _ = io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,11 +237,11 @@ func BenchmarkVoiceRegistryRefresh(b *testing.B) {
|
|||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
name := "voice-" + strconv.Itoa(i)
|
name := "voice-" + strconv.Itoa(i)
|
||||||
vDir := filepath.Join(dir, name)
|
vDir := filepath.Join(dir, name)
|
||||||
os.MkdirAll(vDir, 0o755)
|
_ = os.MkdirAll(vDir, 0o755)
|
||||||
info := map[string]string{"name": name}
|
info := map[string]string{"name": name}
|
||||||
data, _ := json.Marshal(info)
|
data, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model_info.json"), data, 0o644)
|
||||||
os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
_ = os.WriteFile(filepath.Join(vDir, "model.pth"), []byte("fake"), 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
registry := newVoiceRegistry(dir)
|
registry := newVoiceRegistry(dir)
|
||||||
@@ -266,13 +266,13 @@ func BenchmarkAudioChunking(b *testing.B) {
|
|||||||
}
|
}
|
||||||
chunk := audioBytes[i:end]
|
chunk := audioBytes[i:end]
|
||||||
msg := &messages.TTSAudioChunk{
|
msg := &messages.TTSAudioChunk{
|
||||||
SessionID: "bench",
|
SessionId: "bench",
|
||||||
ChunkIndex: i / chunkSize,
|
ChunkIndex: int32(i / chunkSize),
|
||||||
TotalChunks: totalChunks,
|
TotalChunks: int32(totalChunks),
|
||||||
Audio: chunk,
|
Audio: chunk,
|
||||||
SampleRate: 24000,
|
SampleRate: 24000,
|
||||||
}
|
}
|
||||||
msgpack.Marshal(msg)
|
_, _ = proto.Marshal(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
go.mod
8
go.mod
@@ -3,9 +3,9 @@ module git.daviestechlabs.io/daviestechlabs/tts-module
|
|||||||
go 1.25.1
|
go 1.25.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.daviestechlabs.io/daviestechlabs/handler-base v0.0.0
|
git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0
|
||||||
github.com/nats-io/nats.go v1.48.0
|
github.com/nats-io/nats.go v1.48.0
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1
|
google.golang.org/protobuf v1.36.11
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -19,7 +19,6 @@ require (
|
|||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/nats-io/nkeys v0.4.11 // indirect
|
github.com/nats-io/nkeys v0.4.11 // indirect
|
||||||
github.com/nats-io/nuid v1.0.1 // indirect
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/otel v1.40.0 // indirect
|
go.opentelemetry.io/otel v1.40.0 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.40.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.40.0 // indirect
|
||||||
@@ -37,7 +36,4 @@ require (
|
|||||||
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
|
||||||
google.golang.org/grpc v1.78.0 // indirect
|
google.golang.org/grpc v1.78.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.11 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
replace git.daviestechlabs.io/daviestechlabs/handler-base => ../handler-base
|
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -1,3 +1,5 @@
|
|||||||
|
git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0 h1:pB3ehOKaDYQfbyRBKQXrB9curqSFteLrDveoElRKnBY=
|
||||||
|
git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0/go.mod h1:zocOHFt8yY3cW4+Xi37sNr5Tw7KcjGFSZqgWYxPWyqA=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
@@ -31,10 +33,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
|
||||||
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
|
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
|
||||||
|
|||||||
38
main.go
38
main.go
@@ -18,7 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/config"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/config"
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/health"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/health"
|
||||||
@@ -128,12 +128,12 @@ func (vr *VoiceRegistry) get(name string) *CustomVoice {
|
|||||||
return vr.voices[name]
|
return vr.voices[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vr *VoiceRegistry) listVoices() []messages.TTSVoiceInfo {
|
func (vr *VoiceRegistry) listVoices() []*messages.TTSVoiceInfo {
|
||||||
vr.mu.RLock()
|
vr.mu.RLock()
|
||||||
defer vr.mu.RUnlock()
|
defer vr.mu.RUnlock()
|
||||||
result := make([]messages.TTSVoiceInfo, 0, len(vr.voices))
|
result := make([]*messages.TTSVoiceInfo, 0, len(vr.voices))
|
||||||
for _, v := range vr.voices {
|
for _, v := range vr.voices {
|
||||||
result = append(result, messages.TTSVoiceInfo{
|
result = append(result, &messages.TTSVoiceInfo{
|
||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
Language: v.Language,
|
Language: v.Language,
|
||||||
ModelType: v.ModelType,
|
ModelType: v.ModelType,
|
||||||
@@ -223,7 +223,7 @@ func main() {
|
|||||||
// Helper: publish status
|
// Helper: publish status
|
||||||
publishStatus := func(sessionID, status, message string) {
|
publishStatus := func(sessionID, status, message string) {
|
||||||
statusMsg := &messages.TTSStatus{
|
statusMsg := &messages.TTSStatus{
|
||||||
SessionID: sessionID,
|
SessionId: sessionID,
|
||||||
Status: status,
|
Status: status,
|
||||||
Message: message,
|
Message: message,
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
@@ -262,7 +262,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("xtts request: %w", err)
|
return nil, fmt.Errorf("xtts request: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
respBody, _ := io.ReadAll(resp.Body)
|
respBody, _ := io.ReadAll(resp.Body)
|
||||||
@@ -285,13 +285,13 @@ func main() {
|
|||||||
isLast := end >= len(audioBytes)
|
isLast := end >= len(audioBytes)
|
||||||
|
|
||||||
msg := &messages.TTSAudioChunk{
|
msg := &messages.TTSAudioChunk{
|
||||||
SessionID: sessionID,
|
SessionId: sessionID,
|
||||||
ChunkIndex: chunkIndex,
|
ChunkIndex: int32(chunkIndex),
|
||||||
TotalChunks: totalChunks,
|
TotalChunks: int32(totalChunks),
|
||||||
Audio: chunk,
|
Audio: chunk,
|
||||||
IsLast: isLast,
|
IsLast: isLast,
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
SampleRate: sampleRate,
|
SampleRate: int32(sampleRate),
|
||||||
}
|
}
|
||||||
_ = nc.Publish(fmt.Sprintf("%s.%s", audioSubjectPrefix, sessionID), msg)
|
_ = nc.Publish(fmt.Sprintf("%s.%s", audioSubjectPrefix, sessionID), msg)
|
||||||
}
|
}
|
||||||
@@ -307,8 +307,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
sessionID := parts[4]
|
sessionID := parts[4]
|
||||||
|
|
||||||
req, err := natsutil.Decode[messages.TTSRequest](natMsg.Data)
|
var req messages.TTSRequest
|
||||||
if err != nil {
|
if err := natsutil.Decode(natMsg.Data, &req); err != nil {
|
||||||
slog.Error("decode error", "error", err)
|
slog.Error("decode error", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -343,10 +343,10 @@ func main() {
|
|||||||
streamAudio(sessionID, audioBytes)
|
streamAudio(sessionID, audioBytes)
|
||||||
} else {
|
} else {
|
||||||
msg := &messages.TTSFullResponse{
|
msg := &messages.TTSFullResponse{
|
||||||
SessionID: sessionID,
|
SessionId: sessionID,
|
||||||
Audio: audioBytes,
|
Audio: audioBytes,
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
SampleRate: sampleRate,
|
SampleRate: int32(sampleRate),
|
||||||
}
|
}
|
||||||
_ = nc.Publish(fmt.Sprintf("%s.%s", audioSubjectPrefix, sessionID), msg)
|
_ = nc.Publish(fmt.Sprintf("%s.%s", audioSubjectPrefix, sessionID), msg)
|
||||||
}
|
}
|
||||||
@@ -368,9 +368,9 @@ func main() {
|
|||||||
LastRefresh: registry.lastRefresh.Unix(),
|
LastRefresh: registry.lastRefresh.Unix(),
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
packed, _ := msgpack.Marshal(resp)
|
packed, _ := proto.Marshal(resp)
|
||||||
if msg.Reply != "" {
|
if msg.Reply != "" {
|
||||||
msg.Respond(packed)
|
_ = msg.Respond(packed)
|
||||||
}
|
}
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
slog.Error("subscribe voices list failed", "error", err)
|
slog.Error("subscribe voices list failed", "error", err)
|
||||||
@@ -380,13 +380,13 @@ func main() {
|
|||||||
if _, err := nc.Conn().Subscribe(voicesRefreshSubject, func(msg *nats.Msg) {
|
if _, err := nc.Conn().Subscribe(voicesRefreshSubject, func(msg *nats.Msg) {
|
||||||
count := registry.refresh()
|
count := registry.refresh()
|
||||||
resp := &messages.TTSVoiceRefreshResponse{
|
resp := &messages.TTSVoiceRefreshResponse{
|
||||||
Count: count,
|
Count: int32(count),
|
||||||
CustomVoices: registry.listVoices(),
|
CustomVoices: registry.listVoices(),
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
packed, _ := msgpack.Marshal(resp)
|
packed, _ := proto.Marshal(resp)
|
||||||
if msg.Reply != "" {
|
if msg.Reply != "" {
|
||||||
msg.Respond(packed)
|
_ = msg.Respond(packed)
|
||||||
}
|
}
|
||||||
slog.Info("voice registry refreshed on demand", "count", count)
|
slog.Info("voice registry refreshed on demand", "count", count)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|||||||
36
main_test.go
36
main_test.go
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||||
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVoiceRegistryRefresh(t *testing.T) {
|
func TestVoiceRegistryRefresh(t *testing.T) {
|
||||||
@@ -19,11 +19,11 @@ func TestVoiceRegistryRefresh(t *testing.T) {
|
|||||||
|
|
||||||
// Create a voice directory
|
// Create a voice directory
|
||||||
voiceDir := filepath.Join(dir, "test-voice")
|
voiceDir := filepath.Join(dir, "test-voice")
|
||||||
os.MkdirAll(voiceDir, 0o755)
|
_ = os.MkdirAll(voiceDir, 0o755)
|
||||||
info := map[string]string{"name": "test-voice", "language": "en", "type": "coqui-tts", "created_at": "2024-01-01"}
|
info := map[string]string{"name": "test-voice", "language": "en", "type": "coqui-tts", "created_at": "2024-01-01"}
|
||||||
infoData, _ := json.Marshal(info)
|
infoData, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake"), 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model.pth"), []byte("fake"), 0o644)
|
||||||
|
|
||||||
vr := newVoiceRegistry(dir)
|
vr := newVoiceRegistry(dir)
|
||||||
count := vr.refresh()
|
count := vr.refresh()
|
||||||
@@ -59,10 +59,10 @@ func TestVoiceRegistryMissing(t *testing.T) {
|
|||||||
func TestVoiceRegistryNoModel(t *testing.T) {
|
func TestVoiceRegistryNoModel(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
voiceDir := filepath.Join(dir, "bad-voice")
|
voiceDir := filepath.Join(dir, "bad-voice")
|
||||||
os.MkdirAll(voiceDir, 0o755)
|
_ = os.MkdirAll(voiceDir, 0o755)
|
||||||
info := map[string]string{"name": "bad-voice"}
|
info := map[string]string{"name": "bad-voice"}
|
||||||
infoData, _ := json.Marshal(info)
|
infoData, _ := json.Marshal(info)
|
||||||
os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
_ = os.WriteFile(filepath.Join(voiceDir, "model_info.json"), infoData, 0o644)
|
||||||
// No model.pth
|
// No model.pth
|
||||||
|
|
||||||
vr := newVoiceRegistry(dir)
|
vr := newVoiceRegistry(dir)
|
||||||
@@ -82,12 +82,12 @@ func TestSynthesizeHTTP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var payload map[string]any
|
var payload map[string]any
|
||||||
json.NewDecoder(r.Body).Decode(&payload)
|
_ = json.NewDecoder(r.Body).Decode(&payload)
|
||||||
if payload["text"] != "hello" {
|
if payload["text"] != "hello" {
|
||||||
t.Errorf("unexpected text: %v", payload["text"])
|
t.Errorf("unexpected text: %v", payload["text"])
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte{0x01, 0x02, 0x03, 0x04})
|
_, _ = w.Write([]byte{0x01, 0x02, 0x03, 0x04})
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
@@ -98,25 +98,25 @@ func TestSynthesizeHTTP(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
t.Errorf("status = %d, want 200", resp.StatusCode)
|
t.Errorf("status = %d, want 200", resp.StatusCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTTSRequestDecode(t *testing.T) {
|
func TestTTSRequestDecode(t *testing.T) {
|
||||||
req := messages.TTSRequest{
|
req := &messages.TTSRequest{
|
||||||
Text: "hello world",
|
Text: "hello world",
|
||||||
Speaker: "custom-en",
|
Speaker: "custom-en",
|
||||||
Language: "en",
|
Language: "en",
|
||||||
Stream: true,
|
Stream: true,
|
||||||
}
|
}
|
||||||
data, err := msgpack.Marshal(&req)
|
data, err := proto.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
decoded, err := natsutil.Decode[messages.TTSRequest](data)
|
var decoded messages.TTSRequest
|
||||||
if err != nil {
|
if err := natsutil.Decode(data, &decoded); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if decoded.Text != "hello world" {
|
if decoded.Text != "hello world" {
|
||||||
@@ -132,7 +132,7 @@ func TestTTSRequestDecode(t *testing.T) {
|
|||||||
|
|
||||||
func TestTTSAudioChunkRoundtrip(t *testing.T) {
|
func TestTTSAudioChunkRoundtrip(t *testing.T) {
|
||||||
chunk := messages.TTSAudioChunk{
|
chunk := messages.TTSAudioChunk{
|
||||||
SessionID: "sess-001",
|
SessionId: "sess-001",
|
||||||
ChunkIndex: 0,
|
ChunkIndex: 0,
|
||||||
TotalChunks: 2,
|
TotalChunks: 2,
|
||||||
Audio: make([]byte, 32768),
|
Audio: make([]byte, 32768),
|
||||||
@@ -140,16 +140,16 @@ func TestTTSAudioChunkRoundtrip(t *testing.T) {
|
|||||||
Timestamp: 1234567890,
|
Timestamp: 1234567890,
|
||||||
SampleRate: 24000,
|
SampleRate: 24000,
|
||||||
}
|
}
|
||||||
data, err := msgpack.Marshal(&chunk)
|
data, err := proto.Marshal(&chunk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
var got messages.TTSAudioChunk
|
var got messages.TTSAudioChunk
|
||||||
if err := msgpack.Unmarshal(data, &got); err != nil {
|
if err := proto.Unmarshal(data, &got); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if got.SessionID != "sess-001" {
|
if got.SessionId != "sess-001" {
|
||||||
t.Errorf("SessionID = %q", got.SessionID)
|
t.Errorf("SessionID = %q", got.SessionId)
|
||||||
}
|
}
|
||||||
if len(got.Audio) != 32768 {
|
if len(got.Audio) != 32768 {
|
||||||
t.Errorf("Audio len = %d", len(got.Audio))
|
t.Errorf("Audio len = %d", len(got.Audio))
|
||||||
|
|||||||
Reference in New Issue
Block a user