資源簡介
vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼vox轉wav的java代碼
代碼片段和文件信息
?
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileOutputStream;
import?it.sauronsoftware.jave.AudioAttributes;
import?it.sauronsoftware.jave.Encoder;
import?it.sauronsoftware.jave.EncodingAttributes;
/**
?*?Vox轉wav工具類
?*/
public?class?VoxConvert?{
????private?static?int?convertFormat?=?1;
????public?static?int?convertRate?=?6000;
????private?static?int?convertBits?=?4;
????private?static?final?int?WAV_HEAD?=?36;//?wav文件頭長度
????public?static?final?int?VF_ADPCM?=?3;//?編碼格式
????public?static?final?int?BIT_RATE_VB_8?=?1;//?每個樣本位數
????private?static?final?int?BIT_RATE_VB_16?=?2;//?每個樣本位數
????private?static?final?int?RESET_VALUE?=?24;
????private?static?byte?out_val;
????private?VoxConvert()?{
????}
????/**
?????*?將Vox音頻文件格式轉為Wav格式
?????*
?????*?@param?inFile?源文件vox
?????*?@param?outFile?輸出文件?wav
?????*?@param?voxFormat
?????*????????????格式?取值范圍:VF_ADPCM?=?1?VF_MULAW?=?2?VF_ALAW?=?3
?????*?@param?voxRate
?????*????????????采樣率?取值范圍:VR_6K?=?6000?VR_8K?=?8000
?????*?@param?bit_rate
?????*????????????位數?取值范圍:VB_8?=?1?VB_16?=?2
?????*?@return
?????*/
????public?static?boolean?Vox2Wav(String?inFile?String?outFile?int?voxFormat
??????????????????????int?voxRate?int?bit_rate)?throws?Exception?{
????????if?(voxFormat?!=?0)?{
????????????convertFormat?=?voxFormat;
????????}
????????if?(voxRate?!=?0)?{
????????????convertRate?=?voxRate;
????????}
????????if?(bit_rate?!=?0)?{
????????????convertBits?=?bit_rate;
????????}
????????if?(outFile?==?null)?{
????????????outFile?=?inFile.substring(0?inFile.length()?-?3);
????????????outFile?=?outFile?+?“wav“;
????????}
????????File?outF?=?new?File(outFile);
????????File?inF?=?new?File(inFile);
????????long?inFileSize?=?inF.length();
????????if?(voxFormat?==?VF_ADPCM)?{?//?if?using?ADPCM?input?format...
????????????inFileSize?=?inFileSize?*?2;
????????}//?change?from?bytes?to?samples
????????FileOutputStream?filewriter?=?new?FileOutputStream(outF?false);
????????String?wavBegin?=?“RIFF“;
????????filewriter.write(wavBegin.getBytes());//?WAV?文件頭
????????long?wavLength?=?inFileSize?*?bit_rate?+?WAV_HEAD;
????????byte[]?tmpArr?=?new?byte[4];
????????longToIntBinary(wavLength?tmpArr?0);
????????filewriter.write(tmpArr);//?文件總長度
????????String?wavTag?=?“WAVEfmt?“;
????????filewriter.write(wavTag.getBytes());//?WAV?文件標識
????????int?headLength?=?16;
????????tmpArr?=?new?byte[4];
????????longToIntBinary(headLength?tmpArr?0);
????????filewriter.write(tmpArr);//?size?of?.WAV?file?header
????????int?wFormatTag?=?1;?//?format?tag?(01?=?Windows?PCM)
????????tmpArr?=?new?byte[2];
????????toShortBinary(wFormatTag?tmpArr?0);
????????filewriter.write(tmpArr);//?format?tag?(01?=?Windows?PCM)
????????int?nChannels?=?1;?//?channels?(1=mono?2=stereo)
????????tmpArr?=?new?byte[2];
????????toShortBinary(nChannels?tmpArr?0);
????????filewriter.write(tmpArr);//?channels?(1=mono?2=stereo)
- 上一篇:操作系統文件管理課程設計JAVA版
- 下一篇:java通過socket編寫小型聊天室
評論
共有 條評論