正如主题所述,我在使用NSpeex(v1.1.1,使用Speex v1.2rc1)的Windows Phone 7中编码音频时没有任何问题。我已经通过首先对流进行编码来验证这一点,然后在将其再次解码之后,添加wav标头并将其发送回服务器,wav正常播放。但是,如果我将编码流发送到服务器并尝试使用JSpeex(v0.9.7,使用Speex v1.0.3)对其进行解码,我只会通过解码设置获得不同类型的StreamCorruptedExceptions。
我是否在这里遇到版本不可用,或者我只是做了一些错误的事情?如果有人对此配置有任何了解,我将感谢任何帮助。我现在使用的代码:
电话方:
SpeexEncoder encoder = new SpeexEncoder(BandMode.Wide);
// set encoding quality to lowest (which will generate the smallest size in the fastest time)
encoder.Quality = 1;
int inDataSize = _recordedBytes / 2; //_recordedBytes is the lenght of the _recordedBuffer(which is a byte array)
// convert to short array
short[] data = new short[inDataSize];
int sampleIndex = 0;
for (int index = 0; index < _recordedBytes; index += 2, sampleIndex++)
{
data[sampleIndex] = BitConverter.ToInt16(_recordedBuffer, index);
}
// note: the number of samples per frame must be a multiple of encoder.FrameSize
inDataSize = inDataSize - inDataSize % encoder.FrameSize; //framesize is 320
var encodedData = new byte[_recordedBytes];
int encodedBytes = encoder.Encode(data, 0, inDataSize, encodedData, 0, _recordedBytes);
if (encodedBytes != 0)
{
byte[] inDataSizeBuf = BitConverter.GetBytes(inDataSize);
byte[] sizeBuf = BitConverter.GetBytes(encodedBytes + inDataSizeBuf.Length);
byte[] returnBuf = new byte[encodedBytes + sizeBuf.Length + inDataSizeBuf.Length];
sizeBuf.CopyTo(returnBuf, 0);
inDataSizeBuf.CopyTo(returnBuf, sizeBuf.Length);
Array.Copy(encodedData, 0, returnBuf, sizeBuf.Length + inDataSizeBuf.Length, encodedBytes);
}
服务器端:
SpeexDecoder speexDecoder = new SpeexDecoder();
if(speexDecoder.init(1, 16000, 1, true)) { //params: mode(1 = wide), sample rate, channels, enhancement(what ever that is)
speexDecoder.processData(encodedSpeex, 0, 320); //params: encoded byte array, offset, frame size
byte[] decoded = new byte[speexDecoder.getProcessedDataByteSize()];
speexDecoder.getProcessedData(decoded, 0);
}
错误,在processData()中发生(使用代码中使用的当前设置):
java.io.StreamCorruptedException: Invalid sideband mode encountered. (2nd sideband): 6
at org.xiph.speex.NbDecoder.decode(Unknown Source)
at org.xiph.speex.SbDecoder.decode(Unknown Source)
at org.xiph.speex.SpeexDecoder.processData(Unknown Source)
at org.xiph.speex.SpeexDecoder.processData(Unknown Source)
at mun.testi.SpeexTesti.main(SpeexTesti.java:35)