Please help! How turn wav to binary data!!!

we kown that Arduino system don't like c language have file system

so,i use Sd card save my .wav file.

but SD.h libraries didn't have a like c language :

f.open("music.wav","rb") // open a stream file use in binary system
f.open("music.wav","r") just r,w ...No rb wb

and like fread() etc fread("music.wav") // reads data from the file stream

Please help me : open a wav file turn it to binary data.

thanks

All files contain binary data - there is no need to convert anything.

Merged.

but, some websites need to turn wav into binary transmission and identify them.
so,i need kown how turn wav bytes by bytes to binary data

thanks a lot

wgq6959424:
but, some websites need to turn wav into binary transmission and identify them.
so,i need kown how turn wav bytes by bytes to binary data

thanks a lot

To stop all the confusion, please give an example of a byte from a wave file and how you think that would be in binary.

Paul

WAV is a very specific form of compression that works well for audio data. A small WAV file holds many megabytes of audio.

The Arduino memory is just a few kilobytes. It cannot hold even 1 second of uncompressed audio. What do you want to do with that tiny piece of data?

MorganS:
WAV is a very specific form of compression that works well for audio data. A small WAV file holds many megabytes of audio.

The Arduino memory is just a few kilobytes. It cannot hold even 1 second of uncompressed audio. What do you want to do with that tiny piece of data?

thank you for MorganS reply

I have a project about speech recognition using Arduino.The idea is to convert the wav file(The file size is about 8K) to Base64 to facilitate server identification.

The current progress is to turn wav into binary

MorganS:
WAV is a very specific form of compression that works well for audio data. A small WAV file holds many megabytes of audio.

That's not true at all. WAV is a container format and can contain audio data in a variety of different codecs. However, most commonly, WAV is used to store uncompressed linear PCM data.

Hmmm italic code

That will read bytes from the file. But they are meaningless without decompression.

I'm not sure if I read all the information contained in the entire wav file.

Why don't you? You know (or could, the library knows) the size of the file. You know how many bytes you read from the file. The numbers match and you've read all the data, or they don't, and you haven't.

Hi wgq6959424, and others,
A long time ago (1990) I managed to play wav files using a PC printer port and DAC/ADC. On the dark age on information. I get some information about .wav on magazines ans other pre internet information media.
The microsoft wave file have a 44 bytes of header, one of these bytes store the bit sample size, 8bit, 16 bits, etc.
I starting my study of Arduino, I dion't know all functions of API/ABI.
If wav file always have same format, just ignore first 44bytes and read rest of data according of know bit sample size.

If wav file always have same format, just ignore first 44bytes and read data according of bit sample size.

If you ignore the first 44 bytes, you won't know the bit sample size, so reading the rest of the data "according of bit sample size" isn't going to work too well.

pksato:
Hi wgq6959424, and others,
A long time ago (1990) I managed to play wav files using a PC printer port and DAC/ADC. On the dark age on information. I get some information about .wav on magazines ans other pre internet information media.
The microsoft wave file have a 44 bytes of header, one of these bytes store the bit sample size, 8bit, 16 bits, etc.
I starting my study of Arduino, I dion't know all functions of API/ABI.
If wav file always have same format, just ignore first 44bytes and read data according of bit sample size.

Now it's my dark moment (>﹏<)

wgq6959424:
Thanks Paul
ok. the example wav file at : http://speech-doc.gz.bcebos.com/rest-api-asr/public_audio/16k.wav

The current idea is to open the wav file and then read each byte.

File myFile = SD.open("16k.wav");

byte buffer[256];

uint16_t bufLen=myFile.read(buffer,256);

for (uint16_t i=0;i<bufLen;i++){

Serial.print(buffer*,HEX);*

  • }*
  • myFile.close();*
    I'm not sure if I read all the information contained in the entire wav file.
    [/quote]
    Ok, was what you read "binary"? By now you surely realize every byte on every file is "binary".
    Paul

MorganS:
That will read bytes from the file. But they are meaningless without decompression

Nonsense. It is a standard WAV file, 16-bit PCM sampled at 16kHz. NO compression.
All that is required to read it, is to read two bytes at a time and that will give the 16-bit samples.
Or read the whole thing into a suitably sized buffer of signed 16-bit integers.

Pete