Public Access
87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using MeetingAssistant.Transcription;
|
|
|
|
namespace MeetingAssistant.Recording;
|
|
|
|
public interface IRecordingDictationWordProvider
|
|
{
|
|
Task<IReadOnlyList<string>> ReadOptionalWordsAsync(
|
|
MeetingAssistantOptions runOptions,
|
|
CancellationToken cancellationToken);
|
|
}
|
|
|
|
public sealed class RecordingDictationWordProvider : IRecordingDictationWordProvider
|
|
{
|
|
private readonly IDictationWordStore dictationWordStore;
|
|
private readonly ILogger<RecordingDictationWordProvider> logger;
|
|
|
|
public RecordingDictationWordProvider(
|
|
IDictationWordStore dictationWordStore,
|
|
ILogger<RecordingDictationWordProvider> logger)
|
|
{
|
|
this.dictationWordStore = dictationWordStore;
|
|
this.logger = logger;
|
|
}
|
|
|
|
public async Task<IReadOnlyList<string>> ReadOptionalWordsAsync(
|
|
MeetingAssistantOptions runOptions,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var timeout = runOptions.Recording.DictationWordsReadTimeout;
|
|
if (timeout <= TimeSpan.Zero)
|
|
{
|
|
return await ReadWithoutFallbackTimeoutAsync(runOptions, cancellationToken);
|
|
}
|
|
|
|
try
|
|
{
|
|
using var readCancellation = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
|
var readTask = dictationWordStore.ReadWordsAsync(runOptions, readCancellation.Token);
|
|
try
|
|
{
|
|
return await readTask.WaitAsync(timeout, cancellationToken);
|
|
}
|
|
catch (TimeoutException exception)
|
|
{
|
|
readCancellation.Cancel();
|
|
logger.LogWarning(
|
|
exception,
|
|
"Reading dictation words timed out after {Timeout}; recording will continue without dictation-word hints",
|
|
timeout);
|
|
return [];
|
|
}
|
|
}
|
|
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
|
|
{
|
|
throw;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogWarning(
|
|
exception,
|
|
"Could not read dictation words; recording will continue without dictation-word hints");
|
|
return [];
|
|
}
|
|
}
|
|
|
|
private async Task<IReadOnlyList<string>> ReadWithoutFallbackTimeoutAsync(
|
|
MeetingAssistantOptions runOptions,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
return await dictationWordStore.ReadWordsAsync(runOptions, cancellationToken);
|
|
}
|
|
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
|
|
{
|
|
throw;
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogWarning(
|
|
exception,
|
|
"Could not read dictation words; recording will continue without dictation-word hints");
|
|
return [];
|
|
}
|
|
}
|
|
}
|