package com.stu.bj.utils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* http 工具类
*/
public class HttpUtil {
public static String post(String requestUrl, String accessToken, String params) throws Exception {
System.out.println(params);
String generalUrl = "";
generalUrl = requestUrl + "?access_token=" + accessToken;
System.out.println("发送的连接为:"+generalUrl);
URL url = new URL(generalUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("打开链接,开始发送请求"+new Date().getTime()/1000);
connection.setRequestMethod("POST");
// 设置通用的请求属性
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
// 得到请求的输出流对象
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(params);
out.flush();
out.close();
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> headers = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : headers.keySet()) {
System.out.println(key + "--->" + headers.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = null;
if (requestUrl.contains("nlp"))
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "GBK"));
else
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
String result = "";
String getLine;
while ((getLine = in.readLine()) != null) {
result += getLine;
}
in.close();
System.out.println("请求结束"+new Date().getTime()/1000);
System.out.println("result:" + result);
return result;
}
public static String postUnit(String requestUrl, String accessToken, String params) throws Exception {
String generalUrl = requestUrl + "?access_token=" + accessToken;
System.out.println("发送的连接为:"+generalUrl);
URL url = new URL(generalUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("打开链接,开始发送请求"+new Date().getTime()/1000);
connection.setRequestMethod("POST");
// 设置通用的请求属性
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
// 得到请求的输出流对象
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(),"UTF-8");
out.write(params);
out.flush();
out.close();
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> headers = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : headers.keySet()) {
System.out.println(key + "--->" + headers.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = null;
if (requestUrl.contains("nlp"))
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "GBK"));
else
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
String result = "";
String getLine;
while ((getLine = in.readLine()) != null) {
result += getLine;
}
in.close();
System.out.println("请求结束"+new Date().getTime()/1000);
System.out.println("result:" + result);
return result;
}
/**
* 语音合成HTTP方法
* @param requestUrl 请求的接口地址 拼接access_token后的
* @param params 语音合成的参数
* @throws Exception
*/
public static String postVoice(String requestUrl,String params) throws Exception {
String workspace = System.getProperty("user.home");
String path = workspace+"/text2audio/";
try {
if (!(new File(path).isDirectory())) {
new File(path).mkdir();
}
} catch (SecurityException e) {
e.printStackTrace();
}
String filePath = path+"VOICE"+new Date().getTime()/1000+".mp3";
String generalUrl = requestUrl;
URL url = new URL(generalUrl);
System.out.println(generalUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("打开链接,开始发送请求"+new Date().getTime()/1000);
connection.setRequestMethod("POST");
// 设置通用的请求属性
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
// 得到请求的输出流对象
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(params);
out.flush();
out.close();
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> headers = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : headers.keySet()) {
System.out.println(key + "--->" + headers.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
InputStream inputStream = connection.getInputStream();
FileOutputStream outputStream = new FileOutputStream(filePath);
byte[] buffer = new byte[1024];
int len = -1;
while ((len=inputStream.read(buffer))!=-1) {
outputStream.write(buffer,0,len);
}
outputStream.close();
System.out.println("请求结束"+new Date().getTime()/1000);
System.out.println("MP3文件保存目录:" + filePath);
return filePath;
}
/**
* 获取语音识别内容
* @param requestUrl
* @param params
* @return
* @throws Exception
*/
public static String postASR(String requestUrl, String params) throws Exception {
System.out.println(params);
String generalUrl = requestUrl;
System.out.println("发送的连接为:"+generalUrl);
URL url = new URL(generalUrl);
// 打开和URL之间的连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println("打开链接,开始发送请求"+new Date().getTime()/1000);
connection.setRequestMethod("POST");
// 设置通用的请求属性
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
// 得到请求的输出流对象
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(param
没有合适的资源?快使用搜索试试~ 我知道了~
腾讯AI身份证识别,语音合成demo
共90个文件
xml:61个
class:15个
java:13个
4星 · 超过85%的资源 需积分: 10 48 下载量 80 浏览量
2018-01-31
11:24:10
上传
评论
收藏 79KB ZIP 举报
温馨提示
腾讯AI目前没有SDK自己在网上找的例子分享给大家。这个只有语音合成和身份证识别的demo。请看仔细!
资源推荐
资源详情
资源评论
收起资源包目录
tencent_test.zip (90个子文件)
tencent_test
pom.xml 10KB
target
classes
com
stu
bj
tencent_api
AaiTTS$Data.class 1KB
AaiTTS.class 1KB
TencentAPI.class 2KB
sign
TencentAISignSort.class 3KB
TencentAISign.class 3KB
demo
IdCardIndentify$myThread.class 678B
Result.class 5KB
TextToVoice.class 4KB
IdCardIndentify.class 3KB
utils
MD5.class 1KB
FileUtil.class 2KB
Base64Util.class 2KB
HttpsUtil4Tencent$1.class 960B
HttpsUtil4Tencent.class 7KB
HttpUtil.class 9KB
generated-sources
annotations
src
test
java
main.java 80B
main
resources
java
com
stu
bj
tencent_api
AaiTTS.java 1015B
TencentAPI.java 2KB
sign
TencentAISignSort.java 5KB
TencentAISign.java 7KB
demo
TextToVoice.java 3KB
IdCardIndentify.java 2KB
Result.java 3KB
utils
HttpsUtil4Tencent.java 8KB
Base64Util.java 3KB
HttpUtil.java 15KB
MD5.java 1KB
FileUtil.java 1KB
.idea
misc.xml 439B
modules.xml 264B
encodings.xml 294B
compiler.xml 636B
workspace.xml 47KB
libraries
Maven__commons_lang_commons_lang_2_5.xml 525B
Maven__commons_net_commons_net_2_0.xml 514B
Maven__commons_io_commons_io_2_4.xml 503B
Maven__com_googlecode_soundlibs_jlayer_1_0_1_4.xml 559B
Maven__org_slf4j_slf4j_log4j12_1_7_5.xml 534B
Maven__org_apache_httpcomponents_httpclient_cache_4_3.xml 605B
Maven__com_nesscomputing_testing_findbugs_annotations_2_0_0.xml 647B
Maven__joda_time_joda_time_2_0.xml 492B
Maven__cglib_cglib_2_1_3.xml 462B
Maven__org_apache_httpcomponents_httpmime_4_3.xml 549B
Maven__org_json_json_20160810.xml 488B
Maven__org_bouncycastle_bcpkix_jdk15on_1_50.xml 562B
Maven__net_sf_ehcache_ehcache_core_2_5_1.xml 547B
Maven__junit_junit_4_11.xml 455B
Maven__org_apache_httpcomponents_httpclient_4_3.xml 563B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_5_4.xml 644B
Maven__com_google_code_findbugs_jsr305_1_3_9.xml 545B
Maven__net_sf_ezmorph_ezmorph_1_0_6.xml 512B
Maven__com_alibaba_fastjson_1_2_35.xml 514B
Maven__commons_codec_commons_codec_1_9.xml 536B
Maven__org_apache_commons_commons_lang3_3_1.xml 556B
Maven__org_apache_httpcomponents_httpcore_4_3.xml 549B
Maven__org_hamcrest_hamcrest_core_1_3.xml 532B
Maven__opensymphony_ognl_2_6_11.xml 490B
Maven__org_bouncycastle_bcprov_jdk16_1_38.xml 548B
Maven__com_googlecode_soundlibs_tritonus_share_0_3_7_4.xml 615B
Maven__org_slf4j_slf4j_api_1_7_5.xml 506B
Maven__com_thoughtworks_xstream_xstream_1_3_1.xml 552B
Maven__com_fasterxml_jackson_core_jackson_databind_2_5_4.xml 623B
Maven__commons_fileupload_commons_fileupload_1_2_2.xml 605B
Maven__commons_logging_commons_logging_1_1_3.xml 572B
Maven__com_google_code_gson_gson_2_1.xml 501B
Maven__com_google_guava_guava_11_0_1.xml 513B
Maven__commons_configuration_commons_configuration_1_6.xml 624B
Maven__com_fasterxml_jackson_core_jackson_core_2_5_4.xml 595B
Maven__com_googlecode_soundlibs_mp3spi_1_9_5_4.xml 559B
Maven__com_nesscomputing_ness_syslog4j_0_9_47_NESS_3.xml 622B
Maven__com_baidu_aip_java_sdk_4_0_0.xml 515B
Maven__net_sf_json_lib_json_lib_jdk15_2_4.xml 521B
Maven__org_bouncycastle_bcprov_jdk15on_1_50.xml 562B
Maven__log4j_log4j_1_2_17.xml 469B
Maven__org_codehaus_jackson_jackson_core_asl_1_9_13.xml 606B
Maven__org_codehaus_jackson_jackson_mapper_asl_1_9_13.xml 620B
Maven__asm_asm_1_5_3.xml 440B
Maven__com_xiaoleilu_hutool_all_3_0_6.xml 529B
Maven__javax_servlet_servlet_api_2_5.xml 522B
Maven__xpp3_xpp3_min_1_1_4c.xml 486B
Maven__commons_collections_commons_collections_3_2_1.xml 616B
Maven__javax_servlet_jstl_1_2.xml 473B
Maven__com_opensymphony_xwork_2_0_4.xml 506B
Maven__commons_beanutils_commons_beanutils_core_1_8_0.xml 629B
Maven__commons_beanutils_commons_beanutils_1_8_0.xml 594B
Maven__commons_digester_commons_digester_1_8.xml 569B
Maven__javax_servlet_jsp_jsp_api_2_2_1_b03.xml 552B
Maven__net_sf_ehcache_ehcache_web_2_0_4.xml 540B
inspectionProfiles
tencent_test.iml 6KB
共 90 条
- 1
资源评论
- ryX594212018-10-08下载之后本地运行可以使用(只用了语音合成),希望对我们要做的智能机器人在线阅读功能有借鉴作用吧。
- q7822311392018-07-20项目导入Androidstudio用不了,少很多文件
kunnl
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功