赞
踩
在小程序上实现语音的识别
- public static boolean convertMP32Pcm(String mp3filepath, String pcmfilepath) {
- try {
- // 获取文件的音频流,pcm的格式
- AudioInputStream audioInputStream = getPcmAudioInputStream(mp3filepath);
- // 将音频转化为 pcm的格式保存下来
- AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, new File(pcmfilepath));
- return true;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- }
-
- protected static AudioInputStream getPcmAudioInputStream(String mp3filepath) {
- File mp3 = new File(mp3filepath);
- AudioInputStream audioInputStream = null;
- AudioFormat targetFormat = null;
- try {
- AudioInputStream in = null;
- MpegAudioFileReader mp = new MpegAudioFileReader();
- in = mp.getAudioInputStream(mp3);
- AudioFormat baseFormat = in.getFormat();
- targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
- baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
-
- audioInputStream = AudioSystem.getAudioInputStream(targetFormat, in);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return audioInputStream;
- }
讯飞识别调用请看讯飞开发文档
地址:https://doc.xfyun.cn/rest_api/%E8%AF%AD%E9%9F%B3%E5%90%AC%E5%86%99.html
同理百度也是一样
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。