百度语音识别 有MP3转pcm的方法吗
骑酷科技 发布于2019-01-14 15:54 浏览:234 回复:3
1
收藏

百度语音识别 有MP3转pcm的方法吗

收藏
点赞
1
个赞
共3条回复 最后由俩_异面直线回复于2019-01-26 19:27
#4俩_异面直线回复于2019-01-26 19:27:43
#3 131******31回复
1、引入jar包 [代码]   2、代码 [代码]

有iOS wav转pcm的库吗?w(゚Д゚)w

0
#3131******31回复于2019-01-23 17:21:19

1、引入jar包

		<dependency>
			<groupId>com.googlecode.soundlibs</groupId>
			<artifactId>mp3spi</artifactId>
			<version>1.9.5.4</version>
		</dependency>

 

2、代码

    /**
     * MP3转换PCM
     * @param inputStream MP3输入流
     * @throws Exception
     */
    public static byte[] mp3Convert2pcm(InputStream inputStream) throws Exception {
    	//转换PCM audioInputStream 数据
        AudioInputStream audioInputStream = getPcmAudioInputStream(inputStream);
        byte[] pcmBytes = IOUtils.toByteArray(audioInputStream);
        return pcmBytes;
    }
    
    /**
     * 获取PCM AudioInputStream 数据
     * @param inputStream MP3输入流
     * @return AudioInputStream PCM输入流
     */
    private static AudioInputStream getPcmAudioInputStream(InputStream inputStream) {
        AudioInputStream audioInputStream = null;
        AudioFormat targetFormat = null;
        try {
            AudioInputStream in = null;
            MpegAudioFileReader mp = new MpegAudioFileReader();
            in = mp.getAudioInputStream(inputStream);
            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;
    }
0
#2a8461959回复于2019-01-22 11:20:53

我也需要啊,楼主找到了么

0
TOP
切换版块