Question

I am trying to play the mic sound in realtime using soundeffect and audiosink in silverlight 5 but the sound gets chopped up here is the code I used

protected override void OnSamples(long sampleTime, long sampleDuration, byte[] sampleData)
{
  try
  {
    SoundEffect effect = new SoundEffect(sampleData, 8000, AudioChannels.Mono);
    effect.Play();
   }
   catch
   { }
 }

Any help or alternatives?

Was it helpful?

Solution

I'm pretty sure that this isn't the scenario that the SoundEffect class is meant for. To play a consistent stream of audio, you need at least some sort of buffering and consistency between the various frames. What I've done in the past to make this sort of thing work is to buffer the audio coming in from the AudioSink briefly, and then make it available to a MediaStreamSource, which in turn plays it. There are good basic implementations of a MediaStreamSource lots of places that you can borrow (the weird part is getting all the WAV headers right), but you'll still need to write the buffering code yourself. The simplest way would be to use a queue to hold each submitted byte array, and then just have the MediaStreamSource pull the byte arrays in its GetSampleAsync() method.

Start here: http://dotnet.dzone.com/news/creating-sound-using

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top