translate method

String translate(
  1. String inputText
)

Implementation

String translate(String inputText) {
  final ffi.Pointer<ailia_speech_dart.AILIASpeechText> inputTextStruct =
      malloc<ailia_speech_dart.AILIASpeechText>();

  String language = "ja";
  inputTextStruct.ref.text = inputText.toNativeUtf8().cast<ffi.Char>();
  inputTextStruct.ref.time_stamp_begin = 0.0;
  inputTextStruct.ref.time_stamp_end = 0.0;
  inputTextStruct.ref.person_id = 0;
  inputTextStruct.ref.language = language.toNativeUtf8().cast<ffi.Char>();

  int status = ailiaSpeech.ailiaSpeechSetText(
    ppAilia!.value,
    inputTextStruct,
    ailia_speech_dart.AILIA_SPEECH_TEXT_VERSION,
    0,
  );
  throwError("ailiaSpeechTranscribe", status);

  if (!postProcess) {
    throwError("must open postprocess model", -1);
  }

  status = ailiaSpeech.ailiaSpeechPostProcess(ppAilia!.value);
  throwError("ailiaSpeechTranscribe", status);

  final ffi.Pointer<ailia_speech_dart.AILIASpeechText> text =
      malloc<ailia_speech_dart.AILIASpeechText>();
  status = ailiaSpeech.ailiaSpeechGetText(
    ppAilia!.value,
    text,
    ailia_speech_dart.AILIA_SPEECH_TEXT_VERSION,
    0,
  );
  throwError("ailiaSpeechGetText", status);

  ffi.Pointer<Utf8> p = text.ref.text.cast<Utf8>();
  String result = p.toDartString();

  malloc.free(text);
  malloc.free(inputTextStruct);

  return result;
}