声音#

介绍#

VEX AIM 编程机器人的声音功能允许用户播放内置声音、自定义音频文件和音符。它还包含用于停止声音和检测当前是否正在播放音频的控制功能。

以下是所有方法的列表:

操作——播放或停止声音。

  • play — Plays a built-in sound effect.

  • play_file — Plays a user-uploaded custom sound.

  • play_note — Plays a musical note for a set duration.

  • stop — Stops any currently playing sound.

Getter — 检查声音状态。

  • is_active — Returns whether a sound is currently playing.

行动#

play#

play plays one of the robot’s built-in sounds at a specified volume percentage. Since this is a non-waiting method, the robot plays the built-in sound and moves to the next command without waiting for it to finish.

用法:

robot.sound.play(sound, volume)

范围

描述

sound

下面列出的内置声音选项之一。

volume

Optional. The volume for the sound, as a whole number from 0% to 100%. The default is 50%.

内置声音

播放声音

ACT_ANGRY

ACT_EXCITED

ACT_HAPPY

ACT_SAD

ACT_SILLY

BLINKER

BRAKES

CHEER

CHIRP

COMPLETE

CRASH

DETECTED

DOORBELL

FAIL

FLOURISH

HUAH

LOOPING

MOVE_FORWARD

MOVE_REVERSE

OBSTACLE

PAUSE

PICKUP

RECEIVE

RESUME

SENSING

SEND

SPARKLE

TADA

TURN_LEFT

TURN_RIGHT

# 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 plays a custom sound uploaded by the user. Since this is a non-waiting method, the robot plays the custom sound and moves to the next command without waiting for it to finish.

用法:

robot.sound.play_file(file, volume)

范围

描述

file

One of the custom sound files uploaded by the user, from SOUND1 to SOUND10. The sound number matches the number shown in the AIM control panel.

volume

Optional. The volume for the sound, as a whole number from 0% to 100%. The default is 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 plays a specific note for a specific duration in milliseconds. Since this is a non-waiting method, the robot plays the specific note and moves to the next command without waiting for it to finish.

用法:

robot.sound.play_note(note, length, volume)

范围

描述

note

The musical pitch to play, written as a string (e.g., C5, A#6). Valid notes are A through G (with optional # for sharps) across octaves 5 to 8.

length

The duration of the note, given as a whole number in milliseconds.

volume

Optional. The volume for the sound, as a whole number from 0% to 100%. The default is 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 stops a sound that is currently playing.

用法:

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 returns a Boolean indicating whether a sound is currently playing.

  • True — A sound is currently playing

  • False — No sound is playing

用法:

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)