Skip to content

Commit

Permalink
experiment(pyannote): probability
Browse files Browse the repository at this point in the history
  • Loading branch information
jpohhhh committed Dec 13, 2024
1 parent f862f83 commit 47c12c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
3 changes: 1 addition & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class _MyAppState extends State<MyApp> {
),
),
);
}
),
}),
),
);
}
Expand Down
4 changes: 4 additions & 0 deletions example/macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}
15 changes: 15 additions & 0 deletions lib/models/pyannote/pyannote_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ Future<List<Map<String, dynamic>>> _processAudioInIsolate(
List<Map<String, dynamic>> results = [];
List<bool> isActive = List.filled(PyannoteONNX.numSpeakers, false);
List<int> startSamples = List.filled(PyannoteONNX.numSpeakers, 0);
// Add near where isActive and startSamples are declared
final probSums = List<double>.filled(PyannoteONNX.numSpeakers, 0.0);
final framesCounted = List<int>.filled(PyannoteONNX.numSpeakers, 0);
int currentSamples = 721;

final overlap = sample2frame(PyannoteONNX.duration - step);
Expand Down Expand Up @@ -371,18 +374,29 @@ Future<List<Map<String, dynamic>>> _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;
}
}
}
Expand All @@ -402,6 +416,7 @@ Future<List<Map<String, dynamic>>> _processAudioInIsolate(
'speaker': spk,
'start': startSamples[spk] / PyannoteONNX.sampleRate,
'stop': currentSamples / PyannoteONNX.sampleRate,
'probability': probSums[spk] / framesCounted[spk], // Add average probability
});
}
}
Expand Down

0 comments on commit 47c12c3

Please sign in to comment.