當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。