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

Very simple question

Open zeke800 opened this issue 3 years ago • 4 comments
trafficstars

Thank you for the wonderful software!

It used to work fine, until I attempted using a very basic code, and for whatever reason it does not work. Why?

import soundfile as sf
sample_rate = 48000
wavdata = []

for i in range(10):
    wavdata.append(0)

for x in range(40):
    wavdata.append(1)

for y in range(10):
    wavdata.append(0)

sf.write('blip.wav', wavdata, sample_rate)  

Thank you so much!!

zeke800 avatar Jul 11 '22 21:07 zeke800

what's the error message?

bastibe avatar Jul 12 '22 09:07 bastibe

Thank you for the reply! When viewed in Audacity, the wav is simply all zeros. image

zeke800 avatar Jul 12 '22 14:07 zeke800

@zeke800 You might want to explicitly specify the data format subtype i.e., in your case maybe 'FLOAT'?

EDIT: From how I quickly grasp the implementation, *.wav files would use 'PCM_16' by default, which would require values to be scaled to 16bit integer for full-scale (to show up as 1 in the floating point representation in Audacity).

HaHeho avatar Jul 13 '22 00:07 HaHeho

Try writing float data

bastibe avatar Jul 14 '22 11:07 bastibe