/// <summary> /// 发送语音识别 /// </summary> /// <param name="audio">AudioClip 音频</param> /// <param name="complete">回调结果</param> /// <param name="engineType"> 普通话(sms16k),普通话(sms8k),英语(sms-en8k),英语(sms-en16k) </param> public void PostIAT(byte[] audio, UnityAction <string> complete, EngineType engineType = EngineType.SmsEn16k) { if (audio == null || audio.Length == 0) { Debug.LogErrorFormat("[XFYunIAT].PostIAT audio error null or count=0. "); if (complete != null) { complete.Invoke(string.Empty); } return; } string curTime = UtilityTime.GetTimeStampStrByUtcNow(); string param = "{\"aue\":\"" + Aue + "\"" + ",\"engine_type\":\"" + GetEngineType(engineType) + "\"}"; byte[] bytedata = Encoding.ASCII.GetBytes(param); string x_param = Convert.ToBase64String(bytedata); string result = string.Format("{0}{1}{2}", AppKey, curTime, x_param); string X_checksum = Md5(result); HTTPRequest request = new HTTPRequest(new Uri(Host), HTTPMethods.Post, (req, resp) => { if (resp.StatusCode == 200) { Debug.LogFormat("[XFYunIAT].PostIAT complete ."); Debug.LogFormat("返回结果 '{0}' .", resp.DataAsText); if (complete != null) { complete.Invoke(resp.DataAsText); } } else { Debug.LogErrorFormat("[XFYunIAT].PostIAT code error code : '{0}' , data :'{1}' , msg : '{2}'. ", resp.StatusCode, resp.DataAsText, resp.Message); if (complete != null) { complete.Invoke(string.Empty); } } }); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddHeader("charset", "utf-8"); request.AddHeader("X-Appid", AppId); request.AddHeader("X-CurTime", curTime); request.AddHeader("X-Param", x_param); request.AddHeader("X-CheckSum", X_checksum); string audioStr = Convert.ToBase64String(audio); request.AddField("audio", audioStr); request.Send(); }
/// <summary> /// 压缩zip /// </summary> /// <param name="tempWorkPath">临时工作路径</param> /// <param name="fileName"></param> /// <param name="fileList"></param> /// <returns></returns> public static byte[] EnZipBytes(string tempWorkPath, string[] fileName, List <byte[]> fileList) { if (fileName == null || fileList == null || (fileName.Length != fileList.Count)) { Debug.LogError("not s3 pose files."); return(null); } string fname = UtilityTime.GetTimeStampStrByUtcNow() + ".zip"; string zipFileName = Utility.Path.GetCombinePath(tempWorkPath, fname); // 获取工作目录 EnZipFile(zipFileName, fileName, fileList); // 把字节流打包成zip byte[] bytes = File.ReadAllBytes(zipFileName); // 把文件读取到内存中 File.Delete(zipFileName); // 删除本地硬盘上文件 return(bytes); }