html52.com
我爱小程序-开发者交流社区

小程序的录音文件格式(wav和MP3)和标准的格式是不一样吗?上传到后端保存下来打不开,显示0:00

请问小程序录音现在支持WAV了是吗(文档里有说明了),但是我将录音(MP3和WAV都试过)上传到后端之后,保存在本地用播放器打不开,时间显示0:00,但是在浏览器里能够打开,请问小程序的音频格式和标准的格式是不是不一样呢,这个如何解决呢,谢谢。

小程序代码(部分)

//上传录音
  upload:function(){
    wx.uploadFile({
      url"http://localhost:8080/voice/upload",//演示域名、自行配置
      filePath: this.tempFilePath,
      name'file',
      header: {
        "Content-Type""multipart/form-data"
      },


//开始录音的时候
  startfunction () {
    const options = {
      duration10000,//指定录音的时长,单位 ms
      sampleRate16000,//采样率
      numberOfChannels1,//录音通道数
      encodeBitRate96000,//编码码率
      format'mp3',//音频格式,有效值 aac/mp3
      frameSize50,//指定帧大小,单位 KB
    }
    //开始录音
    recorderManager.start(options);
    recorderManager.onStart(() => {
      console.log('recorder start')
    });


后端代码:

public String upload(HttpServletRequest request, @RequestParam("file")MultipartFile[] files){
    LOGGER.info("上传测试");
    //多文件上传
    if(files!=null && files.length>=1) {
        BufferedOutputStream bw = null;
        try {
            String fileName = files[0].getOriginalFilename();
            //判断是否有文件(实际生产中要判断是否是音频文件)
            if(StringUtils.isNoneBlank(fileName)) {
                //创建输出文件对象
                File outFile = new File(uploadPath + UUID.randomUUID().toString()+ FileUtil.getFileType(fileName));
                //拷贝文件到输出文件对象
                FileUtils.copyInputStreamToFile(files[0].getInputStream(), outFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(bw!=null) {bw.close();}
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return "success";
}


希望能得到回复,谢谢。

网友回复

؞咬了你؞F࿆ū࿆t࿆ū࿆r࿆ē࿆:

你是不是在开发者工具里上存的?

你是不是在开发者工具里上存的?顺便吐槽一下,既然有logger,为什么catch异常要e.printStackTrace(),这样不好。。。

顺便吐槽一下,既然有logger,为什么catch异常要e.printStackTrace(),这样不好。。。


评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付