pyannoteIsolateEntryPoint function

void pyannoteIsolateEntryPoint(
  1. SendPort mainSendPort
)

Entry point for the processing isolate.

Sets up message handling and ONNX session management.

Implementation

void pyannoteIsolateEntryPoint(SendPort mainSendPort) {
  final receivePort = ReceivePort();
  mainSendPort.send(receivePort.sendPort);

  OrtSessionObjects? ortSessionObjects;

  receivePort.listen((dynamic message) async {
    if (message is PyannoteIsolateMessage) {
      try {
        if (message.ortDylibPathOverride != null) {
          fonnxOrtDylibPathOverride = message.ortDylibPathOverride;
        }

        ortSessionObjects ??= createOrtSession(message.modelPath);

        final result = await _processAudioInIsolate(
          ortSessionObjects!,
          message.audioData,
        );

        message.replyPort.send(result);
      } catch (e) {
        message.replyPort.send(e);
      }
    } else if (message == 'close') {
      if (ortSessionObjects != null) {
        cleanupOrtSession(ortSessionObjects);
      }
      Isolate.exit();
    } else {
      throw Exception('Unknown message received in Pyannote isolate.');
    }
  });
}