当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python Beeply用法及代码示例

嘟嘟地python 中的模块将帮助您使用计算机特有的蜂鸣声来生成音符。它完全是用 python 编写的(使用温声时间准确地说是模块)

由于该模块是使用编写的温声,它仅适用于 Windows。该模块仅包含一个类和一个方法,即嘟嘟地类和head()方法。

安装:

pip install beeply

下面是一些说明 beeply 模块使用的示例:

示例 1

音阶是音乐的音调基础。它是一组可以产生旋律的音调。下划线_用于声音的音阶 If_给定,它的规模将为 1

用法

obj = notes.beeps(duration in ms)

beeps is class, it’s constructor takes an  arg ( optional ) of time duration if not given it will take it as 900 ms

If given make sure it’s in ms.

obj.hear(self,duration in ms)

Python3


# import required module
from beeply.notes import *
# Creating obj of beeply
# It's has another arg of duration
# By default it's 900 ms
a = beeps()
# It's has another arg of duration
# By default it's 900 ms
a.hear('A_')
print("Done ")
# To acknowledge us
a.hear("A")

输出:

它将在音阶 1 和音阶 0 处发出 A 音,您可以发出 2 声蜂鸣声,每次 0.9 秒。

示例 2

Python3


# import module
from beeply.notes import *
# create object with duration as argument
a = beeps(1154)
# It will sound for 1154 ms
a.hear('A_')
# But if it is
a.head('A_', 5000)
# Then it is for 5 sec i.e. 5000ms
print("Done")

输出:

如果您在创建对象时(即实例化时)将持续时间作为参数给出,那么如果没有具体给出,它也将是hear函数的默认持续时间。



相关用法


注:本文由纯净天空筛选整理自akshaypawar4大神的英文原创作品 Beeply module in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。