所以我试图在我的代码完成后播放一个简单的哔哔声,因为处理大量数据需要一段时间。我在网上尝试了其他示例,但似乎没有任何效果。我试过了:
import sys
sys.stdout.write('\a')
sys.stdout.flush()
它在 IDE shell 中输出单词 bel,但没有别的
我也试过:
import os
print('\a')
输出完全相同的东西。
我试过了
import os
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( 4, 4))
它只是输出:
sh: play: command not found
有人有任何想法吗?
这里还有一个包含 bell 一词的 jpg。看起来很有趣...
我还确保我的音量调高了
更新:它可能只是我的 IDE。我尝试直接从终端启动 python 并使用 write('\a') 并且它起作用了。它只是在 101 翼不起作用
最佳答案
实际上,sys.stdout.write('\a')
对我有用,但在 IDE 中无效,尝试在 终端 中运行此代码。您将听到系统声音。
你也可以试试这两个命令:
say
afplay
例如
import os
os.system('say "Beer time."')
import os
os.system('afplay /System/Library/Sounds/Sosumi.aiff')
运行
man say
以查看更多详细信息。say Hello, World.
say -v Alex -o hi -f hello_world.txt.
say --interactive=/green spending each day the color of the leaves.
say -o hi.aac 'Hello, [[slnc 200]] World'.
say -o hi.m4a --data-format=alac Hello, World.
希望这可以帮助。
关于python - 如何使用 python 3 在 OSX 中发出声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42150309/