sandrohanea / whisper.net

Whisper.net. Speech to text made simple using Whisper Models
MIT License
506 stars 77 forks source link

Invalid Wave file RIFF header when recording with a microphone #154

Closed eugeneYz closed 5 months ago

eugeneYz commented 5 months ago

I used Naudio to capture microphone audio data and converted (byte [] type) pcmData to WaveStream, but processor.ProcessAsync (waveStream) still reported an error. How can I fixed it up?

            nAudioHelper?.StartRec();
            nAudioHelper.PcmDataAvailable += async (data) =>
            {
                pcmData = data;
                MemoryStream memoryStream = new MemoryStream(pcmData);

                WaveFormat waveFormat = new WaveFormat(16000, 16, 1); 

                WaveStream waveStream = new RawSourceWaveStream(memoryStream, waveFormat);
                await foreach (var result in processor.ProcessAsync(waveStream))
                {
                    numkeyboard.Value = result.Text;
                }
            };
            nAudioHelper?.StopRec();
sandrohanea commented 5 months ago

The wavestream that was provided was not containing the wave header and this caused the processor to not accept it as it doesn't know how to decode it (what's the frequency, etc).