python-3.x - 如何在 python3 中用频率发出声音?

标签 python-3.x audio frequency beep

我试过这个,但它并没有超过一个空行:

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

window :
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

关于python-3.x - 如何在 python3 中用频率发出声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43904019/

相关文章:

android - 如何将音频文件与新的视频文件合并?在 Android 中有可能吗?

python - Pandas 数据帧频率操作

r - 计算特定时间段内出现的次数

python - 创建您自己的查找字符串函数

python3.6 : equivalent of %d %s using the format: f("string {var1} {var2})

python-3.x - 如何在使用 aiohttp session.get 发出请求时发送 etag 或上次修改

actionscript-3 - AS3正在获得音频电平,音调和其他数据?

python-3.x - 模块未找到错误 : No module named 'bs4

ios - Xcode 中是否有类似于音乐、播客和电报应用程序中使用的现成音频播放器?

android - 在 java 中以编程方式获得 android 设备上的 root 用户权限以更改 scaling_governor