Recently, the project used to read audio in amr format , but h5 does not support this format, and the foreground processing is not very good at it, and it feels too troublesome, so it is better to convert the format at the backend.
Use a jar: jave.jar
URL: https://www.sauronsoftware.it/projects/jave/download.php
The demo code is also relatively simple, just pass in the path of the amr audio file to be converted and the path of the newly generated mp3 file.
import it.sauronsoftware.jave.*;
import java.io.File;
/**
* Created by xhzhang on 2018/10/23.
*/
public class demo {
public static void main(String[] args) throws Exception {
String sourcePath = "D:/MediaRoot/123.amr";
String targetPath = "D:/MediaRoot/123.mp3";
changeToMp3(sourcePath, targetPath);
}
public static void changeToMp3(String sourcePath, String targetPath) {
File source = new File(sourcePath);
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
Encoder encoder = new Encoder();
audio.setCodec("libmp3lame");
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
try {
encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InputFormatException e) {
e.printStackTrace();
} catch (EncoderException e) {
e.printStackTrace();
}
}
}
See this if the linux server conversion fails