Update: add using pcm bytes (#4323)
COLLABORATOR
@lhoestq Maybe I'm missing something, but what's the reason to read and encode PCM files to WAV in `Audio.encode_example`. Isn't the whole purpose of the decodable types to operate on raw files whenever possible? IMO this PR should only modify `Audio.decode_example` to support PCM files/bytes decoding.
2022-06-01T13:57:17Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1143647118
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EKquO
https://api.github.com/repos/huggingface/datasets/issues/comments/1143647118/reactions
2022-06-01T13:57:17Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1143647118
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
MEMBER
Because the PCM file is not enough, we also need the `sampling_rate` associated to it. Therefore the two alternatives are either:
- convert to WAV
- add a `sampling_rate` field to the Audio arrow storage (not sure how it would behave for backward compatibility though)
2022-06-01T14:03:09Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1143654088
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EKsbI
https://api.github.com/repos/huggingface/datasets/issues/comments/1143654088/reactions
2022-06-01T14:03:09Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1143654088
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
COLLABORATOR
But [`scipy.io.wavfile.read`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html), which is used for reading such files, returns a file's sampling rate. The only tricky part is [resampling](https://stackoverflow.com/questions/33682490/how-to-read-a-wav-file-using-scipy-at-a-different-sampling-rate) to a different sampling rate than the default one.
2022-06-01T14:16:56Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1143671162
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EKwl6
https://api.github.com/repos/huggingface/datasets/issues/comments/1143671162/reactions
2022-06-01T14:16:56Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1143671162
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
MEMBER
How does it get the sampling rate of a PCM file then ? According to [SO](https://stackoverflow.com/a/57027667/17517845) it's not possible to infer it from the file alone
2022-06-01T14:25:57Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1143681737
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EKzLJ
https://api.github.com/repos/huggingface/datasets/issues/comments/1143681737/reactions
2022-06-01T14:25:57Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1143681737
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
> Awesome thanks ! Could you also add tests in `tests/features/test_audio.py` ?
> 
> Maybe add a small pcm file in `tests/features/data` and check that everything works as expected in tests cases like `test_audio_encode_example_pcm` and `test_audio_decode_example_pcm` for example.

@lhoestq  how can i test test_audio.py? where is "__main__" func?
do you have some example or guideline?
2022-06-02T08:49:20Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1144612792
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EOWe4
https://api.github.com/repos/huggingface/datasets/issues/comments/1144612792/reactions
2022-06-02T08:49:20Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1144612792
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
CONTRIBUTOR
> But [`scipy.io.wavfile.read`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.read.html), which is used for reading such files, returns a file's sampling rate. The only tricky part is [resampling](https://stackoverflow.com/questions/33682490/how-to-read-a-wav-file-using-scipy-at-a-different-sampling-rate) to a different sampling rate than the default one.

@mariosasko @lhoestq 
thanks for comment!

First of all, "PCM file" can not read alone to any audio library.
"PCM file" has not any audio META information header. (it just purely audio byte data. therefore, we don't have to encoding and decoding)
but, "PCM file" is audio extension, so we can use `datasets.Audio`

if you want to read "PCM file" to audio file likely, it have to needs additional parameter. (channel, sampling_rate, else....)
but, in many situation, we only know sampling_rate for PCM

and, if we want to use `datasets.Audio` for "PCM file", we must process encode_example.
therefore, i have to use sampling_rate for encoding for making wav-style byte. (we only know sampling_rate)

In my source code, I don't compare sampling rate(`datasets.Audio's self.sampling_rate` and `read pcm sampling_rate(value["sampling_rate"])`) and checking mono
@mariosasko ! do you want to process resampling and making mono? then i can modify my source

2022-06-02T09:35:15Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1144654366
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EOgoe
https://api.github.com/repos/huggingface/datasets/issues/comments/1144654366/reactions
2022-06-07T08:26:58Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1144654366
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
MEMBER
There is no "main" function in test scripts :) To run a test script you must use the `pytest` command:
```
pytest tests/features/test_audio.py
```

to run only one function you can also do
```
pytest tests/features/test_audio.py::test_audio_feature_type_to_arrow
```
for example
2022-06-09T09:44:27Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1150907464
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5EmXRI
https://api.github.com/repos/huggingface/datasets/issues/comments/1150907464/reactions
2022-06-09T09:44:27Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1150907464
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
@lhoestq
maybe, if i write test code, i have to commit test_audio.py and send pr?
because, we need to keep `test_audio_encode_example_pcm` and `test_audio_decode_example_pcm` method after my pr merged?
2022-06-13T09:36:21Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1153697174
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5ExAWW
https://api.github.com/repos/huggingface/datasets/issues/comments/1153697174/reactions
2022-06-13T09:36:21Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1153697174
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
MEMBER
You can add your tests in this PR with the other changes you did
2022-06-13T09:41:32Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1153702204
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5ExBk8
https://api.github.com/repos/huggingface/datasets/issues/comments/1153702204/reactions
2022-06-13T09:41:32Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1153702204
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
CONTRIBUTOR
@lhoestq 
test complete & commit my test_audio.py

AND, some change in my code.

audio.py
i think "sampling_rate" is already Audio object initial variable. so, we don`t have to use input parameter.

test_audio.py
we can check "PCM" file to path (exactly, extenstion)
so, test case has to know `path`. if only have `bytes`, we don`t know that is "PCM" or not
2022-06-14T10:09:07Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1154986027
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5E17Ar
https://api.github.com/repos/huggingface/datasets/issues/comments/1154986027/reactions
2022-06-14T10:09:30Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1154986027
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
CONTRIBUTOR
@lhoestq
and, why circleci raised exception?
maybe, [repo](https://huggingface.co/api/datasets/lhoestq/_dummy?full=true) url is not found!
PLZ, CHK!
2022-06-14T10:19:31Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1154995702
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5E19X2
https://api.github.com/repos/huggingface/datasets/issues/comments/1154995702/reactions
2022-06-14T10:19:31Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1154995702
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
CONTRIBUTOR
@lhoestq
hello????
2022-06-23T11:03:43Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1164272407
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5FZWMX
https://api.github.com/repos/huggingface/datasets/issues/comments/1164272407/reactions
2022-06-23T11:03:43Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1164272407
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
CONTRIBUTOR
@lhoestq 
test_audio.py
if we don`t use path in pcm, test-case need to be changed
so, we check path just None
2022-06-24T03:53:51Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1165165630
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5FcwQ-
https://api.github.com/repos/huggingface/datasets/issues/comments/1165165630/reactions
2022-06-24T03:53:51Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1165165630
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
CONTRIBUTOR
i'm merge branch already and `multiprocess` in `setup.py` but circleci error only win version
![image](https://user-images.githubusercontent.com/34292279/175461714-c7d2e741-3b7b-40a3-bba9-13ce2af0055c.png)
how can i fixed it?
2022-06-24T04:15:07Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1165175022
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5Fcyju
https://api.github.com/repos/huggingface/datasets/issues/comments/1165175022/reactions
2022-06-24T04:22:46Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1165175022
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
CONTRIBUTOR
@lhoestq thx for comment!
test_audio.py test complete. it runs sucessfully
and, self.get("sampling_rate") -> value.get("sampling_rate") changed

and, some comment is not agreed to me, plz check my sub comment!
2022-06-29T06:07:57Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1169571314
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5Ftj3y
https://api.github.com/repos/huggingface/datasets/issues/comments/1169571314/reactions
2022-06-29T06:07:57Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1169571314
https://avatars.githubusercontent.com/u/34292279?v=4
https://api.github.com/users/YooSungHyun/events{/privacy}
https://api.github.com/users/YooSungHyun/followers
https://api.github.com/users/YooSungHyun/following{/other_user}
https://api.github.com/users/YooSungHyun/gists{/gist_id}
https://github.com/YooSungHyun
YooSungHyun
MDQ6VXNlcjM0MjkyMjc5
https://api.github.com/users/YooSungHyun/orgs
https://api.github.com/users/YooSungHyun/received_events
https://api.github.com/users/YooSungHyun/repos
https://api.github.com/users/YooSungHyun/starred{/owner}{/repo}
https://api.github.com/users/YooSungHyun/subscriptions
User
https://api.github.com/users/YooSungHyun
public
NONE
_The documentation is not available anymore as the PR was closed or merged._
2022-07-07T12:58:07Z
https://github.com/huggingface/datasets/pull/4409#issuecomment-1177572914
https://api.github.com/repos/huggingface/datasets/issues/4409
IC_kwDODunzps5GMFYy
https://api.github.com/repos/huggingface/datasets/issues/comments/1177572914/reactions
2022-07-07T13:27:29Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1177572914
https://avatars.githubusercontent.com/u/99929124?v=4
https://api.github.com/users/HuggingFaceDocBuilderDev/events{/privacy}
https://api.github.com/users/HuggingFaceDocBuilderDev/followers
https://api.github.com/users/HuggingFaceDocBuilderDev/following{/other_user}
https://api.github.com/users/HuggingFaceDocBuilderDev/gists{/gist_id}
https://github.com/HuggingFaceDocBuilderDev
HuggingFaceDocBuilderDev
U_kgDOBfTMJA
https://api.github.com/users/HuggingFaceDocBuilderDev/orgs
https://api.github.com/users/HuggingFaceDocBuilderDev/received_events
https://api.github.com/users/HuggingFaceDocBuilderDev/repos
https://api.github.com/users/HuggingFaceDocBuilderDev/starred{/owner}{/repo}
https://api.github.com/users/HuggingFaceDocBuilderDev/subscriptions
User
https://api.github.com/users/HuggingFaceDocBuilderDev
public
first of all, please look #4323

why i can not use {"path","array","sampling_rate"}
because sf.write(format="wav") and sf.read(BytesIO) is changed my pcm data value
maybe, i think wav got header but, pcm is not.
and variable naming, pcm data is "byte" type. so, "array" name is not fair i think

so, i use scipy lib and numpy (that is huggingface dependency)
and refer to @lhoestq answered,
1. encode -> using sampling_rate and pcm byte -> wav style byte (scipy.wavfile.write to byte)
2. byte converting using fairseq style pcm audio read  [FileAudioDataset](https://github.com/facebookresearch/fairseq/blob/main/fairseq/data/audio/raw_audio_dataset.py)
4. decode -> read wavfile.read

that way is not screw up my pcm byte to float data, and another audio type(wav) safety

please check!