convertVoiceToText static method

Future<V2TimValueCallback<String>> convertVoiceToText({
  1. required String msgID,
  2. required String language,
})

Implementation

static Future<V2TimValueCallback<String>> convertVoiceToText({
  required String msgID,
  required String language, // "zh (cmn-Hans-CN)" "yue-Hant-HK" "en-US" "ja-JP"
}) async {
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);

  String userDataFindMsg = Tools.generateUserData(methodName: "findMessage");
  Pointer<Uint8> user_data_find_msg = Tools.string2PointerInt8(userDataFindMsg);

  var msgIDListPtr = Tools.string2PointerInt8(json.encode([msgID]));

  List<Map<String, dynamic>> message_c_list = [];
  int res1 = desktopSDK.D_TIMMsgFindMessages(msgIDListPtr, user_data_find_msg);
  if (res1 != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<String>.fromJson({
      "code": res1,
      "desc": "find message error",
      "data": "",
    });
  } else {
    Map<String, dynamic> msgListData = await getAsyncData(apiKey: userDataFindMsg);
    List<Map<String, dynamic>> dataList = List<Map<String, dynamic>>.from(json.decode(msgListData["json_param"].isEmpty ? json.encode([]) : msgListData["json_param"]));

    for (var element in dataList) {
      message_c_list.add(element);
    }
  }
  if (message_c_list.isEmpty) {
    return V2TimValueCallback<String>.fromJson({
      "code": -2,
      "desc": "find message error",
      "data": "",
    });
  }

  Pointer<Uint8> msgJsonPtr = Tools.string2PointerInt8(json.encode(message_c_list[0]));

  Pointer<Uint8> languagePtr = Tools.string2PointerInt8(language);
  int res = desktopSDK.D_TIMMsgConvertVoiceToText(msgJsonPtr, languagePtr, user_data);

  if (res != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<String>.fromJson({
      "code": res,
      "desc": "",
      "data": "",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);

    return V2TimValueCallback<String>.fromJson({
      "code": data["code"],
      "desc": data["desc"],
      "data": data["json_param"],
    });
  }
}