国产精品久久久久久久久久东京,亚洲视频免费播放,少妇人妻精品一区二区三区视频,日韩一级品

好房網(wǎng)

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

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

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

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

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

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 測試類:

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

還是非常簡單哦。

將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)過上面代碼,我們就可以支持常用的音頻格式進(jìn)行ASR識別引擎的測試!


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


標(biāo)簽:

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