1

正如主题所述,我在 Windows Phone 7 中使用 NSpeex(v1.1.1,使用 Speex v1.2rc1)编码音频没有问题。我已经通过首先对流进行编码来验证这一点,然后在再次解码后立即添加 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)
4

0 回答 0