buf = io.BytesIO()
with AudioFile(buf, "w", samplerate, num_channels, bit_depth, format, quality) as f:
f.write(samples)
result = buf.getvalue()
...this PR adds:
result = AudioFile.encode(samples, samplerate, format, num_channels, bit_depth, format)
...which releases the GIL while processing, doesn't require calling Python for every .write()/.seek()/.tell() during encoding, and is much cleaner to read. This particularly speeds up encoding for OGG files, which involves a lot of small .write() calls.
Comes with new docs:
Comparing performance between these two APIs when another thread is hogging the GIL:
Time taken to call write(10 minutes) for 1 file per thread in 8 threads: 74.01 seconds
Time taken to call encode(10 minutes) for 1 file per thread in 8 threads: 4.30 seconds
Instead of:
...this PR adds:
...which releases the GIL while processing, doesn't require calling Python for every
.write()
/.seek()
/.tell()
during encoding, and is much cleaner to read. This particularly speeds up encoding for OGG files, which involves a lot of small.write()
calls.Comes with new docs:
Comparing performance between these two APIs when another thread is hogging the GIL: