问题描述
我想有一个python程序提醒我,当它已经完成了它的任务,通过蜂鸣声的噪音。目前,我使用导入OS
然后使用命令行语音程序说工艺齐全。我更愿意它是一个简单的钟。
I'd like to have a python program alert me when it has completed its task by making a beep noise. Currently, I use import os
and then use a command line speech program to say "Process complete." I much rather it be a simple "bell."
我知道,有可以在Cocoa程序,NSBeep使用的功能,但我不认为有任何东西做与此有关。
I know that there's a function that can be used in Cocoa apps, NSBeep, but I don't think that has much anything to do with this.
我也试过打印(\\ A)
,但没有奏效。
I've also tried print(\a)
but that didn't work.
我使用的是Mac,如果你不能用我的可可评论说,这样可能会有帮助。
I'm using a Mac, if you couldn't tell by my Cocoa comment, so that may help.
谢谢!
推荐答案
你试过:
import sys
sys.stdout.write('\a')
sys.stdout.flush()
这是我在这里的工作在Mac OS 10.5
That works for me here on Mac OS 10.5
其实,我觉得你原来工作的尝试也稍加修改
Actually, I think your original attempt works also with a little modification:
print('\a')
(你只需要周围的字符序列的单引号)。
(You just need the single quotes around the character sequence).
这篇关于Python的声音("贝尔与QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!