-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
146 changed files
with
13,671 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# ai | ||
|
||
## Runtime Environment | ||
- [Java 7](https://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html) | ||
|
||
## Simple Tutorial | ||
本代码都是基于百度文档整理总结出来的。方便直接使用API的开发人员。没必要再去走弯路找各种工具类 | ||
|
||
**包含了百度AI 腾讯AI接口Java-API调用示例代码** | ||
|
||
**本项目不属于完整的Web项目。只是整理了示例代码。main函数执行而已** | ||
|
||
### 腾讯优图-人脸检测 | ||
腾讯优图接入官网文档:https://open.youtu.qq.com/welcome/developer | ||
|
||
### 百度大脑-人脸检测 | ||
百度大脑接入官网文档:https://ai.baidu.com/docs#/Begin/top | ||
|
||
## Tips | ||
- Commits on 2018-04-08 | ||
|
||
## Links | ||
- [人工智能](https://gitee.com/xshuai/ai) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.bdxc</groupId> | ||
<artifactId>ai</artifactId> | ||
<packaging>war</packaging> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>ai</name> | ||
<url>https://maven.apache.org</url> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<org.springframework.version>4.2.0.RELEASE</org.springframework.version> | ||
<org.apache.httpcomponents.version>4.3</org.apache.httpcomponents.version> | ||
<mongo.version>2.12.5</mongo.version> | ||
<morphia.version>0.107</morphia.version> | ||
</properties> | ||
|
||
<!-- 指定Maven仓库 --> | ||
<repositories> | ||
<repository> | ||
<id>maven</id> | ||
<name>Maven Repository Switchboard</name> | ||
<layout>default</layout> | ||
<url>https://repository.sonatype.org/content/groups/public/</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
|
||
<repository> | ||
<id>maven1</id> | ||
<name>Maven Repository Switchboard</name> | ||
<layout>default</layout> | ||
<url>https://repo1.maven.org/maven2</url> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>alibaba-opensource</id> | ||
<name>alibaba-opensource</name> | ||
<url>https://code.alibabatech.com/mvn/releases/</url> | ||
<layout>default</layout> | ||
</repository> | ||
<repository> | ||
<id>alibaba-opensource-snapshot</id> | ||
<name>alibaba-opensource-snapshot</name> | ||
<url>https://code.alibabatech.com/mvn/snapshots/</url> | ||
<layout>default</layout> | ||
</repository> | ||
<repository> | ||
<id>certral</id> | ||
<name>Central Repository</name> | ||
<url>https://nexus.sourcesense.com/nexus/content/repositories/public/</url> | ||
<layout>default</layout> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
|
||
</repositories> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/org.json/json --> | ||
<dependency> | ||
<groupId>org.json</groupId> | ||
<artifactId>json</artifactId> | ||
<version>20160810</version> | ||
</dependency> | ||
<!-- jstl --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
<version>1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
<artifactId>jsp-api</artifactId> | ||
<version>2.2.1-b03</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.baidu.aip</groupId> | ||
<artifactId>java-sdk</artifactId> | ||
<version>4.0.0</version> | ||
</dependency> | ||
<!-- servlet --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<version>1.2.35</version> | ||
</dependency> | ||
<!-- log4j slf4j--> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>1.2.17</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>1.7.5</version> | ||
</dependency> | ||
|
||
|
||
|
||
<!-- junit --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>commons-fileupload</groupId> | ||
<artifactId>commons-fileupload</artifactId> | ||
<version>1.2.2</version> | ||
</dependency> | ||
|
||
|
||
<!-- 文件上传依赖包 --> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>2.4</version> | ||
</dependency> | ||
<!-- 网络编程工具包 及commons常用包 --> | ||
<dependency> | ||
<groupId>commons-net</groupId> | ||
<artifactId>commons-net</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<version>1.9</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-collections</groupId> | ||
<artifactId>commons-collections</artifactId> | ||
<version>3.2.1</version> | ||
</dependency> | ||
<!-- httpcliet --> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>${org.apache.httpcomponents.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient-cache</artifactId> | ||
<version>${org.apache.httpcomponents.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpmime</artifactId> | ||
<version>${org.apache.httpcomponents.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.nesscomputing</groupId> | ||
<artifactId>ness-syslog4j</artifactId> | ||
<version>0.9.47-NESS-3</version> | ||
</dependency> | ||
<!-- JSON --> | ||
<dependency> | ||
<groupId>net.sf.json-lib</groupId> | ||
<artifactId>json-lib</artifactId> | ||
<version>2.4</version> | ||
<classifier>jdk15</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.thoughtworks.xstream</groupId> | ||
<artifactId>xstream</artifactId> | ||
<version>1.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.opensymphony</groupId> | ||
<artifactId>xwork</artifactId> | ||
<version>2.0.4</version> | ||
</dependency> | ||
<!-- RSA 加密包 | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk16</artifactId> | ||
<version>1.46</version> | ||
</dependency>--> | ||
|
||
<!-- ehcache 缓存 --> | ||
<dependency> | ||
<groupId>net.sf.ehcache</groupId> | ||
<artifactId>ehcache-core</artifactId> | ||
<version>2.5.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.sf.ehcache</groupId> | ||
<artifactId>ehcache-web</artifactId> | ||
<version>2.0.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-configuration</groupId> | ||
<artifactId>commons-configuration</artifactId> | ||
<version>1.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>cglib</groupId> | ||
<artifactId>cglib</artifactId> | ||
<version>2.1_3</version> | ||
</dependency> | ||
<!-- 有依赖关系的jar --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.5.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.5.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-mapper-asl</artifactId> | ||
<version>1.9.13</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.xiaoleilu</groupId> | ||
<artifactId>hutool-all</artifactId> | ||
<version>3.0.6</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk16 --> | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk16</artifactId> | ||
<version>1.38</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on --> | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcpkix-jdk15on</artifactId> | ||
<version>1.50</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.soundlibs</groupId> | ||
<artifactId>mp3spi</artifactId> | ||
<version>1.9.5.4</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>2.1.1</version> | ||
<configuration> | ||
<!-- https://maven.apache.org/plugins/maven-war-plugin/ --> | ||
<packagingExcludes>WEB-INF/web.xml</packagingExcludes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.xs.audio.tns; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
|
||
import com.xs.util.baidu.Base64Util; | ||
import com.xs.util.baidu.FileUtil; | ||
import com.xs.util.baidu.HttpUtil; | ||
import com.xs.util.baidu.RandomStringGenerator; | ||
/** | ||
* 语音识别Java-API JSON上传方式示例代码 | ||
* @author 小帅丶 | ||
* | ||
*/ | ||
public class Audio2Text { | ||
//接口地址 | ||
private static final String AUDIO2TEXT_URL = "https://vop.baidu.com/server_api"; | ||
public static void main(String[] args) throws Exception { | ||
//合成的MP3语音文件 | ||
String path = "C:/Users/Administrator/text2audio/VOICE1512521962.mp3"; | ||
//MP3转pcm要保存的路径和文件名 | ||
String path2 = "G:/1.pcm"; | ||
MP3ConvertPCM.mp3Convertpcm(path, path2); | ||
// 对语音二进制数据进行识别 | ||
byte[] data = FileUtil.readFileByBytes(path2); //readFileByBytes仅为获取二进制数据示例 | ||
String speech = Base64Util.encode(data); | ||
File file = new File(path2); | ||
long len = file.length(); | ||
String result = Audio2text("pcm", 16000,RandomStringGenerator.getRandomStringByLength(60),"自己的token", speech, len); | ||
System.out.println(result); | ||
} | ||
/** | ||
* JSON方式上传 | ||
* @param format 必填 语音文件的格式,pcm 或者 wav 或者 amr。不区分大小写。推荐pcm文件 | ||
* @param rate 必填 采样率, 8000 或者 16000, 推荐 16000 采用率 | ||
* @param channel 必填 声道数,仅支持单声道,请填写固定值 1 | ||
* @param cuid 必填 用户唯一标识,用来区分用户,计算UV值。建议填写能区分用户的机器 MAC 地址或 IMEI 码,长度为60字符以内。 | ||
* @param token 必填 开放平台获取到的access_token, 见上面的“鉴权认证机制”段落 | ||
* @param lan 选填 语种选择,默认中文(zh)。 中文=zh、粤语=ct、英文=en,不区分大小写 | ||
* @param url 选填 可下载的语音下载地址,与callback连一起使用,确保百度服务器可以访问。 | ||
* @param callback 选填 用户服务器的识别结果回调地址,确保百度服务器可以访问 | ||
* @param speech 选填 本地语音文件的的二进制语音数据 ,需要进行base64 编码。与len参数连一起使用。 | ||
* @param len 选填 本地语音文件的的字节数,单位字节 | ||
*/ | ||
public static String Audio2text(String format,Integer rate,String cuid,String token,String speech,long len) throws Exception{ | ||
HashMap<String, Object> paramMap = new HashMap<String, Object>(); | ||
paramMap.put("speech",speech); | ||
paramMap.put("format", format); | ||
paramMap.put("rate", rate); | ||
paramMap.put("channel",1); | ||
paramMap.put("cuid",cuid); | ||
paramMap.put("token", token); | ||
paramMap.put("len", len); | ||
net.sf.json.JSONObject params = net.sf.json.JSONObject.fromObject(paramMap); | ||
String data = HttpUtil.postASR(AUDIO2TEXT_URL,params.toString()); | ||
System.out.println("语音文件识别的内容:"+data); | ||
return data; | ||
} | ||
} |
Oops, something went wrong.