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
@@ -4,41 +4,28 @@ using NAudio.Wave;
namespace MeetingAssistant.Recording;
public sealed class MicrophoneAudioSource : IMeetingAudioSource
internal sealed class NaudioCaptureAudioSource : IMeetingAudioSource
{
private readonly IMicrophoneDeviceProvider microphones;
private readonly ILogger<MicrophoneAudioSource> logger;
private readonly IWaveIn capture;
private readonly string sourceName;
private readonly ILogger logger;
public MicrophoneAudioSource(
IMicrophoneDeviceProvider microphones,
ILogger<MicrophoneAudioSource> logger)
public NaudioCaptureAudioSource(
IWaveIn capture,
string sourceName,
ILogger logger)
{
this.microphones = microphones;
this.capture = capture;
this.sourceName = sourceName;
this.logger = logger;
}
public IAsyncEnumerable<AudioChunk> CaptureAsync(CancellationToken cancellationToken)
{
return CaptureAsync(new MeetingAssistantOptions(), cancellationToken);
return CaptureWith(capture, sourceName, logger, cancellationToken);
}
public IAsyncEnumerable<AudioChunk> CaptureAsync(
MeetingAssistantOptions options,
CancellationToken cancellationToken)
{
return CaptureAsync(microphones.CreateCapture(options), options, cancellationToken);
}
private IAsyncEnumerable<AudioChunk> CaptureAsync(
IWaveIn capture,
MeetingAssistantOptions options,
CancellationToken cancellationToken)
{
capture.WaveFormat = new WaveFormat(options.Recording.SampleRate, 16, options.Recording.Channels);
return CaptureWith(capture, "microphone", logger, cancellationToken);
}
internal static async IAsyncEnumerable<AudioChunk> CaptureWith(
private static async IAsyncEnumerable<AudioChunk> CaptureWith(
IWaveIn capture,
string sourceName,
ILogger logger,
@@ -124,6 +111,6 @@ public sealed class SystemAudioSource : IMeetingAudioSource
WaveFormat = new WaveFormat(options.Recording.SampleRate, 16, options.Recording.Channels)
};
return MicrophoneAudioSource.CaptureWith(capture, "system", logger, cancellationToken);
return new NaudioCaptureAudioSource(capture, "system", logger).CaptureAsync(cancellationToken);
}
}