New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] WAV is corrupted or not a WAV File? #6
Comments
I'm not sure what a PCM file is, but if you have the samples in Dart, as an array of doubles, you can use package:wav to write them as a wav file. Just construct a Wav object, then write it to a file or a Uint8List. |
Code below throws Infinity or NaN to Int in write method. Any thoughts? final pcmBytes =
Uint8List.fromList(state.soundRecord.bytes.reversed.toList());
final wav = Wav(
[pcmBytes.buffer.asFloat64List()],
SoundConfig.BIT_RATE, // 16000
);
final wavBytes = wav.write(); |
I think the exception is because you try to read the samples byte data as the actual wav file. But it is only an assumption |
Ah, you may be right. Wav expecting to get bytes of actual wav file 🤔 |
The Wav constructor is expecting a list of Float64List, where each element in the Float64List is a sample, typically from -1 to 1. The bug in your code is that you're converting pcmBytes to a Float64List using asFloat64List, which just reinterprets each 8 byte chunk of the Uint8List as a double. This is probably not what you want to do. What's the format of the sound that the recorder gives you? I think you mentioned it was 16 bit pcm. In that case you have to do asInt16List instead of asFloat64List, then manually convert the int samples to doubles. If that's what you need, I have some functions inside Wav that do this. I could make them public. But let's try and confirm that this is your actual bug first. |
@liamappelbe Yeah you are right. It is much more reasonable. I am curious, why did you choose such large data type as f64 for audio samples? My implementation stores in i16 all the samples, and I think it is enough for most applications, and uses less space in memory. |
If you're doing audio analysis, or generating audio programatically, any math you do on the samples is going to be way easier if they're doubles. For example, I originally wrote the package because I was trying to test my FFT package by loading a wav file and FFTing it, which requires doubles. |
Oh I see. |
Hi, its me again :D
Thanks for package. Im not sure if its my side or your.
I'm recording voice by flutter_sound plugin and so my config looks like this:
SampleRate: 16000
Channels: 1
BitRate: 16000
Codec: PCM16
I can read later that file and display it but your package throws me error like below:
Link to example file recorded by flutter_sound uploaded to firestore - https://firebasestorage.googleapis.com/v0/b/tradewind-internal-f4761.appspot.com/o/voice_records%2Fvoice_2022-10-24T20%3A32%3A46.993797.wav?alt=media&token=e9891dc3-98b5-4592-9dfb-e112377dbae4
I would be grateful if you could tell me if that config is not supported or just my recorded files are corrupted.
Thanks in advance!
EDIT 1:
We have found out that we should save files as pcm not wav. Do you know any way to achieve converting pcm to wav file?
The text was updated successfully, but these errors were encountered: