Skip to content

Commit

Permalink
update to v2.0beta
Browse files Browse the repository at this point in the history
  • Loading branch information
sanqianyuejia committed Aug 26, 2014
1 parent 5245bd3 commit 2228dfb
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 44 deletions.
24 changes: 19 additions & 5 deletions voiceplusplus/src/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public static void main(String[] args) {
String pwdString = "*"; // 口令内容

// Create server
Client client = new Client("65e02ffc45b0d01bd09fa3e0e9fe1b14", "65e02ffc45b0d01bd09fa3e0e9fe1b14");
client.setServer("192.168.1.253", 11638, "1", Constants.TEXT_DEPENDENT);
Client client = new Client("26bf86dc87c11982ec9905ddce8dd6e8", "26bf86dc87c11982ec9905ddce8dd6e8");
client.setServer("127.0.0.1", 81, "1", Constants.TEXT_DEPENDENT);

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

// Create Person
if ( (ret = person.getInfo()) != Constants.RETURN_SUCCESS) {
if ( (ret = person.create()) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
Expand Down Expand Up @@ -58,14 +63,23 @@ public static void main(String[] args) {

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

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

// Identify voiceprint for speaker
if ((ret = client.identifyVoiceprint_2(person, speech, res)) != Constants.RETURN_SUCCESS) {
System.err.println(person.getLastErr()+":"+String.valueOf(ret));
}

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

public static byte[] readWavform(String filename) {
Expand Down
23 changes: 1 addition & 22 deletions voiceplusplus/src/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,7 @@ public synchronized int identifyVoiceprint_2(Person person, Speech speech,
int ret = Constants.RETURN_SUCCESS;

JSONObject result = getClientService().clientIdentifyVoiceprint_2(person.getId(),
speech.getCodec(), speech.getSampleRate(), speech.getData());

if (!result.getBoolean(Constants.SUCCESS)) {
ret = result.getInt(Constants.ERROR_CODE);
super.setLastErr(result.getString(Constants.ERROR));
super.setErrCode(ret);
} else {
person.setId(result.getString(Constants.ID));
person.setName(result.getString(Constants.NAME));
res.setResult(result.getBoolean(Constants.RESULT));
res.setSimilarity(result.getDouble(Constants.SIMILARITY));
}

return ret;
}

public synchronized int identifyVoiceprint_3(Person person, Speech speech,
VerifyRes res) {
int ret = Constants.RETURN_SUCCESS;

JSONObject result = getClientService().clientIdentifyVoiceprint_3(person.getId(),
speech.getCodec(), speech.getSampleRate(), speech.getData());
speech.getCodec(),speech.getSampleRate(), speech.getVerify(), speech.getRule(), speech.getData());

if (!result.getBoolean(Constants.SUCCESS)) {
ret = result.getInt(Constants.ERROR_CODE);
Expand Down
20 changes: 4 additions & 16 deletions voiceplusplus/src/service/ClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public JSONObject clientVerifyVoiceprint(String id, String name, String codec, i
parameters.put(Constants.API_KEY, super.getClient().getKey());
parameters.put(Constants.API_SECRET, super.getClient().getSecret());
parameters.put(Constants.ID, id);
parameters.put(Constants.NAME, name);
parameters.put(Constants.CODEC, codec);
parameters.put(Constants.SAMPLERATE, String.valueOf(sr));
parameters.put(Constants.VERIFY, String.valueOf(bVerify));
Expand Down Expand Up @@ -56,12 +57,14 @@ public JSONObject clientIdentifyVoiceprint(String id, String codec, int sr, byte
return tokenJson;
}

public JSONObject clientIdentifyVoiceprint_2(String id, String codec, int sr, byte[] data) {
public JSONObject clientIdentifyVoiceprint_2(String id, 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.CODEC, codec);
parameters.put(Constants.SAMPLERATE, String.valueOf(sr));
parameters.put(Constants.VERIFY, String.valueOf(bVerify));
parameters.put(Constants.SPEECH_RULE, rule);
parameters.put(Constants.ID, id);

String tokenResult = HttpURLUtils.doUploadFile(super.getClient().getServerString()+Constants.URL_MODEL_IDENTIFY_2, parameters,
Expand All @@ -71,21 +74,6 @@ public JSONObject clientIdentifyVoiceprint_2(String id, String codec, int sr, by
return tokenJson;
}

public JSONObject clientIdentifyVoiceprint_3(String id, String codec, int sr, 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.CODEC, codec);
parameters.put(Constants.SAMPLERATE, String.valueOf(sr));
parameters.put(Constants.ID, id);

String tokenResult = HttpURLUtils.doUploadFile(super.getClient().getServerString()+Constants.URL_MODEL_IDENTIFY_3, parameters,
Constants.FILEPARAM, "./testfile.wav", "multipart/form-data;", data);
JSONObject tokenJson = (JSONObject) JSONObject.fromObject(tokenResult);

return tokenJson;
}

public JSONObject personFindAll(int limit) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(Constants.API_KEY, super.getClient().getKey());
Expand Down
1 change: 0 additions & 1 deletion voiceplusplus/src/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@ public class Constants {
public static final String URL_MODEL_VERIFY = "/model/verify.json";
public static final String URL_MODEL_IDENTIFY = "/model/identify.json";
public static final String URL_MODEL_IDENTIFY_2 = "/model/identify_2.json";
public static final String URL_MODEL_IDENTIFY_3 = "/model/identify_3.json";
}
Binary file added voiceplusplus/wav/imp_4digits_0475.wav
Binary file not shown.
Binary file added voiceplusplus/wav/imp_4digits_0641.wav
Binary file not shown.
Binary file added voiceplusplus/wav/imp_4digits_1047.wav
Binary file not shown.
Binary file added voiceplusplus/wav/imp_4digits_3408.wav
Binary file not shown.
Binary file added voiceplusplus/wav/imp_4digits_6234.wav
Binary file not shown.
Binary file added voiceplusplus/wav/ver_4digits_3408.wav
Binary file not shown.
Binary file added voiceplusplus/wav/ver_4digits_3506.wav
Binary file not shown.
Binary file added voiceplusplus/wav/ver_4digits_4752.wav
Binary file not shown.

0 comments on commit 2228dfb

Please sign in to comment.