资源简介
JAVA VOX转WAR转换器
代码片段和文件信息
package com.lakala.callcenter.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class VoxConvert {
private int convertFormat = 1;
private int convertRate = 8000;
private int convertBits = 1;
private final int WAV_HEAD = 36;// wav文件头长度
private static final int VF_ADPCM = 1;// 编码格式
private static final int BIT_RATE_VB_8 = 1;// 每个样本位数
private static final int BIT_RATE_VB_16 = 2;// 每个样本位数
private final int RESET_VALUE = 48;
private byte out_val;
/**
*
* @param inFile
* @param outFile
* @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 VoxConvert(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)
int nSamplesPerSec = voxRate; // samples per second
tmpArr = new byte[4];
longToIntBinary(nSamplesPerSec tmpArr 0);
filewriter.write(tmpArr);
int nAvgBytesPerSec = voxRate * bit_rate; // bytes per second
// during play
tmpArr = new byte[4];
longToIntBinary(nAvg
- 上一篇:Java安全通信
- 下一篇:tcnative-1.dll
评论
共有 条评论