聲音#
介紹#
VEX AIM 編程機器人的聲音功能可讓使用者播放內建聲音、自訂音訊檔案和音符。它還包含用於停止聲音和偵測目前是否正在播放音訊的控制功能。
以下是所有方法的清單:
操作-播放或停止聲音。
Getter — 檢查聲音狀態。
is_active— 傳回目前是否正在播放聲音。
行動#
play#
play 會以指定的音量百分比播放機器人內建的某個聲音。由於這是一種非等待方法,機器人會播放內建聲音後立即執行下一個命令,而無需等待其播放完畢。
用法:
robot.sound.play(sound, volume)
範圍 |
描述 |
|---|---|
|
下面列出的內建聲音選項之一。 |
|
可選。音量大小,取值範圍為 0% 到 100% 的整數。預設值為 50%。 |
內建聲音 |
播放聲音 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Play cheer
robot.sound.play(CHEER)
# Play cheer at full volume
robot.sound.play(CHEER, 100)
# Wait until sound is finished to move
robot.sound.play(ACT_HAPPY)
while robot.sound.is_active():
wait(50, MSEC)
robot.turn_to(180)
play_file#
play_file 播放使用者上傳的自訂聲音。由於這是一個非等待方法,機器人會在播放自訂聲音後立即執行下一個命令,而無需等待其播放完成。
用法:
robot.sound.play_file(file, volume)
範圍 |
描述 |
|---|---|
|
使用者上傳的自訂聲音檔案之一,編號從 |
|
可選。音量大小,取值範圍為 0% 到 100% 的整數。預設值為 50%。 |
# Play an uploaded sound
robot.sound.play_file(SOUND1)
# Play an uploaded sound at full volume
robot.sound.play_file(SOUND1, 100)
# Wait until sound is finished to move
robot.sound.play_file(SOUND1)
while robot.sound.is_active():
wait(50, MSEC)
robot.turn_to(180)
play_note#
play_note 會播放特定音符,持續時間為特定毫秒數。由於這是一種非等待方法,機器人會播放特定音符後立即執行下一個命令,而無需等待其結束。
用法:
robot.sound.play_note(note, length, volume)
範圍 |
描述 |
|---|---|
|
要播放的音高,以字符串形式书写(例如 |
|
音符的持續時間,以毫秒為單位的整數表示。 |
|
可選。音量大小,取值範圍為 0% 到 100% 的整數。預設值為 50%。 |
# Play C5 for 2 seconds
robot.sound.play_note("C5", 2000)
# Play C5 for 2 seconds at full volume
robot.sound.play_note("C5", 2000, 100)
# Wait until note is finished to move
robot.sound.play_note("C6", 1000)
while robot.sound.is_active():
wait(50, MSEC)
robot.turn_to(180)
stop#
stop 停止目前正在播放的聲音。
用法:
robot.sound.stop()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Cut a sound off after 1 second
robot.sound.play(ACT_SILLY)
wait(1, SECONDS)
robot.sound.stop()
獲取器#
is_active#
is_active 傳回布林值,指示目前是否正在播放聲音。
True— 目前正在播放聲音False— 沒有聲音播放
用法:
robot.sound.is_active()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Play tada after cheer finishes
robot.sound.play(CHEER)
while robot.sound.is_active():
wait(10, MSEC)
robot.sound.play(TADA)