namespace FFMpegCore.Pipes { /// /// Implementation of for a raw audio stream that is gathered from . /// It is the user's responbility to make sure the enumerated samples match the configuration provided to this pipe. /// public class RawAudioPipeSource : IPipeSource { private readonly IEnumerator _sampleEnumerator; public string Format { get; set; } = "s16le"; public uint SampleRate { get; set; } = 8000; public uint Channels { get; set; } = 1; public RawAudioPipeSource(IEnumerator sampleEnumerator) { _sampleEnumerator = sampleEnumerator; } public RawAudioPipeSource(IEnumerable sampleEnumerator) : this(sampleEnumerator.GetEnumerator()) { } public string GetStreamArguments() { return $"-f {Format} -ar {SampleRate} -ac {Channels}"; } public async Task WriteAsync(Stream outputStream, CancellationToken cancellationToken) { if (_sampleEnumerator.Current != null) { await _sampleEnumerator.Current.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false); } while (_sampleEnumerator.MoveNext()) { await _sampleEnumerator.Current!.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false); } } } }