Java工程师如何高效地对接百度AI接口
import java.io.File; import java.io.IOException; import com.baidu.aip.speech.AipSpeech; import org.json.JSONObject; public class Sample { // 设置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) { // 初始化一个AipSpeech AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY); // 调用API进行语音识别 JSONObject res = client.asr("test.pcm", "pcm", 16000, null); System.out.println(res.toString(2)); } }
import com.baidu.aip.imageclassify.AipImageClassify; import org.json.JSONObject; public class Sample { // 设置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) { // 初始化一个AipImageClassify AipImageClassify client = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY); // 调用API进行图像识别 String path = "test.jpg"; JSONObject res = client.advancedGeneral(path, new HashMap<String, String>()); System.out.println(res.toString(2)); } }
import com.baidu.aip.nlp.AipNlp; import org.json.JSONObject; public class Sample { // 设置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) { // 初始化一个AipNlp AipNlp client = new AipNlp(APP_ID, API_KEY, SECRET_KEY); // 调用API进行文本分析 String text = "今天是个好日子"; JSONObject res = client.sentimentClassify(text, new HashMap<String, Object>()); System.out.println(res.toString(2)); } }
以上是Java工程师如何高效地对接百度AI接口的详细内容。更多信息请关注PHP中文网其他相关文章!