大香蕉综合在线观看视频-日本在线观看免费福利-欧美激情一级欧美精品性-综合激情丁香久久狠狠

好房網(wǎng)

網(wǎng)站首頁(yè)百科全書(shū) >正文

如何將mp3轉(zhuǎn)換成wav(將mp3格式的音頻轉(zhuǎn)換為采樣率8k的wav)

2022-06-11 03:05:21 百科全書(shū)來(lái)源:
導(dǎo)讀目前大家應(yīng)該是對(duì)如何將mp3轉(zhuǎn)換成wav(將mp3格式的音頻轉(zhuǎn)換為采樣率8k的wav)比較感興趣的,所以今天好房網(wǎng)小編CC就來(lái)為大家整理了一些關(guān)于...
目前大家應(yīng)該是對(duì)如何將mp3轉(zhuǎn)換成wav(將mp3格式的音頻轉(zhuǎn)換為采樣率8k的wav)比較感興趣的,所以今天好房網(wǎng)小編CC就來(lái)為大家整理了一些關(guān)于如何將mp3轉(zhuǎn)換成wav(將mp3格式的音頻轉(zhuǎn)換為采樣率8k的wav)方面的相關(guān)知識(shí)來(lái)分享給大家,希望大家會(huì)喜歡哦。

如何將mp3轉(zhuǎn)換成wav(將mp3格式的音頻轉(zhuǎn)換為采樣率8k的wav)

最近系統(tǒng)上需要增加一個(gè)功能,就是測(cè)試我們系統(tǒng)的ASR識(shí)別引擎,這就需要上傳一段音頻,然后我們返回識(shí)別后的文字,但是我們的識(shí)別引擎需要采樣率16k,格式為wav的音頻文件,但是我們又不能限定用戶上傳的錄音格式,所以需要我們?cè)诤笈_(tái)轉(zhuǎn)換一下格式,然后再去識(shí)別。

MP3轉(zhuǎn)換wav

做這個(gè)功能時(shí)候, 發(fā)現(xiàn)網(wǎng)上的資料真的很少,所以,只能安全上網(wǎng)了,在外面找到了方法。

1 引入jar:

<dependency><groupId>javazoom</groupId><artifactId>jlayer</artifactId><version>0.1</version></dependency>

2 工具類代碼:

publicbooleantoWav(StringinputFilePath,StringoutputFilePath){ConverteraConverter=newConverter();try{aConverter.convert(inputFilePath,outputFilePath);}catch(JavaLayerExceptione){e.printStackTrace();returnfalse;}returntrue;}

3 測(cè)試類:

publicstaticvoidmain(Stringargs[]){StringfilePath="C:\\data\\hellowordread.pcm";StringtargetPath="C:\\data\\11133wav";toWav(filePath,targetPath);}

還是非常簡(jiǎn)單哦。

將wav轉(zhuǎn)換為8k采樣率
publicvoidtoStandardWav(StringinputFilePath,StringoutputFilePath){try{byte[]bytes=Files.readAllBytes(newFile(inputFilePath).toPath());WaveFileReaderreader=newWaveFileReader();AudioInputStreamaudioIn=reader.getAudioInputStream(newByteArrayInputStream(bytes));AudioFormatsrcFormat=audioIn.getFormat();inttargetSampleRate=8000;AudioFormatdstFormat=newAudioFormat(srcFormat.getEncoding(),targetSampleRate,srcFormat.getSampleSizeInBits(),srcFormat.getChannels(),srcFormat.getFrameSize(),srcFormat.getFrameRate(),srcFormat.isBigEndian());System.out.println(audioIn.getFrameLength());AudioInputStreamconvertedIn=AudioSystem.getAudioInputStream(dstFormat,audioIn);Filefile=newFile(outputFilePath);WaveFileWriterwriter=newWaveFileWriter();writer.write(convertedIn,AudioFileFormat.Type.WAVE,file);}catch(Exceptione){e.printStackTrace();}}

總結(jié)

經(jīng)過(guò)上面代碼,我們就可以支持常用的音頻格式進(jìn)行ASR識(shí)別引擎的測(cè)試!


版權(quán)說(shuō)明:本文由用戶上傳,如有侵權(quán)請(qǐng)聯(lián)系刪除!


標(biāo)簽:

熱點(diǎn)推薦
熱評(píng)文章
隨機(jī)文章