pyAudio:奇怪的行为

时间:2018-08-23 01:17:44

标签: python audio pyaudio

我正在尝试通过音频输出生成正弦波。我不想生成一个wav文件然后再进行再现,我想“实时”生成信号。因此,我写了这个简单的脚本:

import pyaudio
import numpy as np
import matplotlib.pyplot as plt

SAMPLING_RATE = 44100
AUDIO_FREQ = 100

chunk_size = int(SAMPLING_RATE/AUDIO_FREQ)
samples = np.sin(2*np.pi*AUDIO_FREQ/SAMPLING_RATE*np.arange(chunk_size))
samples = samples.astype(np.float32)
plt.plot(samples)
plt.show()

p = pyaudio.PyAudio()
ostream = p.open(format=pyaudio.paFloat32, channels=2, rate=SAMPLING_RATE, output=True)
for k in range(60):
    ostream.write(samples)
ostream.stop_stream()
ostream.close()
p.terminate()

用样本绘制的图看起来像这样:

enter image description here

但是示波器捕获的音频信号是

enter image description here

我找不到问题所在...

0 个答案:

没有答案