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:
MythEclipse
2026-06-09 22:04:05 +07:00
parent 823b342c2c
commit f04b0f0b42
20 changed files with 447 additions and 633 deletions
+4 -28
View File
@@ -191,34 +191,10 @@ export function createWebSocketServer(server: Server): WebSocketServer {
}
}
setBroadcastFunctions({
messageCreated: (data: unknown) =>
broadcast({ type: "message_created", data }),
messageUpdated: (data: unknown) =>
broadcast({ type: "message_updated", data }),
messageDeleted: (data: unknown) =>
broadcast({ type: "message_deleted", data }),
messageAnalyzed: (data: unknown) =>
broadcast({ type: "message_analyzed", data }),
attachmentCreated: (data: unknown) =>
broadcast({ type: "attachment_created", data }),
attachmentUploaded: (data: unknown) =>
broadcast({ type: "attachment_uploaded", data }),
voiceRecordingStarted: (data: unknown) =>
broadcast({ type: "voice_recording_started", data }),
voiceRecordingStopped: (data: unknown) =>
broadcast({ type: "voice_recording_stopped", data }),
voiceRecordingUploaded: (data: unknown) =>
broadcast({ type: "voice_recording_uploaded", data }),
voicePcmData: (data: unknown) =>
broadcast({ type: "voice_pcm_data", data }),
voiceActiveUser: (data: unknown) =>
broadcast({ type: "voice_active_user", data }),
analysisQueueStatus: (data: unknown) =>
broadcast({ type: "analysis_queue_status", data }),
raw: (type: string, data: unknown) => broadcast({ type, data }),
binary: broadcastBinary,
});
setBroadcastFunctions(
(type: string, data: unknown) => broadcast({ type, data }),
broadcastBinary,
);
// Cleanup on close
wss.on("close", () => {