I'm using this WaveReader class in my code. I'm getting this error:
ERROR: Ensure that samples are integers (e.g. not floating-point numbers)
if (format.wFormatTag != 1) // 1 = PCM 2 = Float
throw new ApplicationException("Format tag " + format.wFormatTag + " is not supported!");
All I'm trying to is convert WAV file to FLAC so I can feed it to GoogleSpeechAPI. I can do the first step, record WAV files. I am stuck on the second step: convert WAV file to FLAC. I can do the 3rd step: convert FLAC to text using GoogleSpeech API.
For the second step, where I'm getting stuck, here is my code:
public void WAV_to_FLAC_converter()
{
string inputFile = "inputFile.wav";
//string outputFile = Path.Combine("flac", Path.ChangeExtension(input, ".flac"));
string outputFile = "outputFile.flac";
if (!File.Exists(inputFile))
throw new ApplicationException("Input file " + inputFile + " cannot be found!");
var stream = File.OpenRead(@"C:\inputFile.wav");
WavReader wav = new WavReader(stream);
using (var flacStream = File.Create(outputFile))
{
FlacWriter flac = new FlacWriter(flacStream, wav.BitDepth, wav.Channels, wav.SampleRate);
// Buffer for 1 second's worth of audio data
byte[] buffer = new byte[wav.Bitrate / 8];
int bytesRead;//**I GET THE ABOVE ERROR HERE.**
do
{
bytesRead = wav.InputStream.Read(buffer, 0, buffer.Length);
flac.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
flac.Dispose();
flac = null;
}
}
Apparently there is something wrong with the input wav file I am giving the function. I think it says the stream variable that I created is in float-point instead of integer. But what am I supposed to do? I didn't mess with the WAV file. It's just a WAV file. How can I change a WAV file from float-point to Integer?? I don't know how to fix this.