随笔 - 1759  文章 - 0  评论 - 109  阅读 - 431万

python发出提示音

在Windows上

import winsound
duration = 1000  # millisecond
freq = 440  # Hz
winsound.Beep(freq, duration)

其中,FREQ是频率(以赫兹为单位),而持续时间是毫秒(毫秒)。

在Linux(和Mac)上

import os
duration = 1  # second
freq = 440  # Hz
os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % (duration, freq))

要使用此示例,必须安装sox...

在Debian/Ubuntu/LinuxMint上,您需要在终端中运行:

sudo apt install sox

这是Macport的方法...运行这是您的终端:

sudo port install sox

在Mac上

如果你在终端上使用Mac,也许在Windows上也能做同样的事情,但我只知道Mac的情况:

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

在Linux上

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

您需要安装speech-dispatcherUbuntu中的包(或其他发行版上的相应包):

sudo apt install speech-dispatcher

赞0评论0收藏0分享

在Windows上 import winsound duration = 1000 # millisecond freq = 440 # Hz winsound.Beep(freq, duration) 其中,FREQ是频率(以赫兹为单位),而持续时间是毫秒(毫秒)。 在L...

用户回答回答于 2018-03-012018-03-01 17:11:16

 

def beep():
    print "\a"
beep()

在Windows中,可以在末尾放:

import winsound
winsound.Beep(500,1000)

where 500 is the frequency in Herz
      1000 is the duration in miliseconds
posted on   一杯明月  阅读(932)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2021-05-09 木心的话
2019-05-09 matlab画矩形和matlab画圆
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示