EOFError encounted for some special audio lengths.
The reason is that when calculating the number of decompressed frames, the wrong order of operations resulted in floating point errors. E.g.:
math.ceil(53760 / 24000 * 75) evals to 169
math.ceil(53760 * 75 / 24000) evals to 168
Traceback (most recent call last):
File "/home/chenjiasheng/.local/bin/encodec", line 33, in <module>
sys.exit(load_entry_point('encodec', 'console_scripts', 'encodec')())
File "/mnt/d/code/encodec/encodec/__main__.py", line 117, in main
out, out_sample_rate = decompress(compressed)
File "/mnt/d/code/encodec/encodec/compress.py", line 185, in decompress
return decompress_from_file(fo, device=device)
File "/mnt/d/code/encodec/encodec/compress.py", line 147, in decompress_from_file
raise EOFError("The stream ended sooner than expected.")
EOFError: The stream ended sooner than expected.
🐛 Bug Report
EOFError
encounted for some special audio lengths. The reason is that when calculating the number of decompressed frames, the wrong order of operations resulted in floating point errors. E.g.:https://github.com/facebookresearch/encodec/blob/c79ba28c9199494d106d2c7f56006260528d7b16/encodec/compress.py#L120 This line of code should be changed to
frame_length = int(math.ceil(this_segment_length * model.frame_rate / model.sample_rate ))
To Reproduce
Create a .wav file with duration 2.24s and content all zeros.
Run encodec compress and decompress
gives error message:
Your Environment
repo version: