我怎样才能用 python3 中的频率发出声音?
How can i make sound with frequency in python3?
我试过了,但它只生成了一个空行:
import os
a=300
b=2000
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( a, b))
在 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
模块和一些编码:
我试过了,但它只生成了一个空行:
import os
a=300
b=2000
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( a, b))
在 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
模块和一些编码: