string ParamList;
WaveOut _waveOut = new WaveOut();
//WaveFileReader reader;
try
{
ParamList = "http://X.X.X.X/axis-cgi/audio/receive.cgi";
NetworkCredential networkCredential = new NetworkCredential("user", "pass");
WebRequest request = WebRequest.Create(ParamList);
request.Credentials = networkCredential;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamResponse = response.GetResponseStream();
MemoryStream ms = new MemoryStream();
SoundPlayer y = new SoundPlayer(ms);
IWaveProvider reader = new RawSourceWaveStream(
streamResponse, new WaveFormat());
_waveOut.Init(reader);
_waveOut.Play();
}
catch (Exception es)
{
MessageBox.Show(es.ToString(), "\nError Message");
}
This is my code and I get the audio without any problem, but the audio is encoded with uLaw and as you know for that reason it is not understandable. I need to be able to convert streamResponse
it into a byte array to be able to decode it, but the problem is that I am Streaming the audio in real time from the IP camera and therefore I cannot do one streamResponse.CopyTo(memoryStream)
because the program will be reading infinitely because the API will never stop send audio. If there is some way that I can convert to bytes streamResponse
in real time it would be my salvation.
You can do the reading in a byte array directly like this:
In the example, the buffer size is 32K but you may have to adjust it to a size according to your requirement.
Note that it
streamResponse.Read(...
returns the number of bytes read and this value can be less than the size of the buffer.In other order of ideas, remember to invoke the method
Dispose()
of all the classes that implement the interfaceIDisposable
(like the objectsStream
) see more