首页 版块 访问AI主站 注册 发帖
visualqu
36
积分 积分商城
0
获赞
声音AI,本地数据集40多条,上传后,数据集少了
Ta的回复 :命名流水:20181007_09335611
2
[C#]定制化图像接口示例代码2
Ta的回复 :我来完善一下定制化【声音识别】接口吧: protected void Page_Load(object sender, EventArgs e) { String mp3_url = "C:\\Users\\VisualQu\\Desktop\\test\\22.mp3"; var image = File.ReadAllBytes(mp3_url); String img64 = System.Convert.ToBase64String(image); String param = "{\"top_num\":6,\"sound\":\"" + img64 + "\"}"; String token = "24.bdda19ce481567d73bf75f1d24f02178.2592000.1541940979.282335-14366147"; string url1 = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/sound_cls/asjj08"; string Url = url1 + "?access_token=" + token; Post(Url, param); } public string Post(string strURL, string jsonParas) { //创建一个HTTP请求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL); //Post请求方式 request.Method = "POST"; //内容类型 //request.ContentType = "application/x-www-form-urlencoded"; request.ContentType = "application/json"; //将Json字符串转化为字节 byte[] payload = System.Text.Encoding.UTF8.GetBytes(jsonParas); //设置请求的ContentLength request.ContentLength = payload.Length; //发送请求,获得请求流 Stream writer; try { writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象 } catch (Exception) { writer = null; //Console.Write("连接服务器失败!"); } //将请求参数写入流 writer.Write(payload, 0, payload.Length); writer.Close();//关闭请求流 String strValue = "";//strValue为http响应所返回的字符流 HttpWebResponse response; try { //获得响应流 response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { response = ex.Response as HttpWebResponse; } Stream s = response.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(s, encode); strValue = readStream.ReadToEnd(); s.Close(); // Releases the resources of the Stream. readStream.Close(); return strValue;//返回Json数据 }
6
切换版块
智能客服