soulsen
Converting PCM Byte Data to WAV stream with proper RIFF header - NAudio
pretty new to audio stuff
I'm trying to convert PCM byte data to a WAV stream that has a RIFF header using NAudio. Right now, I'm doing this
but im getting this error:
using var stream = new MemoryStream(args.PcmData.ToArray());
await using var sourceWaveStream = new RawSourceWaveStream(stream, new WaveFormat(8000, 1));
sourceWaveStream.Position = 0;
await foreach (var result in _whisperProcessor.ProcessAsync(sourceWaveStream))
{
Console.WriteLine(result.Text);
}
using var stream = new MemoryStream(args.PcmData.ToArray());
await using var sourceWaveStream = new RawSourceWaveStream(stream, new WaveFormat(8000, 1));
sourceWaveStream.Position = 0;
await foreach (var result in _whisperProcessor.ProcessAsync(sourceWaveStream))
{
Console.WriteLine(result.Text);
}
Whisper.net.Wave.CorruptedWaveException: Invalid wave file RIFF header.
at Whisper.net.Wave.WaveParser.InitializeCore(Boolean useAsync)
at Whisper.net.Wave.WaveParser.GetAvgSamplesAsync(CancellationToken cancellationToken)
at Whisper.net.WhisperProcessor.ProcessAsync(Stream waveStream, CancellationToken cancellationToken)+MoveNext()
at Whisper.net.WhisperProcessor.ProcessAsync(Stream waveStream, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Ghetto.Modules.ListeningTest.VoiceReceiveHandler(VoiceNextConnection connection, VoiceReceiveEventArgs args) in C:\Users\taluk\RiderProjects\Discord Bots\Ghetto\Modules\ListeningTest.cs:line 73
at Ghetto.Modules.ListeningTest.VoiceReceiveHandler(VoiceNextConnection connection, VoiceReceiveEventArgs args) in C:\Users\taluk\RiderProjects\Discord Bots\Ghetto\Modules\ListeningTest.cs:line 73
at Ghetto.Modules.ListeningTest.VoiceReceiveHandler(VoiceNextConnection connection, VoiceReceiveEventArgs args) in C:\Users\taluk\RiderProjects\Discord Bots\Ghetto\Modules\ListeningTest.cs:line 73
at DSharpPlus.AsyncEvents.AsyncEvent`2.<>c__DisplayClass7_0.<<InvokeAsync>b__0>d.MoveNext()
Whisper.net.Wave.CorruptedWaveException: Invalid wave file RIFF header.
at Whisper.net.Wave.WaveParser.InitializeCore(Boolean useAsync)
at Whisper.net.Wave.WaveParser.GetAvgSamplesAsync(CancellationToken cancellationToken)
at Whisper.net.WhisperProcessor.ProcessAsync(Stream waveStream, CancellationToken cancellationToken)+MoveNext()
at Whisper.net.WhisperProcessor.ProcessAsync(Stream waveStream, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Ghetto.Modules.ListeningTest.VoiceReceiveHandler(VoiceNextConnection connection, VoiceReceiveEventArgs args) in C:\Users\taluk\RiderProjects\Discord Bots\Ghetto\Modules\ListeningTest.cs:line 73
at Ghetto.Modules.ListeningTest.VoiceReceiveHandler(VoiceNextConnection connection, VoiceReceiveEventArgs args) in C:\Users\taluk\RiderProjects\Discord Bots\Ghetto\Modules\ListeningTest.cs:line 73
at Ghetto.Modules.ListeningTest.VoiceReceiveHandler(VoiceNextConnection connection, VoiceReceiveEventArgs args) in C:\Users\taluk\RiderProjects\Discord Bots\Ghetto\Modules\ListeningTest.cs:line 73
at DSharpPlus.AsyncEvents.AsyncEvent`2.<>c__DisplayClass7_0.<<InvokeAsync>b__0>d.MoveNext()
1 replies