百度AI---语音识别

题记:娱乐性的玩玩百度接口。

说实话,其接口个人觉得有点烂,重试了好几个音频文件才成功。

1、重新申请AppID、SecretKey 、API Key。

链接:https://console.bce.baidu.com/ai/?fromai=1#/ai/speech/overview/index

 

2、百度的案例代码

   /**
     * 语音识别
     */
    public static void voiceRecongnize(){
        AipSpeech client = new AipSpeech(BaiduConfig.VOICE_APP_ID, BaiduConfig.VOICE_API_KEY, BaiduConfig.VOICE_SECRET_KEY);//这个要自己写哦
        String path = "C:\\Users\\yangwj\\Desktop\\temp.wav";
        try{
        JSONObject asrRes = client.asr(path, "wav", 16000, null);
        System.out.println(asrRes);

        // 对语音二进制数据进行识别
        byte[] data = Util.readFileByBytes(path);     //readFileByBytes仅为获取二进制数据示例
        JSONObject asrRes2 = client.asr(data, "pcm", 16000, null);
        System.out.println(asrRes2);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

这样就可以调用运行了。

posted @ 2018-12-10 22:07  小白啊小白,Fighting  阅读(1377)  评论(0编辑  收藏  举报