Whenever I save the recorded audio files into the ‘WAV’ format using the audio recording tool in Ubuntu, though most players play them without any issues, but, when trying to load them into an audio editor or trying to convert them for instance, some tools give me the following error and exit:
‘premature end of file “your-audio-file.wav” while reading audio data’
This is usually caused by incomplete or somewhat a ‘corrupted’ WAV file ‘header’ (a special part of a WAV file that contains information such as its length, the codec that should be used for decoding, bitrate etc). These tools won’t be able to fix all sorts of errors, but ‘qwavheaderdump’ and ‘qwavinfo’ can fix some of these errors.
They can inspect a WAV file and if it finds errors, then will display the actual error rather than giving the above ‘premature end …’ message as it doesn’t say a lot about what’s the actual cause for that corruption.
‘qwavheaderdump’ and ‘qwavinfo ‘ are a part of the package called ‘quelcom’ (a set of tools that lets you fix/edit MP3 and WAV files). But I’ll be concentrating on those two tools here.
You can install them in Ubuntu 12.10 Quantal Quetzal, 12.04 Precise Pangolin, 11.10 Oneiric Ocelot, 11.04, 10.10 and 10.04 by entering the below command in your Terminal window.
sudo apt-get install quelcom
How to use them?
To scan a file for errors I’ll use the below tool/command …
Simply replace ‘your-audio.wav’ with your file’s path and name. At the end, it’ll scan and display the actual cause behind the error.
To try and fix a file, I’ll use the below command …
qwavheaderdump -F your-audio.wav
Don’t change the ‘-F’ argument, but again, make sure to replace the file name and the path. As soon as you run this command, it’ll scan and fix the file (if possible) and display a report.
An example …
For ease of understanding, let me give you an example.
Let’s assume that I have a troublesome WAV file called ‘demo.wav in my ‘Home’ folder. Then first I’ll use the below command to scan it for errors.
And as you can see from the first screenshot, it gave me an error by saying that the actual cause behind that ‘premature end …’ error is a ‘length mismatch’ issue.
To fix it, I’ll use the below command (you actually can simply skip scanning for errors and use the below command straight away as well).
qwavheaderdump -F demo.wav
As soon as I do this, it fixed this ‘length mismatch’ error, which is found in almost all WAV files created using the audio record tool in Ubuntu.
That’s it. Enjoy!.