有没有办法可以将所有值转换为每块数据的 float32?我尝试过这种方式,它不会给我一个错误,但随后奥比奥无法识别任何音高。此外,我不能直接转换为 float32,否则它对于我在程序的不同部分中使用的 FFT 变得过于敏感。
CHUNK = 1024
#need it to be float for pitch, but int for frequencies
#FORMAT = pyaudio.paFloat32
FORMAT = pyaudio.paInt32
CHANNELS = 1
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
audioData = stream.read(CHUNK)
pDetection = aubio.pitch("default", CHUNK,
CHUNK, RATE)
#
# Set unit.
pDetection.set_unit("midi")
pDetection.set_silence(-40)
pDetection.set_tolerance(.1)
#trying to change data into float
for i in audioData:
i = np.float32(i)
pitchSamples = np.fromstring(audioData, dtype = aubio.float_type)
#
pitch = pDetection(pitchSamples)[0]