Files
2026-05-27 12:55:17 +02:00

60 lines
1.9 KiB
C#

namespace MeetingAssistant.Speakers;
internal static class SpeakerIdentityTranscriptAudit
{
public static Task AppendIdentifiedAsync(
IEnumerable<SpeakerIdentityReference> references,
string speakerLabel,
string name,
CancellationToken cancellationToken)
{
return AppendAsync(
references,
$"{DateTimeOffset.Now:yyyy-MM-dd} {speakerLabel} was identified as {name}",
cancellationToken);
}
public static Task AppendMergedAsync(
IEnumerable<SpeakerIdentityReference> references,
string name1,
string name2,
CancellationToken cancellationToken)
{
return AppendAsync(
references,
$"{DateTimeOffset.Now:yyyy-MM-dd} {name1} and {name2} were merged",
cancellationToken);
}
private static async Task AppendAsync(
IEnumerable<SpeakerIdentityReference> references,
string line,
CancellationToken cancellationToken)
{
foreach (var transcriptPath in references
.Select(reference => reference.TranscriptPath)
.Where(path => !string.IsNullOrWhiteSpace(path))
.Distinct(StringComparer.OrdinalIgnoreCase))
{
if (!File.Exists(transcriptPath))
{
continue;
}
var existing = await File.ReadAllTextAsync(transcriptPath, cancellationToken);
if (existing.Contains(line, StringComparison.OrdinalIgnoreCase))
{
continue;
}
var separator = existing.EndsWith(Environment.NewLine, StringComparison.Ordinal)
? ""
: Environment.NewLine;
await File.AppendAllTextAsync(
transcriptPath,
$"{separator}{line}{Environment.NewLine}",
cancellationToken);
}
}
}