Baidu Voice, with Jar package way, MAVEN has a problem, wasted a long time

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.