Python中的 Beeply 模块
Python中的beeply模块将帮助您使用计算机特有的哔声来制作音符。它完全是用Python编写的(准确地说是使用winsound和time模块)
由于此模块是使用winsound编写的,因此它只能在 Windows 上运行。该模块仅包含一个类和一个方法,即beeply类和head()方法。
安装:
pip install beeply
下面是一些描述 beeply 模块使用的示例:
示例 1
音阶是音乐的音调基础。它是一组可以从中产生旋律的音调。下划线_用于声音的音阶如果给出_ ,它的音阶将为 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")
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")
输出:
它将在音阶 1 和音阶 0 处产生 A 音调,您可以发出 2 声哔哔声,每次 0.9 秒。
示例 2
蟒蛇3
# 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")
输出:
如果您在创建对象时(即在实例化时)将持续时间作为参数,那么如果没有具体给出,它也将是听函数的默认持续时间。