diff --git a/example/.gitignore b/example/.gitignore index 43ae556..6b57d3c 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/example/lib/main.dart b/example/lib/main.dart index 5dee70d..9dbbcbc 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -90,8 +90,7 @@ class _MyAppState extends State { ), ), ); - } - ), + }), ), ); } diff --git a/example/macos/Runner/AppDelegate.swift b/example/macos/Runner/AppDelegate.swift index 8e02df2..b3c1761 100644 --- a/example/macos/Runner/AppDelegate.swift +++ b/example/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/lib/models/pyannote/pyannote_isolate.dart b/lib/models/pyannote/pyannote_isolate.dart index aaefc97..a07c73c 100644 --- a/lib/models/pyannote/pyannote_isolate.dart +++ b/lib/models/pyannote/pyannote_isolate.dart @@ -265,6 +265,9 @@ Future>> _processAudioInIsolate( List> results = []; List isActive = List.filled(PyannoteONNX.numSpeakers, false); List startSamples = List.filled(PyannoteONNX.numSpeakers, 0); + // Add near where isActive and startSamples are declared + final probSums = List.filled(PyannoteONNX.numSpeakers, 0.0); + final framesCounted = List.filled(PyannoteONNX.numSpeakers, 0); int currentSamples = 721; final overlap = sample2frame(PyannoteONNX.duration - step); @@ -371,18 +374,29 @@ Future>> _processAudioInIsolate( currentSamples += 270; for (int spk = 0; spk < PyannoteONNX.numSpeakers; spk++) { if (isActive[spk]) { + // Add probability tracking + probSums[spk] += probs[spk]; + framesCounted[spk]++; + if (probs[spk] < 0.5) { results.add({ 'speaker': spk, 'start': startSamples[spk] / PyannoteONNX.sampleRate, 'stop': currentSamples / PyannoteONNX.sampleRate, + 'probability': probSums[spk] / framesCounted[spk], // Add average probability }); isActive[spk] = false; + // Reset tracking for this speaker + probSums[spk] = 0.0; + framesCounted[spk] = 0; } } else { if (probs[spk] > 0.5) { startSamples[spk] = currentSamples; isActive[spk] = true; + // Start tracking probability + probSums[spk] = probs[spk]; + framesCounted[spk] = 1; } } } @@ -402,6 +416,7 @@ Future>> _processAudioInIsolate( 'speaker': spk, 'start': startSamples[spk] / PyannoteONNX.sampleRate, 'stop': currentSamples / PyannoteONNX.sampleRate, + 'probability': probSums[spk] / framesCounted[spk], // Add average probability }); } }