0

I made a windows form application that listens from the microphone and detects sound patrons.

Now i want to do the same but in a service.

I use Naudio and this event:

myWave = new WaveIn();
...
myWave.DataAvailable += new EventHandler<WaveInEventArgs>(myWave_DataAvailable);

At windows form works fine, but the service don't fires the event.

Does anyone know why?

Another question is

Will my service hear the microphone even when not logged in?

Thanks!

Edited with new information and using WaveInEvent class:

I declare the variable in the class

public partial class SoundDetector : ServiceBase {
    ... 
    private WaveInEvent myWave;

Set the event in the constructor

public SoundDetector()
{
    myWave.DataAvailable += myWave_DataAvailable;

And start recordig in the OnStart

protected override void OnStart(string[] args)
{
    myWave.StartRecording();

But the event still stop firing...

  • 3
    Never seen NAudio before, but a quick look at the source seems to indicate that it's using window messages - that's not going to work well since the service won't have a message loop running. – Damien_The_Unbeliever Oct 19 '12 at 10:04
  • Are you talking about a Windows Service, right? – giacomelli Oct 19 '12 at 12:22
  • Yes, a Windows Service. I'm trying to find another way to handle the events from wavein with using (WaveIn myWave = new WaveIn(WaveCallbackInfo.FunctionCallback())) { } Now the event fires three times but then stops... – Ingeniería Tecnova Atnova Oct 19 '12 at 14:11
  • I updated the naudio library to the 1.5.10 version, and now i use WaveInEvent instead of WaveIn, but the event only fires a couple of times and then... nothing. – Ingeniería Tecnova Atnova Oct 19 '12 at 15:27
  • 1
    When something works for a short while and then stops, I usually find it's because something that you should be keeping a long term reference to has only been stored in a local variable, and then the garbage collector has come along and finalized it, wiping it out. Could that be the case here? (The storage may be direct or transitive - e.g. you might be storing the reference into a field of a class, but then not keeping any reference to the class instance stored) – Damien_The_Unbeliever Oct 22 '12 at 06:24
  • @Damien_The_Unbeliever, I edited my question with some code. I'm, unable to find my mistake... – Ingeniería Tecnova Atnova Oct 22 '12 at 08:55

1 Answers1

0

Use the WaveInEvent class instead

Mark Heath
  • 48,273
  • 29
  • 137
  • 194