fix: recover from microphone disconnects
PR and Push Build/Test / build-and-test (push) Successful in 12m29s

This commit is contained in:
2026-08-03 15:57:30 +02:00
parent 75250f6041
commit b9547ae4c4
16 changed files with 574 additions and 40 deletions
@@ -3,7 +3,7 @@ using NAudio.Wave;
namespace MeetingAssistant.Recording;
public sealed class WindowsMicrophoneDeviceProvider : IMicrophoneDeviceProvider
public sealed class WindowsMicrophoneDeviceProvider : IMicrophoneDeviceProvider, IMicrophoneCaptureSourceFactory
{
private readonly MicrophoneDeviceSelection selection;
private readonly ILogger<WindowsMicrophoneDeviceProvider> logger;
@@ -42,21 +42,38 @@ public sealed class WindowsMicrophoneDeviceProvider : IMicrophoneDeviceProvider
selection.Resolve(options.Recording.MicrophoneDeviceId, GetDefaultMicrophone(), devices));
}
public IWaveIn CreateCapture(MeetingAssistantOptions options)
public IMeetingAudioSource CreateCapture(MeetingAssistantOptions options)
{
var current = GetMicrophoneSnapshot(options).Current;
IWaveIn capture;
if (current is null)
{
logger.LogInformation("Starting microphone capture from Windows default capture endpoint");
return new WasapiCapture();
capture = new WasapiCapture();
}
else
{
logger.LogInformation(
"Starting microphone capture from {MicrophoneName} ({MicrophoneDeviceId})",
current.Name,
current.Id);
using var enumerator = new MMDeviceEnumerator();
capture = new WasapiCapture(enumerator.GetDevice(current.Id));
}
logger.LogInformation(
"Starting microphone capture from {MicrophoneName} ({MicrophoneDeviceId})",
current.Name,
current.Id);
using var enumerator = new MMDeviceEnumerator();
return new WasapiCapture(enumerator.GetDevice(current.Id));
try
{
capture.WaveFormat = new WaveFormat(
options.Recording.SampleRate,
16,
options.Recording.Channels);
return new NaudioCaptureAudioSource(capture, "microphone", logger);
}
catch
{
capture.Dispose();
throw;
}
}
private static MicrophoneDevice? GetDefaultMicrophone()