C#C
C#16mo ago
hutonahill

✅ Windows Audio Capture

Building an XAML application. The eventual goal is to capture an audio source and stream it to another application using webhooks.

This is my first time doing:
1) XAML
2) Audio anything
3) Webhooks

i detect audio sources with this method:

private void PopulateMicrophones() {
    List<String> waveInDevices = Enumerable.Range(0, WaveIn.DeviceCount)
        .Select(i => WaveIn.GetCapabilities(i).ProductName)
        .ToList();
    
    waveInDevices.Insert(0, "Select Mic");

    MicrophoneDropdown.ItemsSource = waveInDevices;
    if (waveInDevices.Count > 0)
    {
        MicrophoneDropdown.SelectedIndex = 0; // Set the first microphone as default selected
    }
}


Then i use these methods to start and stop recording
private void StartMicrophoneCapture(int deviceNumber) {
    waveIn?.StopRecording();
    waveIn?.Dispose(); // Dispose of the old instance if necessary

    waveIn = new WaveInEvent { DeviceNumber = deviceNumber };

    // Add logging for debugging
    Console.WriteLine($"Starting microphone capture on device {deviceNumber}: {WaveIn.GetCapabilities(deviceNumber).ProductName}");

    waveIn.DataAvailable += OnDataAvailable;
    waveIn.StartRecording();
}

private void StopMicrophoneCapture()
{
    waveIn?.StopRecording();
    waveIn?.Dispose();
    waveIn = null;
    currentVolume = 0; // Reset volume
    VolumeBar.Width = 1; // Reset volume bar width
    VolumeBar.Fill = new SolidColorBrush(Colors.Gray); // Set to neutral color
}


I added a volume bar so i could see the audio being captured and the audio bar gets set to 0 when i pick an audio source (its one if the mic is null). I think this means i am not capturing audio. but i don't actually know.

How do i even debug this?
Was this page helpful?