loadSttModel method

void loadSttModel(
  1. String modelPath, {
  2. String modelType = 'whisper',
  3. Map<String, dynamic>? config,
})

Load an STT model.

Implementation

void loadSttModel(
  String modelPath, {
  String modelType = 'whisper',
  Map<String, dynamic>? config,
}) {
  _ensureBackendType('onnx');

  final pathPtr = modelPath.toNativeUtf8();
  final handlePtr = calloc<RacHandle>();
  final configPtr = calloc<RacSttOnnxConfigStruct>();

  // Set config defaults
  configPtr.ref.modelType = modelType == 'whisper' ? 0 : 99; // AUTO
  configPtr.ref.numThreads = 0; // Auto
  configPtr.ref.useCoreml = RAC_TRUE;

  try {
    final create =
        _lib.lookupFunction<RacSttOnnxCreateNative, RacSttOnnxCreateDart>(
            'rac_stt_onnx_create');

    final result = create(pathPtr, configPtr.cast(), handlePtr);

    if (result != RAC_SUCCESS) {
      throw NativeBackendException(
        'Failed to load STT model: ${RacCore.getErrorMessage(result)}',
        code: result,
      );
    }

    _handle = handlePtr.value;
    _currentModel = modelPath;
  } finally {
    calloc.free(pathPtr);
    calloc.free(handlePtr);
    calloc.free(configPtr);
  }
}