初步技术方案是:小程序录音-上传录音文件到后端服务器,后端服务器调用阿里云一句话语音识别接口获取识别结果并返回给小程序。
小程序的录音文件格式只能是MP3或者AAC,而阿里云语音接口所能接受的音频文件格式为PCM,WAV,最后决定在后端将接收的MP3文件转换成PCM文件。
错误1 could not get audio input stream from input stream
出现这个错误的原因是没有引入MP3解析库
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>1.9.5-1</version>
</dependency>
引入过后,发现错误1解决了,出现了下面的错误2
错误2 java.lang.IllegalArgumentException: Unsupported conversion: PCM_SIGNED from MPEG1L3 44100.0 Hz, unknown bits per sample, stereo, unknown frame size, 38.28125 frames/second
网上找到有说是进行格式转换的源码有问题,有很多参数都没有设置,所有才会报这个错误
更改前的源码(错误源码)
public byte[] mp3Convertpcm(InputStream mp3Stream) throws Exception {
// 原MP3文件转AudioInputStream
Aud