问题
How can I decode GSM 6.10 (Full-Rate) codec audio byte array on the fly in NAudio? Sources says that wave decoding is processed at one time and I can't process several bytes of wave (fix me if I'm wrong).
My situation is that I receive bytes array of GSM 6.10 audio from the server, array size can be specified, but how can i decode it and write to the device?
Edit:
What am I doing wrong? According to Mark's solution this should work but all I hear is distorted sounds:
WaveOut waveO = new WaveOut();
BufferedWaveProvider waveP = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));
waveO.Init(waveP);
waveO.Play();
INetworkChatCodec cod = new Gsm610ChatCodec();
new Thread(delegate()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.nch.com.au/acm/8kgsm.wav");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream resStream = response.GetResponseStream())
{
if (resStream.CanRead)
{
byte[] buf = new byte[65];
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
byte[] decoded = cod.Decode(buf, 0, count);
waveP.AddSamples(decoded, 0, decoded.Length);
Thread.Sleep(50);
}
}
while (count > 0);
}
}
}).Start();
回答1:
You can do this with the AcmStream
class, passing in Gsm610WaveFormat
as the source format and 8kHz 16 bit mono as the output format. The network chat demo in the NAudio source code shows this in action to decode on the fly.
来源:https://stackoverflow.com/questions/22435784/decoding-gsm-6-10-parts-in-naudio