Public Access
Archive completed meeting assistant changes
PR and Push Build/Test / build-and-test (push) Successful in 9m19s
PR and Push Build/Test / build-and-test (push) Successful in 9m19s
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using MeetingAssistant.Recording;
|
||||
using NAudio.Wave;
|
||||
|
||||
namespace MeetingAssistant.Transcription;
|
||||
|
||||
@@ -77,7 +76,7 @@ public sealed class AsrDiagnosticService
|
||||
bool paceAudio,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await foreach (var chunk in ReadPcmWavChunks(fullPath, cancellationToken))
|
||||
await foreach (var chunk in PcmWavAudioChunkReader.ReadChunksAsync(fullPath, cancellationToken: cancellationToken))
|
||||
{
|
||||
await pipeline.WriteAsync(chunk, cancellationToken);
|
||||
if (paceAudio && chunk.Duration > TimeSpan.Zero)
|
||||
@@ -102,40 +101,6 @@ public sealed class AsrDiagnosticService
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
private static async IAsyncEnumerable<AudioChunk> ReadPcmWavChunks(
|
||||
string path,
|
||||
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default)
|
||||
{
|
||||
var reader = new WaveFileReader(path);
|
||||
try
|
||||
{
|
||||
var format = reader.WaveFormat;
|
||||
if (format.Encoding != WaveFormatEncoding.Pcm || format.BitsPerSample != 16)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
$"Only 16-bit PCM WAV files are supported. Found {format.Encoding} with {format.BitsPerSample} bits per sample.");
|
||||
}
|
||||
|
||||
var buffer = new byte[format.AverageBytesPerSecond];
|
||||
int read;
|
||||
while ((read = await reader.ReadAsync(buffer.AsMemory(0, buffer.Length), cancellationToken)) > 0)
|
||||
{
|
||||
yield return new AudioChunk(buffer[..read], format.SampleRate, format.Channels);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.Dispose();
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
// NAudio can throw while disposing reader streams from async iterators; diagnostics should not fail after reading all chunks.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record AsrDiagnosticResult(string Path, IReadOnlyList<TranscriptionSegment> Segments);
|
||||
|
||||
Reference in New Issue
Block a user