Skip to content

Commit

Permalink
feat: 添加sdk调用demo
Browse files Browse the repository at this point in the history
  • Loading branch information
nl8590687 committed Mar 26, 2022
1 parent 021f437 commit b828c31
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.metadata/
.metadata/
12 changes: 12 additions & 0 deletions asrt_client_demo/asrtcli/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/asrtsdk-1.0.rc1.jar"/>
<classpathentry kind="lib" path="lib/gson-2.9.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions asrt_client_demo/asrtcli/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>asrtcli</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
81 changes: 81 additions & 0 deletions asrt_client_demo/asrtcli/src/asrtcli/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
*
*/
package asrtcli;

import net.ailemon.asrt.sdk.*;
import net.ailemon.asrt.sdk.models.*;
import net.ailemon.asrt.sdk.common.*;
/**
* @author ailemon
*
*/
public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String host = "127.0.0.1";
String port = "20001";
String protocol = "http";
BaseSpeechRecognizer sr = Sdk.GetSpeechRecognizer(host, port, protocol);
String filename = "C:\\Users\\ailemon\\Desktop\\data.wav";
if(args.length > 0){
filename = args[0];
}
// ============================================
// 直接调用ASRT识别语音文件
AsrtApiResponse rsp = sr.RecogniteFile(filename);
System.out.println(rsp.statusCode);
System.out.println(rsp.statusMessage);
System.out.println(rsp.result);

// ============================================
// 调用ASRT识别语音序列
byte[] wavBytes = Common.readBinFile(filename);
Wave wav = new Wave();
wav.deserialize(wavBytes);
byte[] sampleBytes = wav.getRawSamples();
int sampleRate = wav.sampleRate;
int channels = wav.channels;
int byteWidth = wav.sampleWidth;
rsp = sr.Recognite(sampleBytes, sampleRate, channels, byteWidth);
System.out.println(rsp.statusCode);
System.out.println(rsp.statusMessage);
System.out.println(rsp.result);

// ============================================
// 调用ASRT声学模型识别语音序列
wavBytes = Common.readBinFile(filename);
wav = new Wave();
wav.deserialize(wavBytes);
sampleBytes = wav.getRawSamples();
sampleRate = wav.sampleRate;
channels = wav.channels;
byteWidth = wav.sampleWidth;
rsp = sr.RecogniteSpeech(sampleBytes, sampleRate, channels, byteWidth);
System.out.println(rsp.statusCode);
System.out.println(rsp.statusMessage);
System.out.println(rsp.result);

// ============================================
// 调用ASRT语言模型识别拼音序列1
String[] pinyins = ((String)rsp.result).split(", ");
rsp = sr.RecogniteLanguage(pinyins);
System.out.println(rsp.statusCode);
System.out.println(rsp.statusMessage);
System.out.println(rsp.result);

// ============================================
// 调用ASRT语言模型识别拼音序列2
pinyins = new String[]{"ni3", "hao3", "a1"};
rsp = sr.RecogniteLanguage(pinyins);
System.out.println(rsp.statusCode);
System.out.println(rsp.statusMessage);
System.out.println(rsp.result);

}

}

0 comments on commit b828c31

Please sign in to comment.