Python的:声音报警时,code饰面 [英] Python: Sound alarm when code finishes

查看:368
本文介绍了Python的:声音报警时,code饰面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的code需要极长的运行情况,我不希望是在这一切的时候,但盯着想知道当它完成。

I am in a situation where my code takes extremely long to run and I don't want to be staring at it all the time but want to know when it is done.

我怎样才能让(蟒蛇)code类声音的警报,当它完成?我正在考虑使其成为播放.wav文件,当它达到code月底...

How can I make the (Python) code sort of sound an "alarm" when it is done? I was contemplating making it play a .wav file when it reaches the end of the code...

这甚至一个可行的想法?
如果是这样,我怎么能这样做呢?

Is this even a feasible idea? If so, how could I do it?

推荐答案

因此​​,它取决于你的系统,下面就为窗口工作:

So it depends on your system, the following will work for windows:

import winsound
winsound.Beep(300,2000)

其中a是频率,b是在毫秒的持续时间

where a is the frequency and b is the duration in miliseconds

这是对于Linux:

import os
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( a, b))

其中,a是在几秒钟和b的持续时间是频率

where a is the duration in seconds and b is the frequency

和一些非常酷的,如果你在终端使用的是Mac,也许可以做的窗户一样,但我只知道肯定的Mac,这会告诉你,它的完成:

and something really cool if you're using a mac in terminal, maybe can do the same in windows, but I only know for sure for mac, this will tell you it's done:

import os
os.system('say "your program has finished"')

请注意:为了使用第一个Linux示例,您必须安装 SOX 。下面是这样做的方式MacPorts的运行...这是你的终端:

note: in order to use the first linux example, you must install sox. Here is the macports way of doing that...run this is your terminal:

sudo port install sox

这篇关于Python的:声音报警时,code饰面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆