Skip to content

Commit

Permalink
modify verifyspeaker api
Browse files Browse the repository at this point in the history
  • Loading branch information
sanqianyuejia committed Aug 22, 2014
1 parent 6e51763 commit 5245bd3
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 19 deletions.
46 changes: 29 additions & 17 deletions voiceplusplus/src/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import utils.Constants;
import client.Client;
import client.VerifyRes;
import model.Person;
import model.Speech;

Expand All @@ -20,40 +20,52 @@ public static void main(String[] args) {
int ret = -1;
String idString = "10001"; // 群组编号
String nameString = "test"; // 说话人别名,同一群组内必须唯一
String pwdString = "0123456789"; // 口令内容
String pwdString = "*"; // 口令内容

// Create server
Client client = new Client("1ee0d9b01e8d92a155597785e0b7074e", "1ee0d9b01e8d92a155597785e0b7074e");
client.setServer("115.28.177.226", 11638, "1", Constants.TEXT_DEPENDENT);
Client client = new Client("65e02ffc45b0d01bd09fa3e0e9fe1b14", "65e02ffc45b0d01bd09fa3e0e9fe1b14");
client.setServer("192.168.1.253", 11638, "1", Constants.TEXT_DEPENDENT);

// Create person
// Create Person
Person person = new Person(client, idString, nameString);
if ( (ret = person.create()) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
return;
if ( (ret = person.getInfo()) != Constants.RETURN_SUCCESS) {
if ( (ret = person.create()) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
}
}

// Create Speech
Speech speech = new Speech("pcm/raw", 8000, true);
Speech speech = new Speech("pcm/raw", 16000, true);
speech.setRule(pwdString);

// Add Speech to person
for (String filepath : args) {
speech.setData(readWavform(filepath)); // readWavform是读文件到byte缓冲的函数
if ((ret = person.addSpeech(speech)) != Constants.RETURN_SUCCESS) {
if (person.getFlag() == false) {
for (String filepath : args) {
speech.setData(readWavform("wav/"+filepath)); // readWavform是读文件到byte缓冲的函数
if ((ret = person.addSpeech(speech)) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
}
}

// Register voiceprint for speaker
if ((ret = client.registerVoiceprint(person)) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
return;
}

// Output result
System.out.println(person.getId()+"\t"+person.getName()+": Register voiceprint success.");
}

// Register voiceprint for speaker
if ((ret = client.registerVoiceprint(person)) != Constants.RETURN_SUCCESS) {
// Verify voiceprint for speaker
VerifyRes res = new VerifyRes();
speech.setRule("5318");
speech.setData(readWavform("wav/ver_4digits_5318.wav"));
if ((ret = client.verifyVoiceprint(person, speech, res)) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
return;
}

// Output result
System.out.println(person.getId()+"\t"+person.getName()+": Register voiceprint success.");
System.out.println(person.getId()+"\t"+person.getName()+": "+res.getResult()+"-"+res.getSimilarity());
}

public static byte[] readWavform(String filename) {
Expand Down
2 changes: 1 addition & 1 deletion voiceplusplus/src/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public synchronized int verifyVoiceprint(Person person, Speech speech,
if (!person.getId().isEmpty()) {
JSONObject result = getClientService().clientVerifyVoiceprint(
person.getId(), person.getName(), speech.getCodec(), speech.getSampleRate(),
speech.getVerify(), speech.getData());
speech.getVerify(), speech.getRule(), speech.getData());

if (!result.getBoolean(Constants.SUCCESS)) {
ret = result.getInt(Constants.ERROR_CODE);
Expand Down
1 change: 1 addition & 0 deletions voiceplusplus/src/model/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Person(Client client, String id, String name) {
this.client = client;
this.id = id;
this.name = name;
this.tag = "";
}

public Person(Client client) {
Expand Down
3 changes: 2 additions & 1 deletion voiceplusplus/src/service/ClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public JSONObject clientRegisterVoiceprint(String id, String name, boolean bUpda
return tokenJson;
}

public JSONObject clientVerifyVoiceprint(String id, String name, String codec, int sr, boolean bVerify, byte[] data) {
public JSONObject clientVerifyVoiceprint(String id, String name, String codec, int sr, boolean bVerify, String rule, byte[] data) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(Constants.API_KEY, super.getClient().getKey());
parameters.put(Constants.API_SECRET, super.getClient().getSecret());
parameters.put(Constants.ID, id);
parameters.put(Constants.CODEC, codec);
parameters.put(Constants.SAMPLERATE, String.valueOf(sr));
parameters.put(Constants.VERIFY, String.valueOf(bVerify));
parameters.put(Constants.SPEECH_RULE, rule);

String tokenResult = HttpURLUtils.doUploadFile(super.getClient().getServerString()+Constants.URL_MODEL_VERIFY, parameters,
Constants.FILEPARAM, "./testfile.wav", "multipart/form-data;", data);
Expand Down
Binary file removed voiceplusplus/wav/0-9.1.wav
Binary file not shown.
Binary file removed voiceplusplus/wav/0-9.2.wav
Binary file not shown.
Binary file removed voiceplusplus/wav/0-9.3.wav
Binary file not shown.
Binary file removed voiceplusplus/wav/0-9.4.wav
Binary file not shown.
Binary file removed voiceplusplus/wav/0-9.5.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_0275.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_1047.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_2645.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_3506.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_5839.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_6234.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_7183.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_7982.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_8190.wav
Binary file not shown.
Binary file added voiceplusplus/wav/reg_4digits_9461.wav
Binary file not shown.
Binary file added voiceplusplus/wav/ver_4digits_1046.wav
Binary file not shown.
Binary file added voiceplusplus/wav/ver_4digits_5318.wav
Binary file not shown.
Binary file removed voiceplusplus/wav/zhimakaimen.wav
Binary file not shown.

0 comments on commit 5245bd3

Please sign in to comment.