Public Access
Keep recording startup independent of dictation words
PR and Push Build/Test / build-and-test (push) Failing after 8m52s
PR and Push Build/Test / build-and-test (push) Failing after 8m52s
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user