Background Management app page point download jar package
1.aip-java-sdk-4.1.1.jar
2.json-20160810.jar
3.log4j-1.2.17.jar
Package afeng.util;
Import Com.baidu.aip.speech.AipSpeech;
Import Com.baidu.aip.speech.TtsResponse;
Import Com.baidu.aip.util.Util;
Import org.json.JSONException;
Import Org.json.JSONObject;
Import java.io.IOException;
Import Java.util.HashMap;
public class Tovoice {
Set Appid/ak/sk
public static final String app_id = "Your APP ID";
public static final String Api_key = "Your API KEY";
public static final String Secret_key = "Your SECRET KEY";
public static void Main (string[] args) {
Initialize a Aipspeech
Aipspeech client = new Aipspeech (app_id, Api_key, Secret_key);
Optional: Set network connection parameters
Client.setconnectiontimeoutinmillis (2000);
Client.setsockettimeoutinmillis (60000);
Optional: Set proxy server address, HTTP and socket two selected, or none set
Client.sethttpproxy ("Proxy_host", Proxy_port); Set HTTP Proxy
Client.setsocketproxy ("Proxy_host", Proxy_port); Setting up the Socket proxy
hashmap<string, object> options = new hashmap<string, object> ();
Options.put ("SPD", "5");
Options.put ("Pit", "5");
Pronunciation person Choice, 0 for female voice, 1 for male, 3 for emotional synthesis-degrees carefree, 4 for emotional synthesis-degrees ya ya, the default for ordinary women
Options.put ("Per", "4");
String string = "Sssssssssss";
Calling interface
Ttsresponse res = client.synthesis (string, "zh", 1, options);
Ttsresponse res = client.synthesis ("Drunken Good house man Hello", "zh", 1, NULL);
byte[] data = Res.getdata ();//Voice file byte
Jsonobject res1 = Res.getresult ();
if (data! = NULL) {
try {
Util.writebytestofilesystem (data, "D:/work.mp3");
Calling interface
Jsonobject res2 = CLIENT.ASR (data, "PCM", 16000, NULL);
System.out.println (res2.tostring (2));
} catch (IOException e) {
E.printstacktrace ();
}
}
if (res1! = null) {
try {
System.out.println (res1.tostring (2));
} catch (Jsonexception e) {
E.printstacktrace ();
}
}
}
}
Baidu Voice, with Jar package way, MAVEN has a problem, wasted a long time