open method

void open(
  1. File encoder,
  2. File decoder,
  3. File? vad,
  4. String language,
  5. int modelType
)

Implementation

void open(
  File encoder,
  File decoder,
  File? vad,
  String language,
  int modelType
) {
  classId = classIdCounter;
  classIdCounter++;

  int status = 0;
  if (Platform.isWindows) {
    status = ailiaSpeech.ailiaSpeechOpenModelFileW(
      ppAilia!.value,
      encoder.path.toNativeUtf16().cast<ffi.Int16>(),
      decoder.path.toNativeUtf16().cast<ffi.Int16>(),
      modelType,
    );
  } else {
    status = ailiaSpeech.ailiaSpeechOpenModelFileA(
      ppAilia!.value,
      encoder.path.toNativeUtf8().cast<ffi.Int8>(),
      decoder.path.toNativeUtf8().cast<ffi.Int8>(),
      modelType,
    );
  }
  throwError("ailiaSpeechOpenModelFileA", status);

  if (language != "auto") {
    status = ailiaSpeech.ailiaSpeechSetLanguage(
      ppAilia!.value,
      language.toNativeUtf8().cast<ffi.Int8>(),
    );
    throwError("ailiaSpeechSetLanguage", status);
  }

  if (vad != null) {
    if (Platform.isWindows) {
      status = ailiaSpeech.ailiaSpeechOpenVadFileW(
        ppAilia!.value,
        vad.path.toNativeUtf16().cast<ffi.Int16>(),
        ailia_speech_dart.AILIA_SPEECH_VAD_TYPE_SILERO,
      );
    } else {
      status = ailiaSpeech.ailiaSpeechOpenVadFileA(
        ppAilia!.value,
        vad.path.toNativeUtf8().cast<ffi.Int8>(),
        ailia_speech_dart.AILIA_SPEECH_VAD_TYPE_SILERO,
      );
    }
    throwError("ailiaSpeechOpenVadFileA", status);
  }

  ailia_speech_dart.AILIA_SPEECH_USER_API_INTERMEDIATE_CALLBACK pointer =
      ffi.Pointer.fromFunction(intermediateCallback, 0);
  ffi.Pointer<ffi.Void> voidPointer =
      ffi.Pointer<ffi.Void>.fromAddress(classId);

  status = ailiaSpeech.ailiaSpeechSetIntermediateCallback(
    ppAilia!.value,
    pointer,
    voidPointer,
  );
  throwError("ailiaSpeechSetIntermediateCallback", status);

  if (vad != null) {
    const double thresholdVad = 0.5;
    const double speechSec = 1.0;
    const double noSpeechSec = 1.0;
    status = ailiaSpeech.ailiaSpeechSetSilentThreshold(
      ppAilia!.value,
      thresholdVad,
      speechSec,
      noSpeechSec,
    );
    throwError("ailiaSpeechSetSilentThreshold", status);
  }

  available = true;
  postProcess = false;
}