C
C#3mo ago
hutoanhill

✅ 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
}
}
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
}
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?
1 Reply
hutoanhill
hutoanhill3mo ago
found the issue. it was my volume bar, I was using volumebar.actualWidth to calculate the full width of the bar, but that value changes when the volume changes. so when i do math to fill it a percentage, it jumps to 0 in like 3 steps
Want results from more Discord servers?
Add your server