process method
Process audio data and return speaker segments
Returns a list of segments. For regular segmentation models:
{
'speaker': int, // Speaker index
'start': double, // Start time in seconds
'stop': double, // End time in seconds
}
Implementation
@override
Future<List<Map<String, dynamic>>> process(Float32List audioData) async {
final snapshot = Float32List.fromList(audioData);
await loadFonnxWebModule('pyannote_init.js');
final jsObject = await pyannoteFn(modelPath, snapshot.toJS).toDart;
if (jsObject == null) {
throw Exception('Pyannote result returned from JS code is null');
}
final dartObject = json.decode(jsObject.toDart);
if (dartObject is! List) {
throw Exception(
'Pyannote result returned from JS code is not a List, it is a ${dartObject.runtimeType}',
);
}
final List<Map<String, dynamic>> results = [];
for (final segment in dartObject) {
if (segment is! Map) {
throw Exception('Segment is not a Map: $segment');
}
final speakerIndex = segment['speaker'];
final start = segment['start'];
final stop = segment['stop'];
if (speakerIndex is! num || start is! num || stop is! num) {
throw Exception('Invalid segment format: $segment');
}
results.add({
'speaker': speakerIndex,
'start': start.toDouble(),
'stop': stop.toDouble(),
});
}
return results;
}