Reputation: 129
I have used the write function from scipy.io.wavfile to generate a .wav file.
final_out = np.int16(stereo_out/np.max(np.abs(stereo_out)) * 32767)
write('final.wav', fs, final_out)
Is there any alternate function for write that allows more than 32767 samples?
Upvotes: 2
Views: 472
Reputation: 4118
There is not such limitation in the number of samples that can be written to a a wav file with scipy.io.wavfile
. The actual limitation on the number of samples is 2^32 (4,294,967,296), but it comes from the fact that the header stores the number of samples as a 32-bit unsigned integer.
The WAV format, however, stores the amplitude of each sample in 16-bits.
With a signed integer of 16-bits, you can only store numbers in the range [-32768, 32767] inclusive, you'll need to scale your signal accordingly to fit that range.
You can think of that number as a fraction (ratio) of the highest amplitude that your system can produce.
Upvotes: 1
Reputation: 21991
You might take a look at the wave module in Python's Standard Library. It may allow you to write more than 32767 samples, but I am unsure as to what limitations you may come across while trying to use it.
Upvotes: 0