[英]High frequency sound Python
I've started to write a script, which is to generate sound of any frequency.我已经开始写一个脚本,它是生成任何频率的声音。 I found some examples and tried to run them.
我找到了一些示例并尝试运行它们。 Then I accidentally put 16000 Hz and somehow my computer played it, although it shouldn't.
然后我不小心把 16000 Hz 和我的电脑以某种方式播放了它,尽管它不应该。 Does anyone know why I can hear such high fr.
有谁知道为什么我能听到这么高的 fr。 sound?
声音? I mean there must be a mistake in the code.
我的意思是代码中一定有错误。
SAMPLE_RATE = 44100
S_16BIT = 2 ** 16
def generate_sample(freq, duration, volume):
amplitude = np.round(S_16BIT * volume)
total_samples = np.round(SAMPLE_RATE * duration)
w = 2.0 * np.pi * freq / SAMPLE_RATE
k = np.arange(0, total_samples)
return np.round(amplitude * np.sin(k * w))
freq_array = np.array([260.00, 290.00, 329.63, 350.00, 392.00, 440.00, 800.00, 16000.00])
tones = []
for freq in freq_array:
tone = np.array(generate_sample(freq, 1.0, 1.0), dtype=np.int16)
tones.append(tone)
def fmain():
p = pa.PyAudio()
stream = p.open(format=p.get_format_from_width(width=2), channels=2, rate=SAMPLE_RATE, output=True)
stream.write(tones[7])
stream.stop_stream()
stream.close()
p.terminate()
fmain()
UPD: 30kHz also can be heard for some reason. UPD:30kHz 也可以因为某种原因听到。
No mistake, the upper limit of the human ear is 20000 Hertz or 20 kHz, 16 kHz is well within the limit.没错,人耳的上限是20000赫兹或20 kHz,16 kHz完全在这个范围内。
https://en.wikipedia.org/wiki/Hearing_range https://en.wikipedia.org/wiki/Hearing_range
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.