refactor(voice): optimize recording pipeline and improve performance
Refactor the voice recording and playback systems to improve efficiency, reduce latency, and enhance Docker build performance. - **Infrastructure**: Optimize Dockerfiles using build mounts for pnpm cache and reorder layers for better caching of dependencies and build tools. - **Backend/Gateway**: - Refactor `broadcast` module to use a generic event-based system instead of hardcoded functions. - Simplify voice recording logic by merging metadata and segment management into a unified `segment.ts`. - Optimize audio downsampling in `streamSetup.ts` using `Int16Array` views for better performance. - Implement `withFallback` utility for more robust Redis/Database command execution. - **Frontend**: - Optimize audio playback visualization using pre-computed level shapes and efficient RMS calculation. - Reduce latency in voice commands by prioritizing WebSocket communication over HTTP. - Improve base64 encoding efficiency in audio transmission. - **General**: - Add default value for `ADMIN_PASSWORD` in shared config. - Fix Docker healthcheck to use `127.0.0.1` instead of `localhost`.
This commit is contained in:
@@ -8,38 +8,42 @@ RUN npm install -g pnpm
|
||||
# Create non-root user
|
||||
RUN addgroup -S app && adduser -S -G app app
|
||||
|
||||
# Copy workspace files
|
||||
# Install build tools for native dependencies (node-crc, @discordjs/opus)
|
||||
# and ffmpeg for voice transmit (PCM to OggOpus encoding)
|
||||
# This is done early to cache this expensive layer
|
||||
RUN apk add --no-cache python3 make g++ rust cargo ffmpeg
|
||||
|
||||
# Copy dependency definition files first for better caching
|
||||
COPY pnpm-workspace.yaml .
|
||||
COPY pnpm-lock.yaml .
|
||||
COPY package.json .
|
||||
|
||||
# Copy patches (pnpm patchedDependencies)
|
||||
COPY patches ./patches
|
||||
|
||||
# Copy vendor packages (workspace dependencies)
|
||||
COPY vendor/discord.js-selfbot-v13 ./vendor/discord.js-selfbot-v13
|
||||
|
||||
# Copy packages (workspace dependencies)
|
||||
COPY packages/shared ./packages/shared
|
||||
|
||||
# Copy patches (pnpm patchedDependencies)
|
||||
COPY patches ./patches
|
||||
|
||||
# Copy service
|
||||
COPY services/discord-gateway ./services/discord-gateway
|
||||
|
||||
# Copy Drizzle migrations (relative path used by migrator)
|
||||
COPY services/discord-gateway/drizzle ./drizzle
|
||||
|
||||
# Install build tools for native dependencies (node-crc, @discordjs/opus)
|
||||
# and ffmpeg for voice transmit (PCM → OggOpus encoding)
|
||||
RUN apk add --no-cache python3 make g++ rust cargo ffmpeg
|
||||
# Copy service source (last — changes most often)
|
||||
COPY services/discord-gateway ./services/discord-gateway
|
||||
|
||||
# Install dependencies
|
||||
RUN pnpm install --frozen-lockfile
|
||||
# Install dependencies with build cache
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
# Build shared workspace dependency first
|
||||
RUN pnpm --filter './packages/shared' run build
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||
pnpm --filter './packages/shared' run build
|
||||
|
||||
# Build discord gateway
|
||||
RUN pnpm --filter './services/discord-gateway' run build
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||
pnpm --filter './services/discord-gateway' run build
|
||||
|
||||
# Create recordings directory
|
||||
RUN mkdir -p /app/recordings
|
||||
|
||||
Reference in New Issue
Block a user