我一直致力于Silverlight语音聊天应用程序,使用speex(基本上是C#移植的Jspeex)进行编码和解码。我想实现以下内容:
以下是我到目前为止实施的代码:
/ ********编码************* ********************* /
JSpeexEnc encoder = new JSpeexEnc();
public byte[] SpeexEncoding(byte[] InputBuffer)
{
MemoryStream msIn = new MemoryStream(InputBuffer);
MemoryStream msOut = new MemoryStream();
encoder.EncodeToSpeex(new RandomInputStream(msIn), new RandomOutputStream(msOut));
return msOut.GetBuffer();
}
void SendVoiceBuffer(object VoiceBuffer, EventArgs e)
{
byte[] PCM_Buffer = (byte[])VoiceBuffer;
if (PCM_Buffer.Length >= 8000)
{
byte[] buffer = SpeexEncoding(PCM_Buffer);
Send_Bytes(buffer);
//this.Dispatcher.BeginInvoke(new ShowMessagedelegate(ShowBufferSize), buffer.Length.ToString());
}
}
/ ********************************************解码************** ******** /
private void PlayReceivedBuffer(byte[] Encodedbuffer)
{
// if (MuteCheckBox.IsChecked == false)
try
{
JSpeexDec decoder = new JSpeexDec();
decoder.setDestFormat(JSpeexDec.FILE_FORMAT_RAW);
decoder.setStereo(true);
MemoryStream InStream = new MemoryStream(Encodedbuffer);
MemoryStream OutStream = new MemoryStream();
decoder.decode(new RandomInputStream(InStream), new RandomOutputStream(OutStream));
PlayWave(OutStream.GetBuffer());
}
catch (Exception) { }
StartReceiving();
}
void PlayWave(byte[] PCMBytes)
{
MemoryStream ms_PCM = new MemoryStream(PCMBytes,44,PCMBytes.Length-44);
MemoryStream ms_Wave = new MemoryStream();
_pcm.SavePcmToWav(ms_PCM, ms_Wave, 16, 8000, 1);
WaveMediaStreamSource WaveStream = new WaveMediaStreamSource(ms_Wave);
mediaElement1.SetSource(WaveStream);
mediaElement1.Play();
}
我一直在调整speex编码和解码类,以获得最佳的语音质量而没有运气。并且一直在搜索speex类中我可以访问和实现的任何AEC,这里也没有运气,但是speex文档提到了C ++中的AEC,但不清楚如何在C#中实现。
我是C#开发的新手,请指导,如果可能的话,请指出一个方向,这将有助于我实施此AEC并提高语音质量。我感谢任何指导。
谢谢!