技术交流QQ群
933925017
livegbs接口 https://gbs.liveqing.com:10010/apidoc/#api-control-ControlTalk
喊话流程是每次取4000个字符然后进行base64encoding–>urlencode
官方给的图片
是用的golang写的
2.java实现
/**
* 青柿语音喊话
*/
public Boolean liveGBSShout(String file, String serial, Integer channel) {
byte[] bytes = getBytes(file);
int length = bytes.length;
int step = 4000;
String base64Data = null;
Boolean flag = true;
for (int i = 0; i <= length; i = i + step) {
if ((i + step) > length) {
byte[] subBytes = subBytes(bytes, i, length - i);
base64Data = Base64.getEncoder().encodeToString(subBytes);
} else {
byte[] subBytes = subBytes(bytes, i, step);
base64Data = Base64.getEncoder().encodeToString(subBytes);
}
try {
String encode = URLEncoder.encode(base64Data, "utf-8");
String url = "https://channel2.cspid.cn/api/v1/control/talk?serial=" + serial + "&channel=" + channel + "&audio=" + encode;
String get = HttpClientUtils.doGet(url);
} catch (Exception e) {
e.printStackTrace();
flag = false;
}
}
return flag;
}
// 拷贝byte数组
public static byte[] subBytes(byte[] src, int begin, int length) {
byte[] bytes = new byte[length];
System.arraycopy(src, begin, bytes, 0, length);
return bytes;
}