GithubHelp home page GithubHelp logo

jave's Introduction

记录解决微信amr文件转mp3格式的过程

我们在做微信语音上传功能开发时,因为微信的原因,音频文件在微信服务端只能存储3天,所以,我们需要根据微信的serverId,使用微信公众平台的接口将音频文件下载下来,存储到我们本地的服务器

由于微信的音频文件格式是amr格式,该格式在HTML5页面是不支持播放的,此时,我们需要将amr格式装换为mp3格式

利用jave的工具包可以实现次目的,由于jave并未上传**仓库,官网下载地址:http://www.sauronsoftware.it/projects/jave/download.php

此次使用jave的工具包主要碰到两个问题:

抛异常 it.sauronsoftware.jave.EncoderException: Duration: N/A, bitrate: N/A

抛异常it.sauronsoftware.jave.EncoderException: Stream mapping:

使用搜索帮助,主要发现两篇有价值的博文:

结合以上两篇博客的解决方案,主要做如下步骤:

1.下载jave的最新src代码(该库09年已停止维护),导入maven工程

2.下载最新的ffmpeg程序,ffmpeg下载地址,替换jave中默认的ffmpeg程序

3.重新打包,mavn install

最终控制台调试 打印log如下:

Java代码使用示例:

TemplateDownloadMaterial tm=weixinService.downloadTempMaterial(media,file.getAbsolutePath());
if (tm!=null&&tm.getFile()!=null){
	//判断是否是amr格式
    //tm.getFile 文件为微信下载下来的amr格式文件
	if (tm.getFile().getName().endsWith("amr")){
		String fileName=tm.getFile().getName();
		String newName=fileName.substring(0,fileName.lastIndexOf("."));
		File dest=new File(tm.getFile().getParent()+File.separator+newName+".mp3");
		AudioUtils.getAmrConversionMp3(tm.getFile().getAbsolutePath(),dest.getAbsolutePath());
		log("转换音频mp3成功");
		tm.getFile().deleteOnExit();
		tm.setFile(dest);
	}
}

修改后的jave源码地址:https://github.com/xiaoymin/jave

下载后 ,mvn install后可以执行使用

jave's People

Contributors

xiaoymin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.