Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate/open microphone at init/system startup #1180

Open
jessp01 opened this issue Sep 1, 2024 · 0 comments
Open

Activate/open microphone at init/system startup #1180

jessp01 opened this issue Sep 1, 2024 · 0 comments

Comments

@jessp01
Copy link

jessp01 commented Sep 1, 2024

Hello all,

First of all, great job on this project.

I'm using the below code (based on NAudioDemo/RecordingDemo/RecordingPanel.cs) to record the mic's output:

            var deviceEnum = new MMDeviceEnumerator();
            var waveInDevices = Enumerable.Range(-1, WaveIn.DeviceCount + 1).Select(n => WaveIn.GetCapabilities(n)).ToArray();
            var devices = deviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToList();
            var device = (MMDevice)devices[index];
            device.AudioEndpointVolume.Mute = false;

            captureDevice = new WaveInEvent() { DeviceNumber = 0 };
            captureDevice.WaveFormat = new WaveFormat(44100, 1);
            captureDevice.DataAvailable += OnDataAvailable;
            captureDevice.RecordingStopped += OnRecordingStopped;
            writer = new WaveFileWriter(Path.Combine(outputDir, outputFilename), captureDevice.WaveFormat);
            captureDevice.StartRecording();

This microphone in question is Microphone Array (Realtek Audio) which is a built in mic.

This runs in the context of a Windows service (class inherits fromServiceBase) and works correctly when a user is logged in or when Windows performs a session preload. However, I need it to work even when that's not the case. Basically, I'd like to activate the microphone as soon as possible, regardless of whether or not an active user session is available.
As it stands now, the file is created but no audio comes in until after a user session is established (so, n seconds of quiet and then audio once the session is active).

I'm aware of the Session 0 isolation cocept and I know I cannot "interact with the desktop" from a service (running in session 0) but all I need is to activate the microphone. I am able to activate the camera and start recording from the service using FFmpeg (-f dshow -i video="{camId}") under these conditions so, it seems reasonable to me that I should be able to activate the microphone as well.

I'd appreciate any assistance or insights.

Thanks in advance,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant