Audio can not find value["bytes"]
Author: YooSungHyun
State: closed
Labels: name: bug

## Describe the bug
I wrote down _generate_examples like:
![image](https://user-images.githubusercontent.com/34292279/168027186-2fe8b255-2cd8-4b9b-ab1e-8d5a7182979b.png)

but where is the bytes?
![image](https://user-images.githubusercontent.com/34292279/168027330-f2496dd0-1d99-464c-b15c-bc57eee0415a.png)


## Expected results
value["bytes"] is not None, so i can make datasets with bytes, not path

## bytes looks like:
blah blah~~
\xfe\x03\x00\xfb\x06\x1c\x0bo\x074\x03\xaf\x01\x13\x04\xbc\x06\x8c\x05y\x05,\t7\x08\xaf\x03\xc0\xfe\xe8\xfc\x94\xfe\xb7\xfd\xea\xfa\xd5\xf9$\xf9>\xf9\x1f\xf8\r\xf5F\xf49\xf4\xda\xf5-\xf8\n\xf8k\xf8\x07\xfb\x18\xfd\xd9\xfdv\xfd"\xfe\xcc\x01\x1c\x04\x08\x04@\x04{\x06^\tf\t\x1e\x07\x8b\x06\x02\x08\x13\t\x07\x08 \x06g\x06"\x06\xa0\x03\xc6\x002\xff \xff\x1d\xff\x19\xfd?\xfb\xdb\xfa\xfc\xfa$\xfb}\xf9\xe5\xf7\xf9\xf7\xce\xf8.\xf9b\xf9\xc5\xf9\xc0\xfb\xfa\xfcP\xfc\xba\xfbQ\xfc1\xfe\x9f\xff\x12\x00\xa2\x00\x18\x02Z\x03\x02\x04\xb1\x03\xc5\x03W\x04\x82\x04\x8f\x04U\x04\xb6\x04\x10\x05{\x04\x83\x02\x17\x01\x1d\x00\xa0\xff\xec\xfe\x03\xfe#\xfe\xc2\xfe2\xff\xe6\xfe\x9a\xfe~\x01\x91\x08\xb3\tU\x05\x10\x024\x02\xe4\x05\xa8\x07\xa7\x053\x07I\n\x91\x07v\x02\x95\xfd\xbb\xfd\x96\xff\x01\xfe\x1e\xfb\xbb\xf9S\xf8!\xf8\xf4\xf5\xd6\xf3\xf7\xf3l\xf4d\xf6l\xf7d\xf6b\xf7\xc1\xfa(\xfd\xcf\xfd*\xfdq\xfe\xe9\x01\xa8\x03t\x03\x17\x04B\x07\xce\t\t\t\xeb\x06\x0c\x07\x95\x08\x92\t\xbc\x07O\x06\xfb\x06\xd2\x06U\x04\x00\x02\x92\x00\xdc\x00\x84\x00 \xfeT\xfc\xf1\xfb\x82\xfc\x97\xfb}\xf9\x00\xf8_\xf8\x0b\xf9\xe5\xf8\xe2\xf7\xaa\xf8\xb2\xfa\x10\xfbl\xfa\xf5\xf9Y\xfb\xc0\xfd\xe8\xfe\xec\xfe1\x00\xad\x01\xec\x02E\x03\x13\x03\x9b\x03o\x04\xce\x04\xa8\x04\xb2\x04\x1b\x05\xc0\x05\xd2\x04\xe8\x02z\x01\xbe\x00\xae\x00\x07\x00$\xff|\xff\x8e\x00\x13\x00\x10\xff\x98\xff0\x05{\x0b\x05\t\xaa\x03\x82\x01n\x03
blah blah~~

that function not return None

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version:2.2.1
- Platform:ubuntu 18.04
- Python version:3.6.9
- PyArrow version:6.0.1


Comments: ![image](https://user-images.githubusercontent.com/34292279/168063684-fff5c12a-8b1e-4c65-b18b-36100ab8a1af.png)

that is reason my bytes`s empty
but i have some confused why path prior is higher than bytes?

if you can make bytes in _generate_examples , you don`t have to make bytes to path?
because we have path and bytes already

> but i have some confused why path prior is higher than bytes?

If the audio file is already available locally, we don't need to store the bytes again.

If you don't specify a "path" to a local file, then the bytes are stored. You can set "path" to None for example.

> if you can make bytes in _generate_examples , you don`t have to make bytes to path?
> because we have path and bytes already

It's useful to pass both "path" and "bytes" in `_generate_examples`:
- when the dataset has been downloaded, then the "path" to the audio files are stored and we can ignore "bytes" in order to save disk space.
- when the dataset is loaded in streaming mode, the audio files are not available on your disk and therefore we use the "bytes" 

@lhoestq 
First of all, thx for reply

but, if i put in "bytes" and "path"
ex) {"bytes":"blah blah~", "path":"blah blah~"}

that source working that my bytes to empty first,
and then, re-calculate my bytes!
![image](https://user-images.githubusercontent.com/34292279/168534687-1fb60d8c-d369-47d2-a4bb-db68f95194b4.png)

if you have some pcm file, pcm is can read bytes.
so, i put in bytes and paths.
but bytes is been None why encode_example func make None
and then, on decode_example func, we no have bytes. so, calculate bytes to path.
pcm is not support librosa or soundfile, error occured!

the most important thing is not announced anywhere this situation can be reproduced

is that truly right process flow?

I don't think we support PCM files, feel free to convert your data to WAV for now.

It would be awesome to support PCM files though, let me know if you'd like to contribute this feature, I'd be happy to help

@lhoestq oh, how can i contribute?

You can clone the repository (see the guide on [how to contribute](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-create-a-pull-request)) and see how we can make the `Image.encode_example` method work with PCM data.

There might be other ways to approach this problem, but here is what I think is a reasonable one:

I think `Image.encode_example` should be able to take PCM bytes as input and the sampling rate, and return the WAV bytes (built by combining the PCM bytes and the sampling rate info), so that `Image.decode_example` can read it.

To check if the input bytes are PCM data, you can just check if the extension of the `path` is ".pcm".


maybe i can start to contribute on this sunday!
@lhoestq 

@lhoestq plz check my pr #4409 

am i wrong somting?

Thanks, I reviewed your PR :)