I am playing audio with python and i don't understand why i hear noise on the ouptut when executing code like this:
import pyaudio
import wave
import numpy as np
f = wave.open('blabla.wav',"r")
p = pyaudio.PyAudio()
# open stream
stream = p.open(format = p.get_format_from_width(f.getsampwidth()),
channels = f.getnchannels(),
rate = f.getframerate(),
output = True)
float_array = np.fromstring(f.readframes(10000000), dtype=np.uint16).astype('float32')
output = 0.9 * float_array
stream.write(output.astype('uint16').tostring())
When i multiply by 0.9
i expect weakening a signal a little bit. But where from this ouput noise came from ?
I don't even add anything to initial data!
Basically i want to add two signals :
output signal = 0.5 * the origin one + 0.5 * shifted origin one
But i get mess out of this process, because even a multiplying an original array make the signal near entirely sound like a mess.
Can you point me out what am i doing wrong and how to make the formula
output signal = 0.5 * the origin one + 0.5 * shifted origin one
work right ?
I think 16 bit PCM is usually signed. Try using int16
instead of uint16