python-soundfile icon indicating copy to clipboard operation
python-soundfile copied to clipboard

Runtime error: format not recognized

Open sWAGgygoat opened this issue 4 years ago • 10 comments

So I was trying to write several .wav file but get this error: image First I get a system error due to wrong path for writing files, but after I fixed the path, this 'format not recognized' error occurs.

sWAGgygoat avatar Aug 04 '21 04:08 sWAGgygoat

Does it work with a simple file name? It might be that libsndfile gets confused by the Asian characters in the file name. If so, you can provide the format, subtype, and endian manually, which should work as a workaround.

bastibe avatar Aug 15 '21 10:08 bastibe

Thanks for your kindly replying,I figure it out that some of my files are originally named by Chinese character,so that is the situation.

发自我的iPhone

------------------ Original ------------------ From: Bastian Bechtold @.> Date: Sun,Aug 15,2021 6:53 PM To: bastibe/python-soundfile @.> Cc: 程一迅 @.>, Author @.> Subject: Re: [bastibe/python-soundfile] Runtime error: format not recognized (#309)

sWAGgygoat avatar Aug 15 '21 11:08 sWAGgygoat

I'm afraid this problem is caused by libsndfile, not soundfile, so there's not much I can do about it. Either rename your files, or open a file descriptor (providing format, subtype, and endian manually), so libsndfile won't ever need to touch the actual file name.

bastibe avatar Aug 15 '21 19:08 bastibe

I also found this error, but my file name does not has non-ascii characters. image

CarlGao4 avatar Jun 17 '22 06:06 CarlGao4

This even happens when I'm writing into io.BytesIO:

RuntimeError: Error opening <_io.BytesIO object at 0x000001B109E460C0>: Format not recognised.

CarlGao4 avatar Jun 17 '22 07:06 CarlGao4

It might be that the wav file indeed contains a strange format that libsndfile doesn't recognize. Try supplying your own format and subtype manually.

bastibe avatar Jun 21 '22 06:06 bastibe

I'm trying to write a file when I got this exception. I have tried using str, file object and io.BytesIO, but all failed with the same error.

CarlGao4 avatar Jun 21 '22 06:06 CarlGao4

As I said, try supplying your own format and subtype.

bastibe avatar Jun 21 '22 06:06 bastibe

As I said, try supplying your own format and subtype.

The error still exists after adding them. I have read the source code and found that the error is inside _open function, which does not pass argument format and subtype.

CarlGao4 avatar Jun 21 '22 06:06 CarlGao4

Could you elaborate in a bit more detail?

Please provide example code if you can.

soundfile is rather well-tested at this point and I am certain that format and subtype do indeed work as intended.

bastibe avatar Jun 21 '22 06:06 bastibe

@bastibe , this could be a bug

https://github.com/bastibe/python-soundfile/issues/276

LastMonopoly avatar Nov 15 '22 09:11 LastMonopoly

I encountered the same error and the reason was that the array I tried to write was 2D array of size 1XN. When I converted to 1D array of size N it worked fine.

itamar-dw avatar Nov 15 '22 12:11 itamar-dw

As per the documentation, soundfile expects data in frames x channels, or one-dimensional data for mono files. It's unfortunate that librosa does it the other way around.

bastibe avatar Nov 19 '22 08:11 bastibe

Same error, diferent (aparent) reason:

LibsndfileError: Error opening 'C:\Users\iamki\Desktop\Iam\Aulas\2022_2\DL\Projeto\Aplicacoes\COVID\base_de_dados\coughvid\00098cdb-4da1-4aa7-825a-4f1b9abc214b.wav': Format not recognised.

In colab I can fix it and runs okay, but in juperlab it return.

iamk0 avatar Nov 23 '22 20:11 iamk0

Please provide a reproducible example

bastibe avatar Nov 24 '22 07:11 bastibe

I've found one possible reason of this issue: the audio is on the wrong dimension. I forgot which dimension the audio should be, but you can try changing it. e.g.

[[x x]
[x x]             [[x x x x x ... x]
[x x]      --->   [x x x x x ... x]]
...
[x x]]

CarlGao4 avatar Nov 24 '22 08:11 CarlGao4

Thank you so much @CarlGao4 , apparently the two errors are also being conflated and even though there might be a dimension not recognized error, it gets reported as format not recognized with the file name which suggests that there might be something to do with the filenames and/or audio format.

Changing the dimension of input does resolve the issue for me as well.

rijulg avatar Dec 17 '22 10:12 rijulg

As per the documentation, soundfile expects data in frames x channels, or one-dimensional data for mono files. It's unfortunate that librosa does it the other way around.

bastibe avatar Dec 19 '22 10:12 bastibe

I have this issue when i try to load m4a file on Windows. image

But i can load it when i use google colab image

Can you guys tell me what is the problem and how to fix it ? Thank you so much

RaitoRyuWorker avatar Feb 03 '23 09:02 RaitoRyuWorker