Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat(meeting): add WebRTC AEC helper and text-level dedupe
Gabriel Stein068280ba86d5
diff --git a/.github/workflows/build-and-notarize.yml b/.github/workflows/build-and-notarize.ymlindex d29829d52..4d4b08153 100644--- a/.github/workflows/build-and-notarize.yml+++ b/.github/workflows/build-and-notarize.yml@@ -37,7 +37,7 @@ jobs:uses: actions/cache@v4with:path: resources/bin- key: linux-x64-bin-${{ hashFiles('scripts/download-*.js') }}+ key: linux-x64-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-meeting-aec-helper.js', 'scripts/lib/meeting-aec-build.js', 'native/meeting-aec-helper/**') }}- name: Download whisper.cpp binariesrun: node scripts/download-whisper-cpp.js --current@@ -112,7 +112,7 @@ jobs:uses: actions/cache@v4with:path: resources/bin- key: windows-x64-bin-${{ hashFiles('scripts/download-*.js') }}+ key: windows-x64-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-meeting-aec-helper.js', 'scripts/lib/meeting-aec-build.js', 'native/meeting-aec-helper/**') }}- name: Download whisper.cpp binariesrun: node scripts/download-whisper-cpp.js --current@@ -213,7 +213,7 @@ jobs:uses: actions/cache@v4with:path: resources/bin- key: macos-${{ matrix.arch }}-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-globe-listener.js', 'resources/macos-globe-listener.swift', 'scripts/build-macos-fast-paste.js', 'resources/macos-fast-paste.swift') }}+ key: macos-${{ matrix.arch }}-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-globe-listener.js', 'resources/macos-globe-listener.swift', 'scripts/build-macos-fast-paste.js', 'resources/macos-fast-paste.swift', 'scripts/build-meeting-aec-helper.js', 'scripts/lib/meeting-aec-build.js', 'native/meeting-aec-helper/**') }}- name: Download whisper.cpp binariesrun: node scripts/download-whisper-cpp.js --current --platform darwin --arch ${{ matrix.arch }}diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 7b3cc63ab..65a316f2e 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -36,7 +36,7 @@ jobs:uses: actions/cache@v4with:path: resources/bin- key: linux-x64-bin-${{ hashFiles('scripts/download-*.js') }}+ key: linux-x64-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-meeting-aec-helper.js', 'scripts/lib/meeting-aec-build.js', 'native/meeting-aec-helper/**') }}- name: Download whisper.cpp binariesrun: node scripts/download-whisper-cpp.js --current@@ -104,7 +104,7 @@ jobs:uses: actions/cache@v4with:path: resources/bin- key: windows-x64-bin-${{ hashFiles('scripts/download-*.js') }}+ key: windows-x64-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-meeting-aec-helper.js', 'scripts/lib/meeting-aec-build.js', 'native/meeting-aec-helper/**') }}- name: Download whisper.cpp binariesrun: node scripts/download-whisper-cpp.js --current@@ -198,7 +198,7 @@ jobs:uses: actions/cache@v4with:path: resources/bin- key: macos-${{ matrix.arch }}-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-globe-listener.js', 'resources/macos-globe-listener.swift', 'scripts/build-macos-fast-paste.js', 'resources/macos-fast-paste.swift') }}+ key: macos-${{ matrix.arch }}-bin-${{ hashFiles('scripts/download-*.js', 'scripts/build-globe-listener.js', 'resources/macos-globe-listener.swift', 'scripts/build-macos-fast-paste.js', 'resources/macos-fast-paste.swift', 'scripts/build-meeting-aec-helper.js', 'scripts/lib/meeting-aec-build.js', 'native/meeting-aec-helper/**') }}- name: Download whisper.cpp binariesrun: node scripts/download-whisper-cpp.js --current --platform darwin --arch ${{ matrix.arch }}diff --git a/.gitignore b/.gitignoreindex 40ea942e5..a8f91c681 100644--- a/.gitignore+++ b/.gitignore@@ -190,6 +190,8 @@ build/# Generated Globe listener binaryresources/bin/+native/meeting-aec-helper/build/+native/meeting-aec-helper/third_party/# macOS.DS_Storediff --git a/electron-builder.json b/electron-builder.jsonindex 78f063f72..cfc3f4dd0 100644--- a/electron-builder.json+++ b/electron-builder.json@@ -105,6 +105,7 @@"llama-server-*","sherpa-onnx-*","qdrant-*",+ "meeting-aec-helper-*","windows-key-listener*","windows-mic-listener*","windows-text-monitor*",diff --git a/main.js b/main.jsindex fd0842eca..81eef3fb0 100644--- a/main.js+++ b/main.js@@ -205,6 +205,7 @@ const MeetingProcessDetector = require("./src/helpers/meetingProcessDetector");const AudioActivityDetector = require("./src/helpers/audioActivityDetector");const AudioTapManager = require("./src/helpers/audioTapManager");const LinuxPortalAudioManager = require("./src/helpers/linuxPortalAudioManager");+const MeetingAecManager = require("./src/helpers/meetingAecManager");const MeetingDetectionEngine = require("./src/helpers/meetingDetectionEngine");const { i18nMain, changeLanguage } = require("./src/helpers/i18nMain");const { ensureYdotool } = require("./src/helpers/ensureYdotool");@@ -229,6 +230,7 @@ let googleCalendarManager = null;let meetingDetectionEngine = null;let audioTapManager = null;let linuxPortalAudioManager = null;+let meetingAecManager = null;let qdrantManager = null;let ipcHandlers = null;let globeKeyAlertShown = false;@@ -309,6 +311,7 @@ function initializeCoreManagers() {textEditMonitor = new TextEditMonitor();audioTapManager = new AudioTapManager();linuxPortalAudioManager = new LinuxPortalAudioManager();+ meetingAecManager = new MeetingAecManager();windowManager.textEditMonitor = textEditMonitor;// IPC handlers must be registered before window content loads@@ -328,6 +331,7 @@ function initializeCoreManagers() {meetingDetectionEngine,audioTapManager,linuxPortalAudioManager,+ meetingAecManager,getTrayManager: () => trayManager,});}@@ -1198,6 +1202,9 @@ if (gotSingleInstanceLock) {if (linuxPortalAudioManager) {linuxPortalAudioManager.stop().catch(() => {});}+ if (meetingAecManager) {+ meetingAecManager.stop().catch(() => {});+ }if (ipcHandlers) {ipcHandlers._cleanupTextEditMonitor();}diff --git a/native/meeting-aec-helper/CMakeLists.txt b/native/meeting-aec-helper/CMakeLists.txtnew file mode 100644index 000000000..fa10c75ad--- /dev/null+++ b/native/meeting-aec-helper/CMakeLists.txt@@ -0,0 +1,35 @@+cmake_minimum_required(VERSION 3.16)+project(meeting_aec_helper LANGUAGES C CXX)++set(CMAKE_C_STANDARD 11)+set(CMAKE_C_STANDARD_REQUIRED ON)+set(CMAKE_C_EXTENSIONS OFF)+set(CMAKE_CXX_STANDARD 20)+set(CMAKE_CXX_STANDARD_REQUIRED ON)+set(CMAKE_CXX_EXTENSIONS OFF)++if(NOT DEFINED MEETING_AEC_GENERATED_CMAKE)+ message(FATAL_ERROR "MEETING_AEC_GENERATED_CMAKE must point to a generated source manifest")+endif()++include(${MEETING_AEC_GENERATED_CMAKE})++add_executable(+ meeting-aec-helper+ src/main.cc+ src/aec_processor.cc+ src/null_aec_dump_factory.cc+ ${MEETING_AEC_WEBRTC_SOURCES}+ ${MEETING_AEC_ABSL_SOURCES}+)++target_include_directories(+ meeting-aec-helper+ PRIVATE+ src+ ${MEETING_AEC_INCLUDE_DIRS}+)++target_compile_definitions(meeting-aec-helper PRIVATE ${MEETING_AEC_DEFINES})+target_compile_options(meeting-aec-helper PRIVATE ${MEETING_AEC_COMPILE_OPTIONS})+target_link_options(meeting-aec-helper PRIVATE ${MEETING_AEC_LINK_OPTIONS})diff --git a/native/meeting-aec-helper/src/aec_processor.cc b/native/meeting-aec-helper/src/aec_processor.ccnew file mode 100644index 000000000..d3d48c1ec--- /dev/null+++ b/native/meeting-aec-helper/src/aec_processor.cc@@ -0,0 +1,197 @@+#include "aec_processor.h"++#include <algorithm>+#include <array>+#include <cstring>+#include <utility>++#include "api/audio/audio_processing.h"+#include "api/audio/builtin_audio_processing_builder.h"+#include "api/audio/echo_canceller3_factory.h"+#include "api/environment/environment_factory.h"+#include "common_audio/resampler/include/push_resampler.h"++namespace {++constexpr int kInputSampleRate = 24000;+constexpr int kProcessingSampleRate = 48000;+constexpr size_t kFrameMs = 10;+constexpr size_t kChannelCount = 1;++} // namespace++AecProcessor::AecProcessor(int sample_rate_hz)+ : sample_rate_hz_(sample_rate_hz),+ input_frame_samples_(static_cast<size_t>(sample_rate_hz_) * kFrameMs / 1000),+ processing_frame_samples_(kProcessingSampleRate * kFrameMs / 1000) {+ if (sample_rate_hz_ != kInputSampleRate) {+ return;+ }++ webrtc::AudioProcessing::Config config;+ config.pipeline.maximum_internal_processing_rate = kProcessingSampleRate;+ config.echo_canceller.enabled = true;+ config.echo_canceller.enforce_high_pass_filtering = false;+ config.high_pass_filter.enabled = false;+ config.noise_suppression.enabled = false;+ config.transient_suppression.enabled = false;+ config.gain_controller1.enabled = false;+ config.gain_controller2.enabled = false;+ config.capture_level_adjustment.enabled = false;++ webrtc::EchoCanceller3Config echo_config;+ webrtc::BuiltinAudioProcessingBuilder builder(config);+ builder.SetEchoControlFactory(std::make_unique<webrtc::EchoCanceller3Factory>(echo_config));+ apm_ = builder.Build(webrtc::CreateEnvironment());+ if (!apm_) {+ return;+ }++ const webrtc::ProcessingConfig processing_config = {{+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ }};++ if (apm_->Initialize(processing_config) != webrtc::AudioProcessing::kNoError) {+ apm_ = nullptr;+ return;+ }++ system_upsampler_ = std::make_unique<webrtc::PushResampler<int16_t>>(+ input_frame_samples_,+ processing_frame_samples_,+ kChannelCount);+ mic_upsampler_ = std::make_unique<webrtc::PushResampler<int16_t>>(+ input_frame_samples_,+ processing_frame_samples_,+ kChannelCount);+ mic_downsampler_ = std::make_unique<webrtc::PushResampler<int16_t>>(+ processing_frame_samples_,+ input_frame_samples_,+ kChannelCount);+}++AecProcessor::~AecProcessor() = default;++bool AecProcessor::isReady() const {+ return apm_ && system_upsampler_ && mic_upsampler_ && mic_downsampler_;+}++void AecProcessor::RecordSystemChunk(const std::vector<int16_t>& samples) {+ if (samples.empty() || !isReady()) {+ return;+ }++ pending_system_input_.insert(+ pending_system_input_.end(), samples.begin(), samples.end());+ ProcessReadySystemFrames();+}++std::vector<int16_t> AecProcessor::ProcessMicChunk(const std::vector<int16_t>& samples) {+ if (samples.empty()) {+ return {};+ }++ if (!isReady()) {+ return samples;+ }++ pending_mic_input_.insert(pending_mic_input_.end(), samples.begin(), samples.end());+ ProcessReadyMicFrames();+ return DrainCleanedOutput();+}++std::vector<int16_t> AecProcessor::Flush() {+ if (!isReady()) {+ return {};+ }++ if (!pending_system_input_.empty()) {+ std::vector<int16_t> padded_system(input_frame_samples_, 0);+ std::copy(+ pending_system_input_.begin(),+ pending_system_input_.end(),+ padded_system.begin());+ pending_system_input_.clear();+ ProcessSystemFrame24k(padded_system.data());+ }++ if (!pending_mic_input_.empty()) {+ const size_t valid_samples = pending_mic_input_.size();+ std::vector<int16_t> padded_mic(input_frame_samples_, 0);+ std::copy(pending_mic_input_.begin(), pending_mic_input_.end(), padded_mic.begin());+ pending_mic_input_.clear();+ ProcessMicFrame24k(padded_mic.data(), valid_samples);+ }++ return DrainCleanedOutput();+}++void AecProcessor::ProcessReadySystemFrames() {+ while (pending_system_input_.size() >= input_frame_samples_) {+ ProcessSystemFrame24k(pending_system_input_.data());+ pending_system_input_.erase(+ pending_system_input_.begin(),+ pending_system_input_.begin() + static_cast<std::ptrdiff_t>(input_frame_samples_));+ }+}++void AecProcessor::ProcessReadyMicFrames() {+ while (pending_mic_input_.size() >= input_frame_samples_) {+ ProcessMicFrame24k(pending_mic_input_.data(), input_frame_samples_);+ pending_mic_input_.erase(+ pending_mic_input_.begin(),+ pending_mic_input_.begin() + static_cast<std::ptrdiff_t>(input_frame_samples_));+ }+}++std::vector<int16_t> AecProcessor::DrainCleanedOutput() {+ std::vector<int16_t> output;+ output.swap(cleaned_output_);+ return output;+}++void AecProcessor::ProcessSystemFrame24k(const int16_t* frame24k) {+ std::array<int16_t, kProcessingSampleRate * kFrameMs / 1000> frame48k = {};+ system_upsampler_->Resample(+ webrtc::MonoView<const int16_t>(frame24k, input_frame_samples_),+ webrtc::MonoView<int16_t>(frame48k.data(), frame48k.size()));++ apm_->ProcessReverseStream(+ frame48k.data(),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ frame48k.data());+}++void AecProcessor::ProcessMicFrame24k(const int16_t* frame24k, size_t output_samples_24k) {+ std::array<int16_t, kProcessingSampleRate * kFrameMs / 1000> frame48k = {};+ mic_upsampler_->Resample(+ webrtc::MonoView<const int16_t>(frame24k, input_frame_samples_),+ webrtc::MonoView<int16_t>(frame48k.data(), frame48k.size()));++ const int result = apm_->ProcessStream(+ frame48k.data(),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ webrtc::StreamConfig(kProcessingSampleRate, kChannelCount),+ frame48k.data());++ std::array<int16_t, kInputSampleRate * kFrameMs / 1000> cleaned24k = {};+ if (result == webrtc::AudioProcessing::kNoError) {+ mic_downsampler_->Resample(+ webrtc::MonoView<const int16_t>(frame48k.data(), frame48k.size()),+ webrtc::MonoView<int16_t>(cleaned24k.data(), cleaned24k.size()));+ } else {+ std::memcpy(+ cleaned24k.data(),+ frame24k,+ std::min(output_samples_24k, input_frame_samples_) * sizeof(int16_t));+ }++ cleaned_output_.insert(+ cleaned_output_.end(),+ cleaned24k.begin(),+ cleaned24k.begin() + static_cast<std::ptrdiff_t>(output_samples_24k));+}diff --git a/native/meeting-aec-helper/src/aec_processor.h b/native/meeting-aec-helper/src/aec_processor.hnew file mode 100644index 000000000..b2c777cc0--- /dev/null+++ b/native/meeting-aec-helper/src/aec_processor.h@@ -0,0 +1,42 @@+#pragma once++#include <cstdint>+#include <memory>+#include <vector>++#include "api/scoped_refptr.h"++namespace webrtc {+class AudioProcessing;+template <typename T>+class PushResampler;+} // namespace webrtc++class AecProcessor {+ public:+ explicit AecProcessor(int sample_rate_hz);+ ~AecProcessor();++ void RecordSystemChunk(const std::vector<int16_t>& samples);+ std::vector<int16_t> ProcessMicChunk(const std::vector<int16_t>& samples);+ std::vector<int16_t> Flush();+ bool isReady() const;++ private:+ void ProcessReadySystemFrames();+ void ProcessReadyMicFrames();+ std::vector<int16_t> DrainCleanedOutput();+ void ProcessSystemFrame24k(const int16_t* frame24k);+ void ProcessMicFrame24k(const int16_t* frame24k, size_t output_samples_24k);++ int sample_rate_hz_;+ size_t input_frame_samples_;+ size_t processing_frame_samples_;+ std::vector<int16_t> pending_system_input_;+ std::vector<int16_t> pending_mic_input_;+ std::vector<int16_t> cleaned_output_;+ webrtc::scoped_refptr<webrtc::AudioProcessing> apm_;+ std::unique_ptr<webrtc::PushResampler<int16_t>> system_upsampler_;+ std::unique_ptr<webrtc::PushResampler<int16_t>> mic_upsampler_;+ std::unique_ptr<webrtc::PushResampler<int16_t>> mic_downsampler_;+};diff --git a/native/meeting-aec-helper/src/main.cc b/native/meeting-aec-helper/src/main.ccnew file mode 100644index 000000000..37f769f5f--- /dev/null+++ b/native/meeting-aec-helper/src/main.cc@@ -0,0 +1,175 @@+#include "aec_processor.h"++#include <cstdint>+#include <cstring>+#include <iostream>+#include <string>+#include <vector>++#ifdef _WIN32+#include <fcntl.h>+#include <io.h>+#endif++#include "rtc_base/logging.h"++namespace {++constexpr uint8_t kSystemStream = 1;+constexpr uint8_t kMicStream = 2;+constexpr int kDefaultSampleRate = 24000;++void SetBinaryMode() {+#ifdef _WIN32+ _setmode(_fileno(stdin), _O_BINARY);+ _setmode(_fileno(stdout), _O_BINARY);+#endif+}++void EmitJsonLine(const std::string& line) {+ std::cerr << line << std::endl;+}++bool ReadExact(char* buffer, size_t length) {+ size_t read = 0;+ while (read < length) {+ std::cin.read(buffer + read, static_cast<std::streamsize>(length - read));+ const auto count = static_cast<size_t>(std::cin.gcount());+ if (count == 0) {+ return false;+ }+ read += count;+ }+ return true;+}++bool WriteAll(const char* buffer, size_t length) {+ std::cout.write(buffer, static_cast<std::streamsize>(length));+ return static_cast<bool>(std::cout);+}++uint32_t ReadUint32Le(const char* buffer) {+ return static_cast<uint32_t>(static_cast<uint8_t>(buffer[0])) |+ (static_cast<uint32_t>(static_cast<uint8_t>(buffer[1])) << 8U) |+ (static_cast<uint32_t>(static_cast<uint8_t>(buffer[2])) << 16U) |+ (static_cast<uint32_t>(static_cast<uint8_t>(buffer[3])) << 24U);+}++void WriteUint32Le(uint32_t value, char* buffer) {+ buffer[0] = static_cast<char>(value & 0xffU);+ buffer[1] = static_cast<char>((value >> 8U) & 0xffU);+ buffer[2] = static_cast<char>((value >> 16U) & 0xffU);+ buffer[3] = static_cast<char>((value >> 24U) & 0xffU);+}++std::vector<int16_t> BytesToSamples(const std::vector<char>& bytes) {+ std::vector<int16_t> samples(bytes.size() / 2U);+ std::memcpy(samples.data(), bytes.data(), samples.size() * sizeof(int16_t));+ return samples;+}++std::vector<char> SamplesToBytes(const std::vector<int16_t>& samples) {+ std::vector<char> bytes(samples.size() * sizeof(int16_t));+ std::memcpy(bytes.data(), samples.data(), bytes.size());+ return bytes;+}++int ParseSampleRate(int argc, char* argv[]) {+ for (int index = 1; index < argc; index += 1) {+ if (std::string(argv[index]) == "--sample-rate" && index + 1 < argc) {+ try {+ return std::stoi(argv[index + 1]);+ } catch (...) {+ return kDefaultSampleRate;+ }+ }+ }+ return kDefaultSampleRate;+}++} // namespace++int main(int argc, char* argv[]) {+ SetBinaryMode();+ webrtc::LogMessage::SetLogToStderr(false);+ webrtc::LogMessage::LogToDebug(webrtc::LS_NONE);++ const int sample_rate_hz = ParseSampleRate(argc, argv);+ AecProcessor processor(sample_rate_hz);+ if (!processor.isReady()) {+ EmitJsonLine(+ "{\"type\":\"error\",\"code\":\"init_failed\",\"message\":\"Failed to initialize WebRTC AEC processor.\"}");+ return 1;+ }++ EmitJsonLine(+ "{\"type\":\"start\",\"backend\":\"webrtc-apm-aec3\",\"sampleRate\":" ++ std::to_string(sample_rate_hz) + "}");++ while (true) {+ char header[5];+ if (!ReadExact(header, sizeof(header))) {+ break;+ }++ const uint8_t stream_type = static_cast<uint8_t>(header[0]);+ const uint32_t payload_size = ReadUint32Le(header + 1);+ if (payload_size == 0 || payload_size % 2U != 0U) {+ EmitJsonLine("{\"type\":\"warning\",\"code\":\"invalid_frame\",\"message\":\"Ignored invalid frame.\"}");+ if (payload_size == 0) {+ continue;+ }+ std::vector<char> discard(payload_size);+ if (!ReadExact(discard.data(), discard.size())) {+ break;+ }+ continue;+ }++ std::vector<char> payload(payload_size);+ if (!ReadExact(payload.data(), payload.size())) {+ break;+ }++ const auto samples = BytesToSamples(payload);+ if (stream_type == kSystemStream) {+ processor.RecordSystemChunk(samples);+ continue;+ }++ if (stream_type != kMicStream) {+ EmitJsonLine("{\"type\":\"warning\",\"code\":\"unknown_stream\",\"message\":\"Ignored unknown stream type.\"}");+ continue;+ }++ const auto cleaned = processor.ProcessMicChunk(samples);+ if (!cleaned.empty()) {+ const auto bytes = SamplesToBytes(cleaned);+ char output_header[4];+ WriteUint32Le(static_cast<uint32_t>(bytes.size()), output_header);+ if (!WriteAll(output_header, sizeof(output_header)) ||+ !WriteAll(bytes.data(), bytes.size())) {+ EmitJsonLine("{\"type\":\"error\",\"code\":\"write_failed\",\"message\":\"Failed to write cleaned mic frame.\"}");+ return 1;+ }++ std::cout.flush();+ }+ }++ const auto flushed = processor.Flush();+ if (!flushed.empty()) {+ const auto bytes = SamplesToBytes(flushed);+ char output_header[4];+ WriteUint32Le(static_cast<uint32_t>(bytes.size()), output_header);+ if (!WriteAll(output_header, sizeof(output_header)) ||+ !WriteAll(bytes.data(), bytes.size())) {+ EmitJsonLine("{\"type\":\"error\",\"code\":\"write_failed\",\"message\":\"Failed to flush cleaned mic frame.\"}");+ return 1;+ }++ std::cout.flush();+ }++ return 0;+}diff --git a/native/meeting-aec-helper/src/null_aec_dump_factory.cc b/native/meeting-aec-helper/src/null_aec_dump_factory.ccnew file mode 100644index 000000000..c386dca4f--- /dev/null+++ b/native/meeting-aec-helper/src/null_aec_dump_factory.cc@@ -0,0 +1,26 @@+#include "modules/audio_processing/aec_dump/aec_dump_factory.h"++namespace webrtc {++std::unique_ptr<AecDump> AecDumpFactory::Create(+ FileWrapper,+ int64_t,+ TaskQueueBase*) {+ return nullptr;+}++std::unique_ptr<AecDump> AecDumpFactory::Create(+ absl::string_view,+ int64_t,+ TaskQueueBase*) {+ return nullptr;+}++std::unique_ptr<AecDump> AecDumpFactory::Create(+ FILE*,+ int64_t,+ TaskQueueBase*) {+ return nullptr;+}++} // namespace webrtcdiff --git a/package.json b/package.jsonindex 5ec59d6e4..bfad5e59e 100644--- a/package.json+++ b/package.json@@ -18,7 +18,8 @@"compile:media-remote": "node scripts/build-media-remote.js","compile:mic-listener": "node scripts/build-macos-mic-listener.js","compile:audio-tap": "node scripts/build-macos-audio-tap.js",- "compile:native": "npm run compile:globe && npm run compile:fast-paste && npm run compile:winkeys && npm run compile:winpaste && npm run compile:linux-paste && npm run compile:linux-system-audio && npm run compile:text-monitor && npm run compile:media-remote && npm run compile:mic-listener && npm run compile:audio-tap",+ "compile:meeting-aec": "node scripts/build-meeting-aec-helper.js",+ "compile:native": "npm run compile:globe && npm run compile:fast-paste && npm run compile:winkeys && npm run compile:winpaste && npm run compile:linux-paste && npm run compile:linux-system-audio && npm run compile:text-monitor && npm run compile:media-remote && npm run compile:mic-listener && npm run compile:audio-tap && npm run compile:meeting-aec","prestart": "npm run compile:native && npm run download:qdrant && npm run download:embedding-model","start": "electron .","predev": "npm run compile:native && npm run download:qdrant && npm run download:embedding-model",diff --git a/scripts/afterPack.js b/scripts/afterPack.jsindex 31fbd2c2c..99f902409 100644--- a/scripts/afterPack.js+++ b/scripts/afterPack.js@@ -121,6 +121,36 @@ exec -a "$0" "$HERE/${binaryName}-app" "\${FLAGS[@]}" "$@"fs.writeFileSync(binaryPath, wrapper, { mode: 0o755 });}+function verifyMeetingAecHelper(context) {+ const platform = context.electronPlatformName;+ const archName = Arch[context.arch];++ if (!["darwin", "linux", "win32"].includes(platform)) {+ return;+ }++ const binaryName = `meeting-aec-helper-${platform}-${archName}${platform === "win32" ? ".exe" : ""}`;+ const resourcesDir =+ platform === "darwin"+ ? path.join(+ context.appOutDir,+ `${context.packager.appInfo.productFilename}.app`,+ "Contents",+ "Resources"+ )+ : path.join(context.appOutDir, "resources");+ const binaryPath = path.join(resourcesDir, "bin", binaryName);++ if (!fs.existsSync(binaryPath)) {+ console.warn(` afterPack: missing optional meeting AEC helper (${binaryName})`);+ return;+ }++ if (platform !== "win32") {+ fs.chmodSync(binaryPath, 0o755);+ }+}+// ---------------------------------------------------------------------------// Main hook// ---------------------------------------------------------------------------@@ -128,4 +158,5 @@ exec -a "$0" "$HERE/${binaryName}-app" "\${FLAGS[@]}" "$@"exports.default = async function (context) {stripOnnxruntimeBinaries(context);wrapLinuxBinary(context);+ verifyMeetingAecHelper(context);};diff --git a/scripts/build-meeting-aec-helper.js b/scripts/build-meeting-aec-helper.jsnew file mode 100644index 000000000..81ca6cb6a--- /dev/null+++ b/scripts/build-meeting-aec-helper.js@@ -0,0 +1,271 @@+#!/usr/bin/env node++const crypto = require("crypto");+const { spawnSync } = require("child_process");+const fs = require("fs");+const os = require("os");+const path = require("path");++const {+ buildManifest,+ computeManifestHash,+ ensureThirdPartySources,+ writeCmakeManifest,+} = require("./lib/meeting-aec-build");++const SUPPORTED_PLATFORMS = new Set(["darwin", "linux", "win32"]);+const SUPPORTED_ARCHES = new Set(["arm64", "x64"]);++if (!SUPPORTED_PLATFORMS.has(process.platform)) {+ process.exit(0);+}++const archIndex = process.argv.indexOf("--arch");+const targetArch =+ (archIndex !== -1 && process.argv[archIndex + 1]) || process.env.TARGET_ARCH || process.arch;++if (!SUPPORTED_ARCHES.has(targetArch)) {+ console.warn(`[meeting-aec-helper] Unsupported architecture: ${targetArch}`);+ process.exit(0);+}++const projectRoot = path.resolve(__dirname, "..");+const helperRoot = path.join(projectRoot, "native", "meeting-aec-helper");+const sourceDir = path.join(helperRoot, "src");+const outputDir = path.join(projectRoot, "resources", "bin");+const buildDir = path.join(helperRoot, "build", `${process.platform}-${targetArch}`);+const generatedDir = path.join(buildDir, "generated");+const objectDir = path.join(buildDir, "obj");+const binaryName = `meeting-aec-helper-${process.platform}-${targetArch}${+ process.platform === "win32" ? ".exe" : ""+}`;+const outputBinary = path.join(outputDir, binaryName);+const builtBinary = path.join(+ buildDir,+ process.platform === "win32" ? "Release" : "",+ `meeting-aec-helper${process.platform === "win32" ? ".exe" : ""}`+);+const hashFile = path.join(outputDir, `.meeting-aec-helper.${process.platform}-${targetArch}.hash`);++function log(message) {+ console.log(`[meeting-aec-helper] ${message}`);+}++function ensureDir(dirPath) {+ if (!fs.existsSync(dirPath)) {+ fs.mkdirSync(dirPath, { recursive: true });+ }+}++function hasCommand(command) {+ const checker = process.platform === "win32" ? "where" : "which";+ const result = spawnSync(checker, [command], {+ stdio: "pipe",+ shell: process.platform === "win32",+ });+ return result.status === 0;+}++function run(command, args, options = {}) {+ const { logCommand = true, ...spawnOptions } = options;+ if (logCommand) {+ log(`Running ${[command, ...args].join(" ")}`);+ }+ return spawnSync(command, args, {+ stdio: "inherit",+ cwd: projectRoot,+ env: process.env,+ ...spawnOptions,+ });+}++function getLocalFiles() {+ return [+ path.join(helperRoot, "CMakeLists.txt"),+ path.join(sourceDir, "main.cc"),+ path.join(sourceDir, "aec_processor.cc"),+ path.join(sourceDir, "aec_processor.h"),+ path.join(sourceDir, "null_aec_dump_factory.cc"),+ __filename,+ path.join(__dirname, "lib", "meeting-aec-build.js"),+ ];+}++function isUpToDate(currentHash) {+ if (!fs.existsSync(outputBinary) || !fs.existsSync(hashFile)) {+ return false;+ }++ return fs.readFileSync(hashFile, "utf8").trim() === currentHash;+}++function getDarwinArch() {+ return targetArch === "x64" ? "x86_64" : "arm64";+}++function getCompilerToolchain() {+ if (process.platform === "darwin") {+ return {+ cc: hasCommand("clang") ? "clang" : null,+ cxx: hasCommand("clang++") ? "clang++" : null,+ };+ }++ if (process.platform === "linux") {+ if (hasCommand("clang") && hasCommand("clang++")) {+ return { cc: "clang", cxx: "clang++" };+ }+ if (hasCommand("gcc") && hasCommand("g++")) {+ return { cc: "gcc", cxx: "g++" };+ }+ }++ return { cc: null, cxx: null };+}++function getSourceObjectName(sourcePath) {+ const hash = crypto.createHash("sha1").update(sourcePath).digest("hex").slice(0, 12);+ return `${hash}.o`;+}++function buildDirect(manifest) {+ if (process.platform === "win32") {+ return false;+ }++ const toolchain = getCompilerToolchain();+ if (!toolchain.cc || !toolchain.cxx) {+ return false;+ }++ fs.rmSync(objectDir, { recursive: true, force: true });+ ensureDir(objectDir);++ const includeArgs = manifest.includeDirs.flatMap((dir) => ["-I", dir]);+ const defineArgs = manifest.defines.map((define) => `-D${define}`);+ const commonArgs = [...manifest.compileOptions, ...includeArgs, ...defineArgs];+ const objectFiles = [];+ const localSources = [+ path.join(sourceDir, "main.cc"),+ path.join(sourceDir, "aec_processor.cc"),+ path.join(sourceDir, "null_aec_dump_factory.cc"),+ ];+ log(`Compiling ${manifest.cSources.length + manifest.cxxSources.length + localSources.length} sources`);++ for (const source of [...manifest.cSources, ...manifest.cxxSources, ...localSources]) {+ const outputObject = path.join(objectDir, getSourceObjectName(source));+ const compiler = source.endsWith(".c") ? toolchain.cc : toolchain.cxx;+ const languageArgs = source.endsWith(".c") ? ["-std=c11"] : ["-std=c++20"];+ const result = run(compiler, [+ ...languageArgs,+ ...commonArgs,+ "-c",+ source,+ "-o",+ outputObject,+ ], { logCommand: false });++ if (result.status !== 0) {+ return false;+ }++ objectFiles.push(outputObject);+ }++ const linkArgs = [+ "-std=c++20",+ ...manifest.compileOptions,+ ...manifest.linkOptions,+ ...objectFiles,+ "-o",+ outputBinary,+ ];+ const linkResult = run(toolchain.cxx, linkArgs, { logCommand: false });+ return linkResult.status === 0 && fs.existsSync(outputBinary);+}++function configureCMake(cmakeManifestPath) {+ const args = [+ "-S",+ helperRoot,+ "-B",+ buildDir,+ "-DMEETING_AEC_GENERATED_CMAKE=" + cmakeManifestPath,+ "-DCMAKE_BUILD_TYPE=Release",+ ];++ if (process.platform === "darwin") {+ args.push(`-DCMAKE_OSX_ARCHITECTURES=${getDarwinArch()}`);+ }++ if (process.platform === "win32" && targetArch === "x64") {+ args.push("-A", "x64");+ }++ return run("cmake", args);+}++function buildCMake() {+ const result = run("cmake", ["--build", buildDir, "--config", "Release"]);+ if (result.status !== 0 || !fs.existsSync(builtBinary)) {+ return false;+ }++ fs.copyFileSync(builtBinary, outputBinary);+ return true;+}++async function main() {+ ensureDir(outputDir);++ const currentHash = computeManifestHash(getLocalFiles(), process.platform, targetArch);+ if (isUpToDate(currentHash)) {+ log("Binary is up to date, skipping build");+ return;+ }++ ensureDir(buildDir);+ ensureDir(generatedDir);++ const { webrtcApmRoot, abslRoot } = await ensureThirdPartySources(helperRoot);+ const manifest = buildManifest({+ helperRoot,+ webrtcApmRoot,+ abslRoot,+ targetPlatform: process.platform,+ targetArch,+ });++ let built = false;+ const cmakeManifestPath = path.join(generatedDir, "meeting-aec-sources.cmake");+ writeCmakeManifest(manifest, cmakeManifestPath);++ if (hasCommand("cmake")) {+ const configured = configureCMake(cmakeManifestPath);+ if (configured.status === 0) {+ built = buildCMake();+ }+ }++ if (!built) {+ built = buildDirect(manifest);+ }++ if (!built) {+ console.warn("[meeting-aec-helper] Failed to build helper");+ process.exitCode = 1;+ return;+ }++ if (process.platform !== "win32") {+ fs.chmodSync(outputBinary, 0o755);+ }++ fs.writeFileSync(hashFile, currentHash);+ log(`Built ${binaryName} (${os.platform()} ${targetArch})`);+}++main().catch((error) => {+ console.error(`[meeting-aec-helper] ${error.message}`);+ process.exitCode = 1;+});diff --git a/scripts/lib/meeting-aec-build.js b/scripts/lib/meeting-aec-build.jsnew file mode 100644index 000000000..9e16658f9--- /dev/null+++ b/scripts/lib/meeting-aec-build.js@@ -0,0 +1,422 @@+const crypto = require("crypto");+const { execFileSync } = require("child_process");+const fs = require("fs");+const path = require("path");++const { downloadFile, extractArchive } = require("./download-utils");++const WEBRTC_APM_COMMIT = "08f235eba0c247f8929045adb090d0b0445cf8ea";+const ABSEIL_CPP_COMMIT = "9ac7062b1860d895fb5a8cbf58c3e9ef8f674b5f";++const WEBRTC_APM_URL = `https://chromium.googlesource.com/chromiumos/third_party/webrtc-apm/+archive/${WEBRTC_APM_COMMIT}.tar.gz`;+const ABSEIL_CPP_URL = `https://github.com/abseil/abseil-cpp/archive/${ABSEIL_CPP_COMMIT}.tar.gz`;++const WEBRTC_ROOT_LABELS = [+ "//api/audio:aec3_factory",+ "//api/audio:builtin_audio_processing_builder",+ "//api/environment:environment_factory",+ "//modules/audio_processing",+];++const SKIPPED_WEBRTC_SOURCES = new Set([+ "modules/audio_processing/aec_dump/aec_dump_impl.cc",+ "modules/audio_processing/aec_dump/capture_stream_info.cc",+]);++const EXTRA_WEBRTC_SOURCES = [+ "common_audio/vad/vad_core.c",+ "common_audio/vad/vad_filterbank.c",+ "common_audio/vad/vad_gmm.c",+ "common_audio/vad/vad_sp.c",+ "common_audio/vad/webrtc_vad.c",+ "modules/audio_processing/include/aec_dump.cc",+ "modules/audio_processing/logging/apm_data_dumper.cc",+ "rtc_base/strings/string_builder.cc",+];++const ABSL_SOURCES = [+ "absl/base/internal/cycleclock.cc",+ "absl/base/internal/raw_logging.cc",+ "absl/base/internal/spinlock.cc",+ "absl/base/internal/spinlock_wait.cc",+ "absl/base/internal/sysinfo.cc",+ "absl/base/internal/thread_identity.cc",+ "absl/base/internal/throw_delegate.cc",+ "absl/base/internal/unscaledcycleclock.cc",+ "absl/base/log_severity.cc",+ "absl/numeric/int128.cc",+ "absl/strings/ascii.cc",+ "absl/strings/charconv.cc",+ "absl/strings/escaping.cc",+ "absl/strings/internal/charconv_bigint.cc",+ "absl/strings/internal/charconv_parse.cc",+ "absl/strings/internal/damerau_levenshtein_distance.cc",+ "absl/strings/internal/escaping.cc",+ "absl/strings/internal/memutil.cc",+ "absl/strings/internal/ostringstream.cc",+ "absl/strings/internal/stringify_sink.cc",+ "absl/strings/internal/utf8.cc",+ "absl/strings/match.cc",+ "absl/strings/numbers.cc",+ "absl/strings/str_cat.cc",+ "absl/strings/str_replace.cc",+ "absl/strings/str_split.cc",+ "absl/strings/string_view.cc",+ "absl/strings/substitute.cc",+ "absl/types/bad_optional_access.cc",+];++function ensureDir(dirPath) {+ if (!fs.existsSync(dirPath)) {+ fs.mkdirSync(dirPath, { recursive: true });+ }+}++function listEntries(dirPath) {+ return fs.readdirSync(dirPath, { withFileTypes: true });+}++function moveChildrenUp(dirPath) {+ const entries = listEntries(dirPath);+ if (entries.length !== 1 || !entries[0].isDirectory()) {+ return;+ }++ const nestedDir = path.join(dirPath, entries[0].name);+ for (const child of listEntries(nestedDir)) {+ fs.renameSync(path.join(nestedDir, child.name), path.join(dirPath, child.name));+ }+ fs.rmSync(nestedDir, { recursive: true, force: true });+}++async function ensureSourceTree({+ url,+ archiveName,+ outputDir,+ flattenSingleRoot = false,+}) {+ if (fs.existsSync(outputDir) && listEntries(outputDir).length > 0) {+ return outputDir;+ }++ ensureDir(outputDir);+ const archivePath = path.join(path.dirname(outputDir), archiveName);++ try {+ await downloadFile(url, archivePath);+ await extractArchive(archivePath, outputDir);+ if (flattenSingleRoot) {+ moveChildrenUp(outputDir);+ }+ } finally {+ if (fs.existsSync(archivePath)) {+ fs.rmSync(archivePath, { force: true });+ }+ }++ return outputDir;+}++async function ensureThirdPartySources(helperRoot) {+ const thirdPartyRoot = path.join(helperRoot, "third_party");+ ensureDir(thirdPartyRoot);++ const webrtcApmRoot = path.join(thirdPartyRoot, `webrtc-apm-${WEBRTC_APM_COMMIT}`);+ const abslRoot = path.join(thirdPartyRoot, `abseil-cpp-${ABSEIL_CPP_COMMIT}`);++ await ensureSourceTree({+ url: WEBRTC_APM_URL,+ archiveName: `webrtc-apm-${WEBRTC_APM_COMMIT}.tar.gz`,+ outputDir: webrtcApmRoot,+ });+ await ensureSourceTree({+ url: ABSEIL_CPP_URL,+ archiveName: `abseil-cpp-${ABSEIL_CPP_COMMIT}.tar.gz`,+ outputDir: abslRoot,+ flattenSingleRoot: true,+ });++ return {+ webrtcApmRoot,+ abslRoot,+ };+}++function normalizeArch(arch) {+ if (arch === "x64") {+ return "x64";+ }+ if (arch === "arm64" || arch === "aarch64") {+ return "arm64";+ }+ return arch;+}++function buildWebrtcSourceList(webrtcApmRoot, targetArch) {+ const pythonScript = `+import json+from pathlib import Path++ROOT = Path(${JSON.stringify(webrtcApmRoot)})+ROOT_LABELS = ${JSON.stringify(WEBRTC_ROOT_LABELS)}+SKIPPED = set(${JSON.stringify([...SKIPPED_WEBRTC_SOURCES])})+TARGET_ARCH = ${JSON.stringify(normalizeArch(targetArch))}++want_arm64 = TARGET_ARCH == "arm64"+want_arm32 = TARGET_ARCH.startswith("arm") and not want_arm64+want_neon = want_arm64 or want_arm32++targets = {}+loaded_packages = set()+current_package = "//"++def select(options):+ for key, value in options.items():+ if (key == "//:aarch64_build" or key == ":aarch64_build") and want_arm64:+ return value+ if (key == "//:aarch32_build" or key == ":aarch32_build") and want_arm32:+ return value+ if (key == "//:neon_build" or key == ":neon_build") and want_neon:+ return value+ return options.get("//conditions:default", [])++def cc_library(**kwargs):+ targets[f"{current_package}:{kwargs['name']}"] = kwargs++def cc_proto_library(**kwargs):+ targets[f"{current_package}:{kwargs['name']}"] = kwargs++def proto_library(**kwargs):+ targets[f"{current_package}:{kwargs['name']}"] = kwargs++def alias(**kwargs):+ targets[f"{current_package}:{kwargs['name']}"] = {"deps": [kwargs["actual"]]}++def cc_test(**kwargs):+ return None++def package(**kwargs):+ return None++def test_suite(**kwargs):+ return None++def config_setting(**kwargs):+ return None++def bool_flag(**kwargs):+ return None++def exports_files(**kwargs):+ return None++ENV = {+ "cc_library": cc_library,+ "cc_proto_library": cc_proto_library,+ "proto_library": proto_library,+ "alias": alias,+ "cc_test": cc_test,+ "package": package,+ "test_suite": test_suite,+ "config_setting": config_setting,+ "bool_flag": bool_flag,+ "exports_files": exports_files,+ "select": select,+ "COPTS": [],+ "AVX2_COPTS": [],+ "NEON_COPTS": [],+ "require_condition": lambda cond: [],+}++def normalize_label(label, package_path):+ if label.startswith("@"):+ return label+ if label.startswith(":"):+ return f"//{package_path}{label}"+ if label.startswith("//"):+ if ":" in label:+ return label+ pkg = label[2:]+ return f"{label}:{pkg.split('/')[-1]}"+ return f"//{package_path}:{label}"++def load_build(package_path):+ global current_package+ if package_path in loaded_packages:+ return+ loaded_packages.add(package_path)+ build_path = ROOT / package_path / "BUILD.bazel" if package_path else ROOT / "BUILD.bazel"+ text = "\\n".join(+ line for line in build_path.read_text().splitlines() if not line.strip().startswith("load(")+ )+ current_package = f"//{package_path}" if package_path else "//"+ exec(text, dict(ENV), {})++def get_target(label):+ if label.startswith("@"):+ return None+ normalized = normalize_label(label, "")+ package_path = normalized[2:].split(":", 1)[0]+ load_build(package_path)+ return targets.get(normalized)++visited = set()+collected = set()++def walk(label, package_path=""):+ normalized = normalize_label(label, package_path)+ if normalized.startswith("@") or normalized in visited:+ return+ visited.add(normalized)+ target = get_target(normalized)+ if not target:+ return+ target_package_path = normalized[2:].split(":", 1)[0]+ for source in target.get("srcs", []):+ if not isinstance(source, str):+ continue+ if source.startswith("@") or source.startswith("//"):+ continue+ if not (source.endswith(".c") or source.endswith(".cc")):+ continue+ relative_path = str(Path(target_package_path) / source).replace("\\\\", "/")+ if relative_path in SKIPPED:+ continue+ if "avx2" in Path(relative_path).name:+ continue+ collected.add(str((ROOT / relative_path).resolve()))+ for dependency in target.get("deps", []):+ if isinstance(dependency, str):+ walk(dependency, target_package_path)++for root_label in ROOT_LABELS:+ walk(root_label)++print(json.dumps(sorted(collected)))+`;++ const output = execFileSync("python3", ["-c", pythonScript], {+ encoding: "utf8",+ });+ return JSON.parse(output);+}++function getPlatformDefines(targetPlatform, targetArch) {+ const defines = [+ "WEBRTC_APM_DEBUG_DUMP=0",+ "WEBRTC_ENABLE_PROTOBUF=0",+ "WEBRTC_INTELLIGIBILITY_ENHANCER=0",+ "WEBRTC_NS_FLOAT=1",+ "RTC_DISABLE_CHECK_MSG",+ ];++ if (targetPlatform === "win32") {+ defines.push("WEBRTC_WIN=1", "NOMINMAX", "WIN32_LEAN_AND_MEAN", "_USE_MATH_DEFINES");+ } else {+ defines.push("WEBRTC_POSIX=1");+ if (targetPlatform === "darwin") {+ defines.push("WEBRTC_MAC=1");+ } else if (targetPlatform === "linux") {+ defines.push("WEBRTC_LINUX=1");+ }+ }++ const normalizedArch = normalizeArch(targetArch);+ if (normalizedArch === "arm64") {+ defines.push("WEBRTC_ARCH_ARM64", "WEBRTC_HAS_NEON");+ } else if (normalizedArch.startsWith("arm")) {+ defines.push("WEBRTC_ARCH_ARM", "WEBRTC_HAS_NEON");+ }++ return defines;+}++function getDarwinArch(targetArch) {+ return normalizeArch(targetArch) === "x64" ? "x86_64" : "arm64";+}++function getArchOptions(targetPlatform, targetArch) {+ if (targetPlatform !== "darwin") {+ return [];+ }++ return ["-arch", getDarwinArch(targetArch)];+}++function getLinkOptions(targetPlatform) {+ if (targetPlatform === "linux") {+ return ["-pthread", "-lm"];+ }++ return [];+}++function quoteCmake(value) {+ return `"${String(value).replace(/\\/g, "/").replace(/"/g, "\\\"")}"`;+}++function writeCmakeManifest(manifest, outputPath) {+ const lines = [];+ const writeList = (name, values) => {+ lines.push(`set(${name}`);+ for (const value of values) {+ lines.push(` ${quoteCmake(value)}`);+ }+ lines.push(")");+ };++ writeList("MEETING_AEC_WEBRTC_SOURCES", manifest.webrtcSources);+ writeList("MEETING_AEC_ABSL_SOURCES", manifest.abslSources);+ writeList("MEETING_AEC_INCLUDE_DIRS", manifest.includeDirs);+ writeList("MEETING_AEC_DEFINES", manifest.defines);+ writeList("MEETING_AEC_COMPILE_OPTIONS", manifest.compileOptions);+ writeList("MEETING_AEC_LINK_OPTIONS", manifest.linkOptions);++ fs.writeFileSync(outputPath, `${lines.join("\n")}\n`);+}++function buildManifest({ helperRoot, webrtcApmRoot, abslRoot, targetPlatform, targetArch }) {+ const webrtcSources = [+ ...new Set([+ ...buildWebrtcSourceList(webrtcApmRoot, targetArch),+ ...EXTRA_WEBRTC_SOURCES.map((source) => path.join(webrtcApmRoot, source)),+ ]),+ ];+ const abslSources = ABSL_SOURCES.map((source) => path.join(abslRoot, source));+ const defines = getPlatformDefines(targetPlatform, targetArch);+ const compileOptions = ["-O2", ...getArchOptions(targetPlatform, targetArch)];+ const linkOptions = getLinkOptions(targetPlatform);++ return {+ helperRoot,+ webrtcSources,+ abslSources,+ includeDirs: [helperRoot, webrtcApmRoot, abslRoot],+ defines,+ compileOptions,+ linkOptions,+ cSources: [...webrtcSources, ...abslSources].filter((source) => source.endsWith(".c")),+ cxxSources: [...webrtcSources, ...abslSources].filter((source) => source.endsWith(".cc")),+ allSources: [...webrtcSources, ...abslSources],+ };+}++function computeManifestHash(localFiles, targetPlatform, targetArch) {+ const hash = crypto.createHash("sha256");+ for (const file of localFiles) {+ hash.update(path.basename(file));+ hash.update(fs.readFileSync(file, "utf8"));+ }+ hash.update(targetPlatform);+ hash.update(targetArch);+ hash.update(WEBRTC_APM_COMMIT);+ hash.update(ABSEIL_CPP_COMMIT);+ return hash.digest("hex");+}++module.exports = {+ buildManifest,+ computeManifestHash,+ ensureThirdPartySources,+ writeCmakeManifest,+};diff --git a/src/helpers/diarization.js b/src/helpers/diarization.jsindex dd0dc7f39..f9ed79380 100644--- a/src/helpers/diarization.js+++ b/src/helpers/diarization.js@@ -9,8 +9,41 @@ const { getModelsDirForService } = require("./modelDirUtils");const { convertToWav } = require("./ffmpegUtils");const { getSafeTempDir } = require("./safeTempDir");const { applyProvisionalSpeaker, applyConfirmedSpeaker } = require("./speakerAssignmentPolicy");+const {+ transcriptsOverlap,+ transcriptsLooselyOverlap,+ buildMergedCandidates,+} = require("./transcriptText");const DIARIZATION_TIMEOUT_MS = 300000; // 5 minutes+const POST_MERGE_CONTEXT_WINDOW_MS = 6000;+const POST_MERGE_CONTEXT_MERGE_LIMIT = 3;++const dedupeMicAgainstSystem = (segments) => {+ const systemSegments = segments.filter((seg) => seg.source === "system" && seg.text);+ if (!systemSegments.length) return segments;++ return segments.filter((seg) => {+ if (seg.source !== "mic" || !seg.text) return true;+ if (+ !seg.likelyRenderBleed &&+ !seg.hasBleedEvidence &&+ seg.suppressionReason !== "double_talk"+ ) {+ return true;+ }++ const matcher =+ seg.suppressionReason === "double_talk" ? transcriptsLooselyOverlap : transcriptsOverlap;+ const candidates = buildMergedCandidates({+ segments: systemSegments,+ timestamp: seg.timestamp,+ windowMs: POST_MERGE_CONTEXT_WINDOW_MS,+ mergeLimit: POST_MERGE_CONTEXT_MERGE_LIMIT,+ });+ return !candidates.some((candidateText) => matcher(seg.text, candidateText));+ });+};const SEGMENTATION_MODEL_URL ="https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-segmentation-models/sherpa-onnx-pyannote-segmentation-3-0.tar.bz2";@@ -383,8 +416,9 @@ class DiarizationManager {mergeWithTranscript(transcriptSegments, diarizationSegments) {if (!transcriptSegments || transcriptSegments.length === 0) return [];+ const deduped = dedupeMicAgainstSystem(transcriptSegments);if (!diarizationSegments || diarizationSegments.length === 0) {- return transcriptSegments.map((seg) => ({ ...seg }));+ return deduped.map((seg) => ({ ...seg }));}// Build speaker renumbering map (e.g., speaker_00 → speaker_0)@@ -397,8 +431,8 @@ class DiarizationManager {}const nextSystemTimestampAt = (startIndex) => {- for (let i = startIndex + 1; i < transcriptSegments.length; i += 1) {- const candidate = transcriptSegments[i];+ for (let i = startIndex + 1; i < deduped.length; i += 1) {+ const candidate = deduped[i];if (candidate.source === "system" && candidate.timestamp != null) {return candidate.timestamp;}@@ -408,7 +442,7 @@ class DiarizationManager {let fallbackSpeakerIndex = 0;- return transcriptSegments.map((seg, index) => {+ return deduped.map((seg, index) => {const enriched = { ...seg };if (seg.source === "mic") {diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.jsindex 6dc60375b..824950c83 100644--- a/src/helpers/ipcHandlers.js+++ b/src/helpers/ipcHandlers.js@@ -13,6 +13,11 @@ const OpenAIRealtimeStreaming = require("./openaiRealtimeStreaming");const AudioStorageManager = require("./audioStorage");const liveSpeakerIdentifier = require("./liveSpeakerIdentifier");const MeetingEchoLeakDetector = require("./meetingEchoLeakDetector");+const {+ transcriptsOverlap,+ transcriptsLooselyOverlap,+ buildMergedCandidates,+} = require("./transcriptText");const {applyConfirmedSpeaker,applySuggestedSpeaker,@@ -114,6 +119,7 @@ class IPCHandlers {this.googleCalendarManager = managers.googleCalendarManager;this.meetingDetectionEngine = managers.meetingDetectionEngine;this.audioTapManager = managers.audioTapManager;+ this.meetingAecManager = managers.meetingAecManager;this.sessionId = crypto.randomUUID();this.assemblyAiStreaming = null;this.deepgramStreaming = null;@@ -2813,58 +2819,260 @@ class IPCHandlers {let meetingTranscriptionPrepareInProgress = false;let meetingTranscriptionPreparePromise = null;- const normalizeTranscriptForComparison = (text) =>- String(text || "")- .toLowerCase()- .replace(/[^\p{L}\p{N}\s]/gu, " ")- .replace(/\s+/g, " ")- .trim();+ const DUPLICATE_TRANSCRIPT_WINDOW_MS = 6000;+ const DUPLICATE_TRANSCRIPT_MERGE_LIMIT = 3;+ const STREAMING_RISKY_MIC_SEGMENT_HOLDBACK_MS = 1500;+ const LOCAL_RISKY_MIC_SEGMENT_HOLDBACK_MS = 4500;++ const buildNearbyTranscriptCandidates = (+ targetSource,+ timestamp,+ { extraSegment = null } = {}+ ) => {+ const relevant = meetingDiarizationSegments.filter(+ (candidate) =>+ candidate.source === targetSource && candidate.timestamp != null && candidate.text+ );- const hasNearbyTranscriptMatch = (targetSource, text, timestamp) => {- const normalizedText = normalizeTranscriptForComparison(text);- if (!normalizedText) {- return false;+ return buildMergedCandidates({+ segments: relevant,+ timestamp,+ windowMs: DUPLICATE_TRANSCRIPT_WINDOW_MS,+ mergeLimit: DUPLICATE_TRANSCRIPT_MERGE_LIMIT,+ extraSegment,+ });+ };++ const hasNearbyTranscriptMatch = (targetSource, text, timestamp, options = {}) => {+ if (!text) return false;++ const matcher = options.relaxed ? transcriptsLooselyOverlap : transcriptsOverlap;+ const candidates = buildNearbyTranscriptCandidates(targetSource, timestamp, options);+ for (const candidateText of candidates) {+ if (matcher(text, candidateText)) {+ return true;+ }}+ return false;+ };++ const shouldSkipDuplicateMicSegment = (text, timestamp, suppression = null) => {+ if (suppression?.likelyRenderBleed || suppression?.hasBleedEvidence) {+ if (hasNearbyTranscriptMatch("system", text, timestamp)) {+ return true;+ }+ }++ if (suppression?.reason === "double_talk") {+ return hasNearbyTranscriptMatch("system", text, timestamp, { relaxed: true });+ }++ return false;+ };++ const hasRiskyMicDuplicateProfile = (suppression = null) =>+ !!suppression &&+ (suppression.reason === "double_talk" ||+ suppression.hasBleedEvidence ||+ suppression.likelyRenderBleed);++ const removeRacingMicEntriesFor = (systemText, systemTimestamp) => {+ const removed = [];for (let i = meetingDiarizationSegments.length - 1; i >= 0; i -= 1) {const candidate = meetingDiarizationSegments[i];- if (candidate.source !== targetSource || candidate.timestamp == null) {+ if (candidate.source !== "mic" || candidate.timestamp == null) continue;+ if (systemTimestamp != null && Math.abs(candidate.timestamp - systemTimestamp) > 4000) {+ if (candidate.timestamp < systemTimestamp) break;continue;}-- if (timestamp != null && Math.abs(candidate.timestamp - timestamp) > 4000) {- if (candidate.timestamp < timestamp) {- break;+ const hasMicDuplicateRisk =+ candidate.likelyRenderBleed ||+ candidate.hasBleedEvidence ||+ candidate.suppressionReason === "double_talk";+ const overlapsSystem = hasNearbyTranscriptMatch(+ "system",+ candidate.text,+ candidate.timestamp,+ {+ extraSegment: {+ text: systemText,+ timestamp: systemTimestamp,+ },+ relaxed: candidate.suppressionReason === "double_talk",}- continue;+ );+ if (hasMicDuplicateRisk && overlapsSystem) {+ meetingDiarizationSegments.splice(i, 1);+ removed.push(candidate);}+ }+ return removed;+ };++ const appendMeetingLocalTranscript = (text) => {+ if (!text) return;+ meetingLocalTranscript += `${meetingLocalTranscript ? " " : ""}${text}`;+ };- const normalizedCandidate = normalizeTranscriptForComparison(candidate.text);- if (!normalizedCandidate) {+ const storeMeetingDiarizationSegment = (text, source, timestamp, micSuppression = null) => {+ meetingDiarizationSegments.push({+ text,+ source,+ timestamp,+ suppressionReason: source === "mic" ? micSuppression?.reason || null : null,+ hasBleedEvidence: source === "mic" ? !!micSuppression?.hasBleedEvidence : false,+ likelyRenderBleed: source === "mic" ? !!micSuppression?.likelyRenderBleed : false,+ });+ };++ const sendMeetingFinalSegment = ({+ text,+ source,+ timestamp,+ micSuppression = null,+ send = null,+ includeInLocalTranscript = false,+ }) => {+ if (includeInLocalTranscript) {+ appendMeetingLocalTranscript(text);+ }++ storeMeetingDiarizationSegment(text, source, timestamp, micSuppression);++ if (send) {+ send("meeting-transcription-segment", {+ text,+ source,+ type: "final",+ timestamp,+ });+ }+ };++ function flushPendingMicFinals(force = false) {+ if (meetingPendingMicFinals.length === 0) {+ if (meetingPendingMicFinalTimer) {+ clearTimeout(meetingPendingMicFinalTimer);+ meetingPendingMicFinalTimer = null;+ }+ return;+ }++ const ready = [];+ const deferred = [];+ const now = Date.now();++ for (const pending of meetingPendingMicFinals) {+ if (!force && pending.releaseAt > now) {+ deferred.push(pending);continue;}if (- normalizedCandidate === normalizedText ||- normalizedCandidate.includes(normalizedText) ||- normalizedText.includes(normalizedCandidate)+ shouldSkipDuplicateMicSegment(pending.text, pending.timestamp, pending.micSuppression)) {- return true;+ debugLogger.debug(+ "Dropping buffered mic segment after system context confirmed duplicate",+ {+ text: pending.text.slice(0, 80),+ averageCorrelation: pending.micSuppression?.averageCorrelation?.toFixed(3),+ averageResidual: pending.micSuppression?.averageResidual?.toFixed(3),+ }+ );+ continue;}++ ready.push(pending);}- return false;+ meetingPendingMicFinals = deferred;+ schedulePendingMicFinalFlush();++ for (const pending of ready) {+ debugLogger.debug("Releasing buffered mic segment after duplicate holdback", {+ text: pending.text.slice(0, 80),+ holdbackMs: pending.holdbackMs,+ averageCorrelation: pending.micSuppression?.averageCorrelation?.toFixed(3),+ averageResidual: pending.micSuppression?.averageResidual?.toFixed(3),+ });+ pending.emit();+ }+ }++ const schedulePendingMicFinalFlush = () => {+ if (meetingPendingMicFinalTimer) {+ clearTimeout(meetingPendingMicFinalTimer);+ meetingPendingMicFinalTimer = null;+ }++ if (meetingPendingMicFinals.length === 0) {+ return;+ }++ const nextDelay = Math.max(0, meetingPendingMicFinals[0].releaseAt - Date.now());+ meetingPendingMicFinalTimer = setTimeout(() => {+ meetingPendingMicFinalTimer = null;+ flushPendingMicFinals();+ }, nextDelay);};- const shouldSkipDuplicateSystemSegment = (text, timestamp) =>- hasNearbyTranscriptMatch("mic", text, timestamp);+ const resetPendingMicFinals = () => {+ meetingPendingMicFinals = [];+ if (meetingPendingMicFinalTimer) {+ clearTimeout(meetingPendingMicFinalTimer);+ meetingPendingMicFinalTimer = null;+ }+ };- const shouldSkipDuplicateMicSegment = (text, timestamp, suppression = null) => {- if (!suppression?.likelyRenderBleed || suppression.reason === "double_talk") {+ const removePendingMicFinalsFor = (systemText, systemTimestamp) => {+ const removed = [];+ meetingPendingMicFinals = meetingPendingMicFinals.filter((candidate) => {+ const overlapsSystem = hasNearbyTranscriptMatch(+ "system",+ candidate.text,+ candidate.timestamp,+ {+ extraSegment: {+ text: systemText,+ timestamp: systemTimestamp,+ },+ relaxed: candidate.micSuppression?.reason === "double_talk",+ }+ );+ if (!overlapsSystem) {+ return true;+ }+ removed.push(candidate);return false;- }+ });+ schedulePendingMicFinalFlush();+ return removed;+ };- return hasNearbyTranscriptMatch("system", text, timestamp);+ const queuePendingMicFinal = ({ text, timestamp, micSuppression, holdbackMs, emit }) => {+ meetingPendingMicFinals.push({+ text,+ timestamp,+ micSuppression,+ holdbackMs,+ releaseAt: Date.now() + holdbackMs,+ emit,+ });+ meetingPendingMicFinals.sort((left, right) => left.releaseAt - right.releaseAt);+ schedulePendingMicFinalFlush();+ };++ const captureMeetingDiarizationState = async () => {+ const diarizationPcmPath = meetingDiarizationPath;+ const diarizationSegments = meetingDiarizationSegments;+ if (meetingDiarizationStream) {+ await new Promise((resolve) => meetingDiarizationStream.end(resolve));+ meetingDiarizationStream = null;+ }+ meetingDiarizationPath = null;+ meetingDiarizationSegments = [];+ return { diarizationPcmPath, diarizationSegments };};const attachMeetingStreamingHandlers = (streaming, win, source) => {@@ -2891,47 +3099,92 @@ class IPCHandlers {streaming.onFinalTranscript = (text, timestamp) => {const segments = streaming.completedSegments;const latestSegment = segments.length > 0 ? segments[segments.length - 1] : text;+ let micSuppression = null;if (source === "mic") {- const suppression = shouldSuppressMicTranscriptSegment(timestamp, Date.now());- if (suppression.suppress) {+ micSuppression = shouldSuppressMicTranscriptSegment(timestamp, Date.now());+ if (micSuppression.suppress) {debugLogger.debug("Suppressing contaminated mic segment", {- reason: suppression.reason,- averageCorrelation: suppression.averageCorrelation?.toFixed(3),- averageResidual: suppression.averageResidual?.toFixed(3),+ reason: micSuppression.reason,+ averageCorrelation: micSuppression.averageCorrelation?.toFixed(3),+ averageResidual: micSuppression.averageResidual?.toFixed(3),text: latestSegment.slice(0, 80),});send("meeting-transcription-segment", { text: "", source, type: "partial" });return;}- if (shouldSkipDuplicateMicSegment(latestSegment, timestamp, suppression)) {+ if (shouldSkipDuplicateMicSegment(latestSegment, timestamp, micSuppression)) {debugLogger.debug("Skipping duplicate mic segment that matches recent system audio", {text: latestSegment.slice(0, 80),- averageCorrelation: suppression.averageCorrelation?.toFixed(3),- averageResidual: suppression.averageResidual?.toFixed(3),+ averageCorrelation: micSuppression.averageCorrelation?.toFixed(3),+ averageResidual: micSuppression.averageResidual?.toFixed(3),});send("meeting-transcription-segment", { text: "", source, type: "partial" });return;}}- if (source === "system" && shouldSkipDuplicateSystemSegment(latestSegment, timestamp)) {- debugLogger.debug("Skipping duplicate system segment that matches recent mic audio", {- text: latestSegment.slice(0, 80),- });- return;+ if (source === "system") {+ const pending = removePendingMicFinalsFor(latestSegment, timestamp);+ if (pending.length > 0) {+ debugLogger.debug("Dropping buffered mic segments after system transcript arrived", {+ count: pending.length,+ text: latestSegment.slice(0, 80),+ });+ }++ const retracted = removeRacingMicEntriesFor(latestSegment, timestamp);+ for (const stale of retracted) {+ send("meeting-transcription-segment", {+ text: stale.text,+ source: "mic",+ type: "retract",+ timestamp: stale.timestamp,+ });+ }}+debugLogger.debug("Meeting segment sending to renderer", {source,text: latestSegment.slice(0, 80),segmentCount: segments.length,+ micCorrelation: micSuppression?.averageCorrelation?.toFixed(3),+ micSuppressionReason: micSuppression?.reason,+ micHasBleedEvidence: micSuppression?.hasBleedEvidence,+ micLikelyRenderBleed: micSuppression?.likelyRenderBleed,+ systemSpeaking: micSuppression?.systemSpeaking,});- meetingDiarizationSegments.push({ text: latestSegment, source, timestamp });- send("meeting-transcription-segment", {+ if (source === "mic" && hasRiskyMicDuplicateProfile(micSuppression)) {+ debugLogger.debug("Buffering risky mic segment before renderer commit", {+ text: latestSegment.slice(0, 80),+ holdbackMs: STREAMING_RISKY_MIC_SEGMENT_HOLDBACK_MS,+ reason: micSuppression?.reason,+ hasBleedEvidence: micSuppression?.hasBleedEvidence,+ });+ send("meeting-transcription-segment", { text: "", source, type: "partial" });+ queuePendingMicFinal({+ text: latestSegment,+ timestamp,+ micSuppression,+ holdbackMs: STREAMING_RISKY_MIC_SEGMENT_HOLDBACK_MS,+ emit: () =>+ sendMeetingFinalSegment({+ text: latestSegment,+ source,+ timestamp,+ micSuppression,+ send,+ }),+ });+ return;+ }++ sendMeetingFinalSegment({text: latestSegment,source,- type: "final",timestamp,+ micSuppression,+ send,});};streaming.onError = (error) => {@@ -3032,7 +3285,7 @@ class IPCHandlers {return win;};- const MEETING_MIC_REFERENCE_ALIGNMENT_MS = 180;+ const MEETING_MIC_REFERENCE_ALIGNMENT_MS = 320;let meetingSendCounts = { mic: 0, system: 0 };const meetingEchoLeakDetector = new MeetingEchoLeakDetector();@@ -3053,6 +3306,9 @@ class IPCHandlers {let meetingLocalModel = null;let meetingLocalTranscribing = false;let meetingPendingMicChunks = [];+ let meetingPendingMicFinals = [];+ let meetingPendingMicFinalTimer = null;+ let meetingAecEnabled = false;const getLiveSpeakerProfiles = () => this.databaseManager.getSpeakerProfiles(true);const shouldSuppressMicTranscriptSegment = (startedAt, endedAt = Date.now()) =>@@ -3086,6 +3342,46 @@ class IPCHandlers {}};+ const stopMeetingAec = async () => {+ meetingAecEnabled = false;+ if (this.meetingAecManager) {+ await this.meetingAecManager.stop().catch(() => {});+ }+ };++ const startMeetingAec = async (systemAudioMode) => {+ meetingAecEnabled = false;+ if (systemAudioMode === "unsupported" || !this.meetingAecManager?.isAvailable()) {+ return false;+ }++ const started = await this.meetingAecManager+ .start({+ onMicChunk: (chunk) => {+ meetingEchoLeakDetector.analyzeMicChunk(chunk);+ dispatchMeetingAudioBuffer(chunk, "mic");+ },+ onError: (error) => {+ debugLogger.warn("Meeting AEC helper disabled", { error: error.message }, "meeting");+ meetingAecEnabled = false;+ void this.meetingAecManager.stop().catch(() => {});+ },+ onWarning: (warning) => {+ debugLogger.debug("Meeting AEC helper warning", warning, "meeting");+ },+ })+ .catch((error) => {+ debugLogger.warn("Meeting AEC helper start failed", { error: error.message }, "meeting");+ return false;+ });++ meetingAecEnabled = !!started;+ if (meetingAecEnabled) {+ debugLogger.info("Meeting AEC helper started", { systemAudioMode }, "meeting");+ }+ return meetingAecEnabled;+ };+const flushPendingMeetingMicChunks = (force = false) => {if (!meetingPendingMicChunks.length) {return;@@ -3100,7 +3396,7 @@ class IPCHandlers {meetingPendingMicChunks.shift();const analysis = meetingEchoLeakDetector.analyzeMicChunk(next.buffer);- if (analysis?.shouldMute) {+ if (analysis?.shouldMute && !meetingAecEnabled) {if (!meetingLocalMode) {dispatchMeetingAudioBuffer(Buffer.alloc(next.buffer.length), "mic");}@@ -3111,6 +3407,20 @@ class IPCHandlers {}};+ const processMeetingMicWithAec = (buffer) => {+ if (!meetingAecEnabled) {+ return false;+ }++ const sent = this.meetingAecManager?.processMicBuffer(buffer);+ if (sent) {+ return true;+ }++ meetingAecEnabled = false;+ return false;+ };+const stopLiveSpeakerIdentification = async () => {if (!meetingLiveSpeakerActive) {return null;@@ -3227,43 +3537,116 @@ class IPCHandlers {if (result?.success && result.text?.trim()) {const text = result.text.trim();const segTimestamp = Date.now();+ let micSuppression = null;if (source === "mic") {const chunkDurationMs = (pcm24k.length / 2 / 24000) * 1000;- const suppression = shouldSuppressMicTranscriptSegment(+ micSuppression = shouldSuppressMicTranscriptSegment(segTimestamp - chunkDurationMs,segTimestamp);- if (suppression.suppress) {+ debugLogger.debug("Local meeting transcription candidate", {+ source,+ text: text.slice(0, 80),+ suppress: micSuppression.suppress,+ reason: micSuppression.reason,+ hasBleedEvidence: micSuppression.hasBleedEvidence,+ likelyRenderBleed: micSuppression.likelyRenderBleed,+ averageCorrelation: micSuppression.averageCorrelation?.toFixed(3),+ averageResidual: micSuppression.averageResidual?.toFixed(3),+ });+ if (micSuppression.suppress) {debugLogger.debug("Suppressing contaminated local mic segment", {- reason: suppression.reason,- averageCorrelation: suppression.averageCorrelation?.toFixed(3),- averageResidual: suppression.averageResidual?.toFixed(3),+ reason: micSuppression.reason,+ averageCorrelation: micSuppression.averageCorrelation?.toFixed(3),+ averageResidual: micSuppression.averageResidual?.toFixed(3),text: text.slice(0, 80),});return;}- if (shouldSkipDuplicateMicSegment(text, segTimestamp, suppression)) {+ if (shouldSkipDuplicateMicSegment(text, segTimestamp, micSuppression)) {debugLogger.debug("Skipping duplicate local mic segment that matches system audio", {text: text.slice(0, 80),- averageCorrelation: suppression.averageCorrelation?.toFixed(3),- averageResidual: suppression.averageResidual?.toFixed(3),+ averageCorrelation: micSuppression.averageCorrelation?.toFixed(3),+ averageResidual: micSuppression.averageResidual?.toFixed(3),});return;}+ } else {+ debugLogger.debug("Local meeting transcription candidate", {+ source,+ text: text.slice(0, 80),+ });}- meetingLocalTranscript += (meetingLocalTranscript ? " " : "") + text;- meetingDiarizationSegments.push({ text, source, timestamp: segTimestamp });+ if (source === "system") {+ const pending = removePendingMicFinalsFor(text, segTimestamp);+ if (pending.length > 0) {+ debugLogger.debug(+ "Dropping buffered local mic segments after system transcript arrived",+ {+ count: pending.length,+ text: text.slice(0, 80),+ }+ );+ }++ const retracted = removeRacingMicEntriesFor(text, segTimestamp);+ for (const stale of retracted) {+ if (meetingLocalWin && !meetingLocalWin.isDestroyed()) {+ meetingLocalWin.webContents.send("meeting-transcription-segment", {+ text: stale.text,+ source: "mic",+ type: "retract",+ timestamp: stale.timestamp,+ });+ }+ }+ }++ const sendLocalSegment = (channel, payload) => {+ if (channel !== "meeting-transcription-segment") {+ return;+ }- if (meetingLocalWin && !meetingLocalWin.isDestroyed()) {- meetingLocalWin.webContents.send("meeting-transcription-segment", {+ if (meetingLocalWin && !meetingLocalWin.isDestroyed()) {+ meetingLocalWin.webContents.send(channel, payload);+ }+ };++ if (source === "mic" && hasRiskyMicDuplicateProfile(micSuppression)) {+ debugLogger.debug("Buffering risky local mic segment before renderer commit", {+ text: text.slice(0, 80),+ holdbackMs: LOCAL_RISKY_MIC_SEGMENT_HOLDBACK_MS,+ reason: micSuppression?.reason,+ hasBleedEvidence: micSuppression?.hasBleedEvidence,+ });+ queuePendingMicFinal({text,- source,- type: "final",timestamp: segTimestamp,+ micSuppression,+ holdbackMs: LOCAL_RISKY_MIC_SEGMENT_HOLDBACK_MS,+ emit: () =>+ sendMeetingFinalSegment({+ text,+ source,+ timestamp: segTimestamp,+ micSuppression,+ send: sendLocalSegment,+ includeInLocalTranscript: true,+ }),});+ return;}++ sendMeetingFinalSegment({+ text,+ source,+ timestamp: segTimestamp,+ micSuppression,+ send: sendLocalSegment,+ includeInLocalTranscript: true,+ });}} catch (error) {debugLogger.error("Local meeting transcription chunk failed", {@@ -3280,8 +3663,8 @@ class IPCHandlers {if (meetingLocalTranscribing) return;meetingLocalTranscribing = true;try {- await transcribeLocalMeetingChunk("mic");await transcribeLocalMeetingChunk("system");+ await transcribeLocalMeetingChunk("mic");} finally {meetingLocalTranscribing = false;}@@ -3312,6 +3695,8 @@ class IPCHandlers {meetingLocalModel = null;meetingLocalTranscribing = false;meetingPendingMicChunks = [];+ resetPendingMicFinals();+ meetingAecEnabled = false;meetingEchoLeakDetector.reset();};@@ -3321,10 +3706,12 @@ class IPCHandlers {meetingSendCounts = { mic: 0, system: 0 };meetingLiveSpeakerStartedAt = null;meetingPendingMicChunks = [];+ resetPendingMicFinals();+ meetingAecEnabled = false;meetingEchoLeakDetector.reset();};- const disconnectMeetingStreaming = async () => {+ const disconnectMeetingStreaming = async ({ flushPending = false } = {}) => {const results = await Promise.all([this._meetingMicStreaming? this._meetingMicStreaming.disconnect().catch(() => ({ text: "" }))@@ -3334,6 +3721,10 @@ class IPCHandlers {: Promise.resolve({ text: "" }),]);+ if (flushPending) {+ flushPendingMicFinals(true);+ }+resetMeetingStreamingState();return results;};@@ -3342,6 +3733,7 @@ class IPCHandlers {if (this.audioTapManager) {await this.audioTapManager.stop().catch(() => {});}+ await stopMeetingAec();await stopLiveSpeakerIdentification().catch(() => {});resetMeetingLocalState();await disconnectMeetingStreaming().catch(() => {});@@ -3434,6 +3826,7 @@ class IPCHandlers {debugLogger.debug("Meeting transcription start: reusing warm connections");const win = BrowserWindow.fromWebContents(event.sender);attachMeetingStreamingHandlers(this._meetingMicStreaming, win, "mic");+ await startMeetingAec(systemAudioMode);if (systemAudioMode === "native") {await startLiveSpeakerIdentification(win, systemAudioMode);attachMeetingStreamingHandlers(this._meetingSystemStreaming, win, "system");@@ -3451,6 +3844,7 @@ class IPCHandlers {meetingLocalTranscript = "";await startLiveSpeakerIdentification(meetingLocalWin, systemAudioMode);+ await startMeetingAec(systemAudioMode);meetingLocalTimer = setInterval(() => {transcribeAllLocalBuffers();@@ -3477,6 +3871,7 @@ class IPCHandlers {BrowserWindow.fromWebContents(event.sender),systemAudioMode);+ await startMeetingAec(systemAudioMode);if (systemAudioMode === "native") {await startNativeMeetingSystemAudio(event);}@@ -3496,6 +3891,9 @@ class IPCHandlers {if (source === "system") {meetingEchoLeakDetector.recordSystemChunk(outboundBuffer);+ if (meetingAecEnabled && !this.meetingAecManager?.processSystemBuffer(outboundBuffer)) {+ meetingAecEnabled = false;+ }flushPendingMeetingMicChunks();if (meetingLiveSpeakerActive) {@@ -3513,9 +3911,13 @@ class IPCHandlers {}if (source === "mic") {+ if (processMeetingMicWithAec(outboundBuffer)) {+ return;+ }+if (!hasNativeMeetingSystemAudio()) {const analysis = meetingEchoLeakDetector.analyzeMicChunk(outboundBuffer);- if (analysis?.shouldMute) {+ if (analysis?.shouldMute && !meetingAecEnabled) {if (!meetingLocalMode) {dispatchMeetingAudioBuffer(Buffer.alloc(outboundBuffer.length), "mic");}@@ -3561,18 +3963,11 @@ class IPCHandlers {}flushPendingMeetingMicChunks(true);+ await stopMeetingAec();const liveSpeakerState = await stopLiveSpeakerIdentification().catch(() => null);const diarizationSessionId = `diar-${Date.now()}`;- const diarizationPcmPath = meetingDiarizationPath;- const diarizationSegments = meetingDiarizationSegments;- if (meetingDiarizationStream) {- await new Promise((resolve) => meetingDiarizationStream.end(resolve));- meetingDiarizationStream = null;- }- meetingDiarizationPath = null;- meetingDiarizationSegments = [];const diarizationWin = meetingLocalWin || this.windowManager.controlPanelWindow;if (meetingLocalMode) {@@ -3585,6 +3980,9 @@ class IPCHandlers {} catch (err) {debugLogger.error("Local meeting final transcription failed", { error: err.message });}+ flushPendingMicFinals(true);+ const { diarizationPcmPath, diarizationSegments } =+ await captureMeetingDiarizationState();const transcript =diarizationSegments.map((segment) => segment.text)@@ -3604,7 +4002,8 @@ class IPCHandlers {return { success: true, transcript, diarizationSessionId };}- const results = await disconnectMeetingStreaming();+ const results = await disconnectMeetingStreaming({ flushPending: true });+ const { diarizationPcmPath, diarizationSegments } = await captureMeetingDiarizationState();const transcript =diarizationSegments.map((segment) => segment.text)diff --git a/src/helpers/meetingAecManager.js b/src/helpers/meetingAecManager.jsnew file mode 100644index 000000000..081a13b05--- /dev/null+++ b/src/helpers/meetingAecManager.js@@ -0,0 +1,270 @@+const { spawn } = require("child_process");+const fs = require("fs");+const path = require("path");+const debugLogger = require("./debugLogger");++const START_TIMEOUT_MS = 3000;+const STOP_TIMEOUT_MS = 2000;+const SYSTEM_STREAM = 1;+const MIC_STREAM = 2;+const SAMPLE_RATE = 24000;++class MeetingAecManager {+ constructor() {+ this.process = null;+ this.stdoutBuffer = Buffer.alloc(0);+ this.stderrBuffer = "";+ this.onMicChunk = null;+ this.onError = null;+ this.onWarning = null;+ this.isStopping = false;+ }++ isSupported() {+ return (+ process.platform === "darwin" || process.platform === "linux" || process.platform === "win32"+ );+ }++ isAvailable() {+ return !!this.resolveBinary();+ }++ resolveBinary() {+ if (!this.isSupported()) {+ return null;+ }++ const binaryName = `meeting-aec-helper-${process.platform}-${process.arch}${+ process.platform === "win32" ? ".exe" : ""+ }`;+ const candidates = new Set([path.join(__dirname, "..", "..", "resources", "bin", binaryName)]);++ if (process.resourcesPath) {+ candidates.add(path.join(process.resourcesPath, "bin", binaryName));+ candidates.add(path.join(process.resourcesPath, "resources", "bin", binaryName));+ candidates.add(path.join(process.resourcesPath, binaryName));+ }++ for (const candidate of candidates) {+ if (fs.existsSync(candidate)) {+ return candidate;+ }+ }++ return null;+ }++ async start({ onMicChunk, onError, onWarning } = {}) {+ if (this.process) {+ this.onMicChunk = onMicChunk || null;+ this.onError = onError || null;+ this.onWarning = onWarning || null;+ return true;+ }++ const binaryPath = this.resolveBinary();+ if (!binaryPath) {+ return false;+ }++ try {+ fs.accessSync(binaryPath, fs.constants.X_OK);+ } catch {+ if (process.platform !== "win32") {+ fs.chmodSync(binaryPath, 0o755);+ }+ }++ const child = spawn(binaryPath, ["--sample-rate", String(SAMPLE_RATE)], {+ stdio: ["pipe", "pipe", "pipe"],+ });++ this.process = child;+ this.stdoutBuffer = Buffer.alloc(0);+ this.stderrBuffer = "";+ this.onMicChunk = onMicChunk || null;+ this.onError = onError || null;+ this.onWarning = onWarning || null;+ this.isStopping = false;++ return new Promise((resolve) => {+ let settled = false;+ let started = false;+ const timeout = setTimeout(() => {+ finish(false);+ void this.stop();+ }, START_TIMEOUT_MS);++ const finish = (result) => {+ if (settled) {+ return;+ }+ settled = true;+ clearTimeout(timeout);+ resolve(result);+ };++ child.stdout.on("data", (chunk) => {+ if (this.process !== child) {+ return;+ }+ this._consumeStdout(chunk);+ });++ child.stderr.on("data", (chunk) => {+ if (this.process !== child) {+ return;+ }+ this._consumeStderr(chunk, (message) => {+ if (message.type === "start") {+ started = true;+ finish(true);+ return;+ }+ if (message.type === "warning") {+ this.onWarning?.(message);+ return;+ }+ if (message.type === "error") {+ this.onError?.(new Error(message.message || "Meeting AEC helper failed"));+ }+ });+ });++ child.on("error", (error) => {+ if (!this.isStopping) {+ this.onError?.(error);+ }+ finish(false);+ });++ child.on("exit", (code, signal) => {+ const wasStopping = this.isStopping;+ if (this.process === child) {+ this.process = null;+ }+ this.isStopping = false;+ if (!wasStopping && (code || signal)) {+ this.onError?.(+ new Error(+ `Meeting AEC helper exited unexpectedly (code ${code ?? "null"}, signal ${+ signal ?? "null"+ })`+ )+ );+ }+ finish(started && (code === 0 || code === null));+ });+ });+ }++ processSystemBuffer(buffer) {+ return this._writeFrame(SYSTEM_STREAM, buffer);+ }++ processMicBuffer(buffer) {+ return this._writeFrame(MIC_STREAM, buffer);+ }++ async stop() {+ if (!this.process) {+ return;+ }++ const child = this.process;+ this.isStopping = true;++ await new Promise((resolve) => {+ let settled = false;+ const finish = () => {+ if (settled) {+ return;+ }+ settled = true;+ resolve();+ };++ const timeout = setTimeout(() => {+ if (child.exitCode == null) {+ child.kill();+ }+ finish();+ }, STOP_TIMEOUT_MS);++ child.once("exit", () => {+ clearTimeout(timeout);+ finish();+ });++ if (child.stdin && !child.stdin.destroyed) {+ child.stdin.end();+ } else {+ clearTimeout(timeout);+ finish();+ }+ });++ if (this.process === child) {+ this.process = null;+ }+ this.isStopping = false;+ this.stdoutBuffer = Buffer.alloc(0);+ this.stderrBuffer = "";+ }++ _writeFrame(type, buffer) {+ const stdin = this.process?.stdin;+ if (!stdin || stdin.destroyed) {+ return false;+ }++ const payload = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);+ if (!payload.length) {+ return true;+ }++ const header = Buffer.alloc(5);+ header.writeUInt8(type, 0);+ header.writeUInt32LE(payload.length, 1);+ stdin.write(Buffer.concat([header, payload]));+ return true;+ }++ _consumeStdout(chunk) {+ this.stdoutBuffer = Buffer.concat([this.stdoutBuffer, chunk]);++ while (this.stdoutBuffer.length >= 4) {+ const frameLength = this.stdoutBuffer.readUInt32LE(0);+ if (this.stdoutBuffer.length < 4 + frameLength) {+ return;+ }++ const payload = this.stdoutBuffer.subarray(4, 4 + frameLength);+ this.stdoutBuffer = this.stdoutBuffer.subarray(4 + frameLength);+ this.onMicChunk?.(Buffer.from(payload));+ }+ }++ _consumeStderr(chunk, onMessage) {+ this.stderrBuffer += chunk.toString();+ let newlineIndex = this.stderrBuffer.indexOf("\n");++ while (newlineIndex !== -1) {+ const line = this.stderrBuffer.slice(0, newlineIndex).trim();+ this.stderrBuffer = this.stderrBuffer.slice(newlineIndex + 1);++ if (line) {+ try {+ onMessage(JSON.parse(line));+ } catch {+ debugLogger.warn("[MeetingAecManager] Non-JSON stderr output", { line }, "meeting");+ }+ }++ newlineIndex = this.stderrBuffer.indexOf("\n");+ }+ }+}++module.exports = MeetingAecManager;diff --git a/src/helpers/meetingEchoLeakDetector.js b/src/helpers/meetingEchoLeakDetector.jsindex 13059d4a3..87221726f 100644--- a/src/helpers/meetingEchoLeakDetector.js+++ b/src/helpers/meetingEchoLeakDetector.js@@ -1,24 +1,29 @@const SAMPLE_RATE = 24000;-const MAX_SYSTEM_HISTORY_MS = 4000;+const MAX_SYSTEM_HISTORY_MS = 6000;const MAX_MIC_HISTORY_MS = 12000;const MIN_RMS = 0.006;const MIN_SYSTEM_RMS = 0.004;-const MAX_LAG_MS = 220;+const MAX_LAG_MS = 500;const LAG_STEP_SAMPLES = 120;-const PARTIAL_WINDOW_MS = 450;-const FINAL_PADDING_MS = 250;-const CHUNK_MUTE_WINDOW_MS = 180;-const STRONG_BLEED_CORRELATION = 0.94;-const STRONG_BLEED_RESIDUAL = 0.18;-const STRONG_BLEED_EXPLAINED = 0.82;-const STRONG_BLEED_MIC_TO_SYSTEM_RATIO = 1.12;-const PARTIAL_BLEED_CORRELATION = 0.9;-const PARTIAL_BLEED_RESIDUAL = 0.22;-const PARTIAL_BLEED_EXPLAINED = 0.78;-const FINAL_BLEED_CORRELATION = 0.88;-const FINAL_BLEED_RESIDUAL = 0.24;-const FINAL_BLEED_EXPLAINED = 0.74;-const FINAL_BLEED_MIC_TO_SYSTEM_RATIO = 1.18;+const PARTIAL_WINDOW_MS = 600;+const FINAL_PADDING_MS = 500;+const CHUNK_MUTE_WINDOW_MS = 260;+const STRONG_BLEED_CORRELATION = 0.75;+const STRONG_BLEED_RESIDUAL = 0.32;+const STRONG_BLEED_EXPLAINED = 0.65;+const STRONG_BLEED_MIC_TO_SYSTEM_RATIO = 1.25;+const PARTIAL_BLEED_CORRELATION = 0.6;+const PARTIAL_BLEED_RESIDUAL = 0.45;+const PARTIAL_BLEED_EXPLAINED = 0.5;+const FINAL_BLEED_CORRELATION = 0.55;+const FINAL_BLEED_RESIDUAL = 0.48;+const FINAL_BLEED_EXPLAINED = 0.45;+const FINAL_BLEED_MIC_TO_SYSTEM_RATIO = 1.35;+const SYSTEM_VAD_TAIL_MS = 300;+const VAD_GATED_BLEED_CORRELATION = 0.4;+const VAD_GATED_BLEED_RESIDUAL = 0.6;+const VAD_GATED_BLEED_EXPLAINED = 0.35;+const VAD_GATED_SUSPECTED_SHARE = 0.3;const DOUBLE_TALK_CORRELATION = 0.45;const DOUBLE_TALK_EXPLAINED = 0.3;const DOUBLE_TALK_RESIDUAL = 0.2;@@ -111,6 +116,7 @@ class MeetingEchoLeakDetector {const systemWindow = this._getSystemWindow();if (systemWindow.length < samples.length + this._maxLagSamples()) {+ analysis.state = "awaiting_reference";this.micHistory.push(analysis);this._trimHistory(timestampMs);return analysis;@@ -173,31 +179,34 @@ class MeetingEchoLeakDetector {isMicProbablyRenderBleed(nowMs = Date.now()) {const recent = this.micHistory.filter(- (entry) => nowMs - entry.timestampMs <= PARTIAL_WINDOW_MS && entry.rms >= MIN_RMS+ (entry) =>+ nowMs - entry.timestampMs <= PARTIAL_WINDOW_MS &&+ entry.rms >= MIN_RMS &&+ entry.state !== "awaiting_reference");if (recent.length < 3) {return false;}- if (recent.some((entry) => entry.state === "double_talk")) {- return false;- }-- const suspectedCount = recent.filter(- (entry) => entry.state === "suspected_render_bleed"- ).length;- if (suspectedCount < Math.ceil(recent.length * 0.8)) {+ const bleedMatches = recent.filter((entry) =>+ this._matchesBleedProfile(+ entry,+ PARTIAL_BLEED_CORRELATION,+ PARTIAL_BLEED_RESIDUAL,+ PARTIAL_BLEED_EXPLAINED+ )+ );+ if (bleedMatches.length < Math.ceil(recent.length * 0.8)) {return false;}- const suspected = recent.filter((entry) => entry.state === "suspected_render_bleed");const averageCorrelation =- suspected.reduce((sum, entry) => sum + entry.correlation, 0) / suspected.length;+ bleedMatches.reduce((sum, entry) => sum + entry.correlation, 0) / bleedMatches.length;const averageResidual =- suspected.reduce((sum, entry) => sum + entry.residualRatio, 0) / suspected.length;+ bleedMatches.reduce((sum, entry) => sum + entry.residualRatio, 0) / bleedMatches.length;const averageExplained =- suspected.reduce((sum, entry) => sum + entry.explainedRatio, 0) / suspected.length;+ bleedMatches.reduce((sum, entry) => sum + entry.explainedRatio, 0) / bleedMatches.length;return (averageCorrelation >= PARTIAL_BLEED_CORRELATION &&@@ -206,6 +215,20 @@ class MeetingEchoLeakDetector {);}+ isSystemSpeaking(windowStartMs, windowEndMs = Date.now()) {+ for (let i = this.systemHistory.length - 1; i >= 0; i -= 1) {+ const entry = this.systemHistory[i];+ const entryEnd = entry.timestampMs + entry.durationMs;+ if (entryEnd < windowStartMs - SYSTEM_VAD_TAIL_MS) {+ break;+ }+ if (entry.rms >= MIN_SYSTEM_RMS && entry.timestampMs <= windowEndMs + SYSTEM_VAD_TAIL_MS) {+ return true;+ }+ }+ return false;+ }+shouldSuppressMicSegment(startedAtMs, endedAtMs = Date.now()) {if (!startedAtMs) {return { suppress: false, reason: "missing_start" };@@ -213,84 +236,110 @@ class MeetingEchoLeakDetector {const windowStart = startedAtMs - FINAL_PADDING_MS;const windowEnd = endedAtMs + FINAL_PADDING_MS;+ const systemSpeaking = this.isSystemSpeaking(startedAtMs, endedAtMs);const relevant = this.micHistory.filter((entry) =>- entry.timestampMs + entry.durationMs >= windowStart && entry.timestampMs <= windowEnd+ entry.timestampMs + entry.durationMs >= windowStart &&+ entry.timestampMs <= windowEnd &&+ entry.state !== "awaiting_reference");if (relevant.length < 2) {return { suppress: false, reason: "insufficient_signal" };}- const suspected = relevant.filter((entry) => entry.state === "suspected_render_bleed");const doubleTalk = relevant.filter((entry) => entry.state === "double_talk");+ const bleedMatches = relevant.filter((entry) =>+ this._matchesBleedProfile(+ entry,+ FINAL_BLEED_CORRELATION,+ FINAL_BLEED_RESIDUAL,+ FINAL_BLEED_EXPLAINED+ )+ );const averageCorrelation =- suspected.length > 0- ? suspected.reduce((sum, entry) => sum + entry.correlation, 0) / suspected.length+ bleedMatches.length > 0+ ? bleedMatches.reduce((sum, entry) => sum + entry.correlation, 0) / bleedMatches.length: 0;const averageResidual =- suspected.length > 0- ? suspected.reduce((sum, entry) => sum + entry.residualRatio, 0) / suspected.length+ bleedMatches.length > 0+ ? bleedMatches.reduce((sum, entry) => sum + entry.residualRatio, 0) / bleedMatches.length: 1;const averageExplained =- suspected.length > 0- ? suspected.reduce((sum, entry) => sum + entry.explainedRatio, 0) / suspected.length+ bleedMatches.length > 0+ ? bleedMatches.reduce((sum, entry) => sum + entry.explainedRatio, 0) / bleedMatches.length: 0;const averageMicToSystemRatio =- suspected.length > 0- ? suspected.reduce((sum, entry) => sum + (entry.micToSystemRatio || 0), 0) /- suspected.length+ bleedMatches.length > 0+ ? bleedMatches.reduce((sum, entry) => sum + (entry.micToSystemRatio || 0), 0) /+ bleedMatches.length: null;- const suspectedShare = suspected.length / relevant.length;- const likelyRenderBleed =- suspected.length > 0 &&- suspectedShare >= 0.5 &&- averageCorrelation >= 0.84 &&- averageResidual <= 0.32 &&- averageExplained >= 0.68;-- if (doubleTalk.length > 0) {+ const hasBleedEvidence =+ bleedMatches.length > 0 &&+ averageCorrelation >= PARTIAL_BLEED_CORRELATION &&+ averageResidual <= PARTIAL_BLEED_RESIDUAL &&+ averageExplained >= PARTIAL_BLEED_EXPLAINED;+ const bleedShare = bleedMatches.length / relevant.length;+ const shareGate = systemSpeaking ? VAD_GATED_SUSPECTED_SHARE : 0.6;+ const likelyRenderBleedShareGate = systemSpeaking ? VAD_GATED_SUSPECTED_SHARE : 0.4;+ const likelyRenderBleed = hasBleedEvidence && bleedShare >= likelyRenderBleedShareGate;++ if (doubleTalk.length > 0 && !likelyRenderBleed) {return {suppress: false,reason: "double_talk",+ hasBleedEvidence,likelyRenderBleed,averageCorrelation,averageResidual,averageExplained,averageMicToSystemRatio,+ bleedMatchCount: bleedMatches.length,sampleCount: relevant.length,+ systemSpeaking,};}- if (suspectedShare < 0.75) {+ if (bleedShare < shareGate) {return {suppress: false,reason: "mixed_signal",+ hasBleedEvidence,likelyRenderBleed,averageCorrelation,averageResidual,averageExplained,averageMicToSystemRatio,+ bleedMatchCount: bleedMatches.length,sampleCount: relevant.length,+ systemSpeaking,};}+ const corrGate = systemSpeaking ? VAD_GATED_BLEED_CORRELATION : FINAL_BLEED_CORRELATION;+ const residualGate = systemSpeaking ? VAD_GATED_BLEED_RESIDUAL : FINAL_BLEED_RESIDUAL;+ const explainedGate = systemSpeaking ? VAD_GATED_BLEED_EXPLAINED : FINAL_BLEED_EXPLAINED;+const suppress =- averageCorrelation >= FINAL_BLEED_CORRELATION &&- averageResidual <= FINAL_BLEED_RESIDUAL &&- averageExplained >= FINAL_BLEED_EXPLAINED &&+ doubleTalk.length === 0 &&+ averageCorrelation >= corrGate &&+ averageResidual <= residualGate &&+ averageExplained >= explainedGate &&(averageMicToSystemRatio == null ||averageMicToSystemRatio <= FINAL_BLEED_MIC_TO_SYSTEM_RATIO);return {suppress,+ hasBleedEvidence,likelyRenderBleed,- reason: suppress ? "render_bleed" : "weak_match",+ systemSpeaking,+ reason: suppress ? "render_bleed" : doubleTalk.length > 0 ? "mixed_signal" : "weak_match",averageCorrelation,averageResidual,averageExplained,averageMicToSystemRatio,+ bleedMatchCount: bleedMatches.length,sampleCount: relevant.length,};}@@ -326,10 +375,10 @@ class MeetingEchoLeakDetector {}if (- correlation >= 0.9 &&- residualRatio <= 0.26 &&- explainedRatio >= 0.72 &&- (micToSystemRatio == null || micToSystemRatio <= 1.2)+ correlation >= 0.6 &&+ residualRatio <= 0.45 &&+ explainedRatio >= 0.5 &&+ (micToSystemRatio == null || micToSystemRatio <= 1.3)) {return "suspected_render_bleed";}@@ -380,6 +429,17 @@ class MeetingEchoLeakDetector {return sumSq;}+ _matchesBleedProfile(entry, correlationGate, residualGate, explainedGate) {+ return (+ !!entry &&+ entry.rms >= MIN_RMS &&+ entry.systemRms >= MIN_SYSTEM_RMS &&+ entry.correlation >= correlationGate &&+ entry.residualRatio <= residualGate &&+ entry.explainedRatio >= explainedGate+ );+ }+_maxLagSamples() {return Math.round((MAX_LAG_MS / 1000) * SAMPLE_RATE);}diff --git a/src/helpers/transcriptText.js b/src/helpers/transcriptText.jsnew file mode 100644index 000000000..84481b760--- /dev/null+++ b/src/helpers/transcriptText.js@@ -0,0 +1,205 @@+const TOKEN_COVERAGE_THRESHOLD = 0.6;+const TOKEN_SEQUENCE_THRESHOLD = 0.6;+const MIN_TOKENS_FOR_OVERLAP = 3;+const MEANINGFUL_TOKEN_COVERAGE_THRESHOLD = 0.55;+const MEANINGFUL_TOKEN_SEQUENCE_THRESHOLD = 0.55;+const MIN_MEANINGFUL_TOKENS_FOR_OVERLAP = 4;++const LOW_SIGNAL_TOKENS = new Set([+ "a",+ "an",+ "and",+ "are",+ "as",+ "at",+ "be",+ "been",+ "being",+ "but",+ "by",+ "d",+ "did",+ "do",+ "does",+ "for",+ "from",+ "had",+ "has",+ "have",+ "he",+ "her",+ "here",+ "his",+ "how",+ "i",+ "if",+ "in",+ "is",+ "it",+ "ll",+ "m",+ "me",+ "my",+ "of",+ "on",+ "or",+ "our",+ "out",+ "re",+ "s",+ "she",+ "so",+ "t",+ "that",+ "the",+ "their",+ "them",+ "there",+ "these",+ "they",+ "this",+ "those",+ "to",+ "ve",+ "was",+ "we",+ "well",+ "were",+ "what",+ "when",+ "where",+ "which",+ "who",+ "why",+ "with",+ "without",+ "you",+ "your",+]);++const normalizeTranscriptText = (text) =>+ String(text || "")+ .toLowerCase()+ .replace(/[^\p{L}\p{N}\s]/gu, " ")+ .replace(/\s+/g, " ")+ .trim();++const longestCommonTokenSubsequence = (a, b) => {+ const dp = Array.from({ length: a.length + 1 }, () => new Uint16Array(b.length + 1));++ for (let i = 1; i <= a.length; i += 1) {+ for (let j = 1; j <= b.length; j += 1) {+ if (a[i - 1] === b[j - 1]) {+ dp[i][j] = dp[i - 1][j - 1] + 1;+ } else {+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);+ }+ }+ }++ return dp[a.length][b.length];+};++const countCommonTokens = (a, b) => {+ const counts = new Map();+ let common = 0;++ for (const token of a) {+ counts.set(token, (counts.get(token) || 0) + 1);+ }++ for (const token of b) {+ const remaining = counts.get(token) || 0;+ if (remaining <= 0) continue;+ counts.set(token, remaining - 1);+ common += 1;+ }++ return common;+};++const toMeaningfulTokens = (text) =>+ text+ .split(" ")+ .filter(Boolean)+ .filter((token) => token.length > 1 && !LOW_SIGNAL_TOKENS.has(token));++const transcriptsOverlap = (a, b) => {+ const normalizedA = typeof a === "string" ? normalizeTranscriptText(a) : a;+ const normalizedB = typeof b === "string" ? normalizeTranscriptText(b) : b;+ if (!normalizedA || !normalizedB) return false;+ if (normalizedA === normalizedB) return true;+ if (normalizedA.includes(normalizedB) || normalizedB.includes(normalizedA)) return true;++ const tokensA = normalizedA.split(" ");+ const tokensB = normalizedB.split(" ");+ const shorter = Math.min(tokensA.length, tokensB.length);+ if (shorter < MIN_TOKENS_FOR_OVERLAP) return false;++ const common = countCommonTokens(tokensA, tokensB);+ if (common / shorter >= TOKEN_COVERAGE_THRESHOLD) {+ return true;+ }++ const sequence = longestCommonTokenSubsequence(tokensA, tokensB);+ return sequence / shorter >= TOKEN_SEQUENCE_THRESHOLD;+};++const transcriptsLooselyOverlap = (a, b) => {+ const normalizedA = typeof a === "string" ? normalizeTranscriptText(a) : a;+ const normalizedB = typeof b === "string" ? normalizeTranscriptText(b) : b;+ if (!normalizedA || !normalizedB) return false;+ if (normalizedA === normalizedB) return true;+ if (normalizedA.includes(normalizedB) || normalizedB.includes(normalizedA)) return true;++ const tokensA = toMeaningfulTokens(normalizedA);+ const tokensB = toMeaningfulTokens(normalizedB);+ const shorter = Math.min(tokensA.length, tokensB.length);+ if (shorter < MIN_MEANINGFUL_TOKENS_FOR_OVERLAP) return false;++ const common = countCommonTokens(tokensA, tokensB);+ if (common / shorter >= MEANINGFUL_TOKEN_COVERAGE_THRESHOLD) {+ return true;+ }++ const sequence = longestCommonTokenSubsequence(tokensA, tokensB);+ return sequence / shorter >= MEANINGFUL_TOKEN_SEQUENCE_THRESHOLD;+};++const buildMergedCandidates = ({+ segments,+ timestamp,+ windowMs,+ mergeLimit,+ extraSegment = null,+}) => {+ const nearby = segments.filter(+ (seg) =>+ seg.text &&+ (seg.timestamp == null ||+ timestamp == null ||+ Math.abs(seg.timestamp - timestamp) <= windowMs)+ );++ if (extraSegment?.text) {+ nearby.push({+ text: extraSegment.text,+ timestamp: extraSegment.timestamp ?? timestamp ?? Date.now(),+ });+ }++ nearby.sort((left, right) => (left.timestamp ?? 0) - (right.timestamp ?? 0));++ const texts = new Set();+ for (let start = 0; start < nearby.length; start += 1) {+ let merged = "";+ for (let end = start; end < nearby.length && end < start + mergeLimit; end += 1) {+ merged += `${merged ? " " : ""}${nearby[end].text}`;+ texts.add(merged);+ }+ }++ return [...texts];+};++module.exports = { transcriptsOverlap, transcriptsLooselyOverlap, buildMergedCandidates };diff --git a/src/hooks/useMeetingTranscription.ts b/src/hooks/useMeetingTranscription.tsindex 485db02d2..f455b6333 100644--- a/src/hooks/useMeetingTranscription.ts+++ b/src/hooks/useMeetingTranscription.ts@@ -65,15 +65,15 @@ const MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS = {noiseSuppression: false,autoGainControl: false,} as const;-const MEETING_MIC_FALLBACK_AUDIO_CONSTRAINTS = {- echoCancellation: false,- noiseSuppression: false,- autoGainControl: false,-} as const;const REALTIME_MODELS = new Set(["gpt-4o-mini-transcribe", "gpt-4o-transcribe"]);const SPEAKER_IDENTIFICATION_RETENTION_MS = 30_000;const SYSTEM_SPEAKER_CARRY_FORWARD_MS = 2_500;+const buildTranscriptText = (segments: TranscriptSegment[]) =>+ segments+ .map((segment) => segment.text)+ .join(" ")+ .trim();const getSpeakerNumericIndex = (speakerId?: string): number | null => {if (!speakerId) {@@ -215,10 +215,6 @@ const getMeetingMicConstraints = async (): Promise<MediaStreamConstraints> => {return { audio: MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS };};-const getFallbackMeetingMicConstraints = (): MediaStreamConstraints => ({- audio: MEETING_MIC_FALLBACK_AUDIO_CONSTRAINTS,-});-const createAudioPipeline = async ({stream,context,@@ -556,7 +552,7 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {locks.set(s.speaker, s.speakerName);}}- setTranscript(seed.map((s) => s.text).join(" "));+ setTranscript(buildTranscriptText(seed));setPartialTranscript("");setSegments(seed);segmentsRef.current = seed;@@ -586,30 +582,36 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {try {return await navigator.mediaDevices.getUserMedia(constraints);} catch (err) {+ const hasExactDevice =+ typeof constraints.audio === "object" &&+ constraints.audio !== null &&+ "deviceId" in constraints.audio;+ if (hasExactDevice) {+ try {+ const fallbackStream = await navigator.mediaDevices.getUserMedia({+ audio: MEETING_MIC_PRIMARY_AUDIO_CONSTRAINTS,+ });+ logger.info(+ "Meeting mic capture recovered using default device",+ { error: (err as Error).message },+ "meeting"+ );+ return fallbackStream;+ } catch (fallbackErr) {+ logger.error(+ "Meeting mic capture failed, continuing with system audio only",+ { error: (fallbackErr as Error).message },+ "meeting"+ );+ return null;+ }+ }logger.error(- "Meeting mic capture failed with preferred constraints",+ "Meeting mic capture failed, continuing with system audio only",{ error: (err as Error).message, constraints },"meeting");-- try {- const fallbackConstraints = getFallbackMeetingMicConstraints();- const fallbackStream =- await navigator.mediaDevices.getUserMedia(fallbackConstraints);- logger.info(- "Meeting mic capture recovered with fallback constraints",- { fallbackConstraints },- "meeting"- );- return fallbackStream;- } catch (fallbackErr) {- logger.error(- "Mic capture failed, continuing with system audio only",- { error: (fallbackErr as Error).message },- "meeting"- );- return null;- }+ return null;}}),]);@@ -660,11 +662,28 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {(data: {text: string;source: "mic" | "system";- type: "partial" | "final";+ type: "partial" | "final" | "retract";timestamp?: number;}) => {const setPartialForSource = partialSetters[data.source];+ if (data.type === "retract") {+ setSegments((prev) => {+ const next = prev.filter(+ (seg) =>+ !(+ seg.source === data.source &&+ seg.timestamp === data.timestamp &&+ seg.text === data.text+ )+ );+ segmentsRef.current = next;+ setTranscript(buildTranscriptText(next));+ return next;+ });+ return;+ }+if (data.type === "partial") {setPartialForSource(data.text);setPartialTranscript(data.text);@@ -708,6 +727,7 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {const next =i === prev.length ? [...prev, seg] : [...prev.slice(0, i), seg, ...prev.slice(i)];segmentsRef.current = next;+ setTranscript(buildTranscriptText(next));return next;});if (data.source === "system" && seg.speaker) {@@ -722,7 +742,6 @@ export function useMeetingTranscription(): UseMeetingTranscriptionReturn {if (data.source === "system") {setSystemPartialSpeakerIdentity(null, null);}- setTranscript((prev) => (prev ? prev + " " + data.text : data.text));setPartialTranscript("");}}diff --git a/src/types/electron.ts b/src/types/electron.tsindex 6043c295b..2cffee66b 100644--- a/src/types/electron.ts+++ b/src/types/electron.ts@@ -1355,7 +1355,7 @@ declare global {callback: (data: {text: string;source: "mic" | "system";- type: "partial" | "final";+ type: "partial" | "final" | "retract";timestamp?: number;}) => void) => () => void;diff --git a/test/helpers/meetingEchoLeakDetector.test.js b/test/helpers/meetingEchoLeakDetector.test.jsnew file mode 100644index 000000000..04221f6ec--- /dev/null+++ b/test/helpers/meetingEchoLeakDetector.test.js@@ -0,0 +1,74 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const MeetingEchoLeakDetector = require("../../src/helpers/meetingEchoLeakDetector");++test("shouldSuppressMicSegment keeps bleed evidence even when share stays below render-bleed gate", () => {+ const detector = new MeetingEchoLeakDetector();+ const nowMs = 10_000;++ detector.systemHistory = [+ {+ timestampMs: nowMs - 250,+ durationMs: 120,+ rms: 0.02,+ samples: new Float32Array(2400),+ },+ ];++ detector.micHistory = [+ {+ timestampMs: nowMs - 420,+ durationMs: 120,+ rms: 0.02,+ correlation: 0.77,+ residualRatio: 0.4,+ explainedRatio: 0.6,+ systemRms: 0.02,+ micToSystemRatio: 1.1,+ state: "double_talk",+ },+ {+ timestampMs: nowMs - 300,+ durationMs: 120,+ rms: 0.02,+ correlation: 0.15,+ residualRatio: 0.9,+ explainedRatio: 0.1,+ systemRms: 0.02,+ micToSystemRatio: 1.1,+ state: "clean_local",+ },+ {+ timestampMs: nowMs - 180,+ durationMs: 120,+ rms: 0.02,+ correlation: 0.1,+ residualRatio: 0.95,+ explainedRatio: 0.05,+ systemRms: 0.02,+ micToSystemRatio: 1.1,+ state: "clean_local",+ },+ {+ timestampMs: nowMs - 60,+ durationMs: 120,+ rms: 0.02,+ correlation: 0.2,+ residualRatio: 0.85,+ explainedRatio: 0.15,+ systemRms: 0.02,+ micToSystemRatio: 1.1,+ state: "clean_local",+ },+ ];++ const result = detector.shouldSuppressMicSegment(nowMs - 500, nowMs);++ assert.equal(result.suppress, false);+ assert.equal(result.reason, "double_talk");+ assert.equal(result.hasBleedEvidence, true);+ assert.equal(result.likelyRenderBleed, false);+ assert.equal(result.bleedMatchCount, 1);+ assert.equal(result.sampleCount, 4);+});diff --git a/test/helpers/transcriptText.test.js b/test/helpers/transcriptText.test.jsnew file mode 100644index 000000000..ebd16f987--- /dev/null+++ b/test/helpers/transcriptText.test.js@@ -0,0 +1,47 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const { transcriptsOverlap, transcriptsLooselyOverlap } = require("../../src/helpers/transcriptText");++test("transcriptsOverlap matches near-duplicate meeting transcripts", () => {+ assert.equal(+ transcriptsOverlap(+ "a distribution mechanism? Is it a future product? Is it one of N ways people are",+ "mechanism as a future product? Is it one of the ways we are going to interact wi"+ ),+ true+ );++ assert.equal(+ transcriptsOverlap(+ "with the world? I feel like in search with every shift, you're able to do more w",+ "I feel like in search with every step you're able to do more."+ ),+ true+ );+});++test("transcriptsOverlap stays conservative for short generic fragments", () => {+ assert.equal(transcriptsOverlap("and you know we have", "you know, be a..."), false);+ assert.equal(transcriptsOverlap("Thank you.", "Thanks."), false);+});++test("transcriptsLooselyOverlap catches chunk-boundary paraphrases without matching filler", () => {+ assert.equal(+ transcriptsLooselyOverlap(+ "or just information-seeking queries, will be agent-taken search, You'll be completing tasks, you'll have many threads running. Well, search exist",+ "The inquiry will be agent in search. You will be completing"+ ),+ true+ );++ assert.equal(+ transcriptsLooselyOverlap(+ "You'll be completing tasks, you'll have many threads running. Well, search exist in 10 years? Well, you know, you may... Or it just evolves into something else.",+ "I don't see that many threads running. So, it takes us 10 years? What?"+ ),+ true+ );++ assert.equal(transcriptsLooselyOverlap("and you know we have", "you know, be a..."), false);+});