我尝试了这个,但它没有多于空行:
import os
a=300
b=2000
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( a, b))
答案 0 :(得分:2)
在Python中播放给定频率和持续时间的哔声的简单方法:
frequency = 1000 # Hertz
duration = 2000 # milliseconds
在 Windows :
上import winsound
winsound.Beep(frequency, duration)
在 Linux :
上# SoX must be installed using 'sudo apt-get install sox' in the terminal
import os
os.system('play -n synth %s sin %s' % (duration/1000, frequency))
在 macOS :
上# First install Homebrew (https://brew.sh/)
# and then SoX using 'brew install sox' in the terminal
import os
os.system('play -n synth %s sin %s' % (duration/1000, frequency))
跨平台:
使用PyAudio
模块和一些编码:https://stackoverflow.com/a/27978895