setVoiceInfo method

Future<bool> setVoiceInfo(
  1. String? voiceUrl,
  2. String voiceName,
  3. int swtich,
  4. int voicetype, {
  5. bool playInDevice = false,
  6. int timeout = 20,
  7. String playTimes = '3',
})

设置报警声音 param voiceUrl 下载服务器地址 param voiceName 文件名 param swtich 0无声音 1 有声音 param voicetype 0---人脸侦测报警提 示音 1---人形侦测报警提 示音 2---烟感报警提示音 3---移动侦测报警提 示音 4---离岗检测提示音 5---哭声检测提示音 6---在岗监测提示音 7---烟火相机火焰提示音 8---烟火相机烟雾提示音 param playInDevice 是否让设备播放

Implementation

Future<bool> setVoiceInfo(
    String? voiceUrl, String voiceName, int swtich, int voicetype,
    {bool playInDevice = false,
    int timeout = 20,
    String playTimes = '3'}) async {
  String urlJson = "{}";
  if (voiceUrl != null && voiceUrl.isNotEmpty) {
    var dic = {"url": voiceUrl};
    urlJson = json.encode(dic);
  }
  String cgi =
      "trans_cmd_string.cgi?cmd=2135&command=0&urlJson=$urlJson&filename=$voiceName&switch=$swtich&voicetype=$voicetype&";
  if (swtich == 0) {
    cgi =
        "trans_cmd_string.cgi?cmd=2135&command=0&switch=$swtich&voicetype=$voicetype&";
  }
  if (playInDevice == true) {
    cgi = cgi + "play=1&" + "playtimes=$playTimes&";
  } else {
    cgi = cgi + "playtimes=$playTimes&";
  }
  bool ret = await _command.writeCgi(cgi, timeout: timeout);
  if (ret) {
    CommandResult result =
        await _command.waitCommandResult((int cmd, Uint8List data) {
      if (cmd == 24785) {
        String str = utf8.decode(data);
        return str.contains("cmd=2135;") && str.contains("command=0;");
      }
      return false;
    }, timeout);
    if (result.isSuccess == true) {
      Map data = result.getMap();
      return data["result"] == "0";
    }
  }
  return false;
}