JAVA接收PCM文件使用百度語音進行識別

//設置APPID/AK/SK
public static final String APP_ID = " ";
public static final String API_KEY = " ";
public static final String SECRET_KEY = " ";

//接收pcm文件並對語音二進制數據進行識別
public void nb(@RequestParam(value=“file”) MultipartFile file) throws IOException, JSONException {
// 初始化一個AipSpeech
AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);
byte[] bytes = file.getBytes();
JSONObject asrRes = client.asr(bytes, “pcm”, 16000, null);
System.out.println(asrRes);
if((“success.”).equals(asrRes.get(“err_msg”).toString())){
String result=asrRes.get(“result”).toString();
System.out.println(“語音識別出來的值是”+result);
} else {
if(Integer.parseInt(asrRes.get(“err_no”).toString())==3300) {
System.out.println(“輸入參數不正確”);
} else if(Integer.parseInt(asrRes.get(“err_no”).toString())==3301) {
System.out.println(“音頻質量過差”);
}else if(Integer.parseInt(asrRes.get(“err_no”).toString())==3308) {
System.out.println(“音頻過長”);
}else if(Integer.parseInt(asrRes.get(“err_no”).toString())==3310) {
System.out.println(“音頻文件過大”);
} else {
System.out.println(“語音識別失敗!”);
}
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章