npm install convert-audio
import AudioConverter from 'convert-audio'
AudioConverter.convert(sourceAudioFile, targetAudioFormat);
<input type='file' accept=".mp3, .wav, .aac" onchange="convertAudio(this)" />
import AudioConverter from 'convert-audio'
async function convertAudio(input) {
let sourceAudioFile = input.files[0];
let targetAudioFormat = 'wav'
let convertedAudioDataObj = await AudioConverter.convert(sourceAudioFile, targetAudioFormat);
}
This convert function will return a converted audio data object which includes audio name, format and blob URL.
function downloadAudio(convertedAudioDataObj) {
let a = document.createElement("a");
a.href = convertedAudioDataObj.data;
a.download = convertedAudioDataObj.name + "." + convertedAudioDataObj.format;
a.click();
}
MIT