Sound#
Introduction#
The VEX AIM Coding Robot’s sounds allow users to play built-in sounds, custom audio files, and musical notes. It also includes controls for stopping sounds and detecting if audio is currently playing. Below is a list of all available methods:
Actions – Play or stop sounds.
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 – Check sound status.
is_active – Returns whether a sound is currently playing.
Actions#
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.
Usage:
robot.sound.play(sound, volume)
Parameter |
Description |
---|---|
|
One of the built-in sound options listed below. |
|
Optional. The volume for the sound, as an integer from 0 to 100 percent. The default is 50 percent. |
Built-In Sounds |
Play Sound |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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.
Usage:
robot.sound.play_file(file, volume)
Parameter |
Description |
---|---|
|
One of the custom sound files uploaded by the user, from |
|
Optional. The volume for the sound, as an integer from 0 to 100 percent. The default is 50 percent. |
# 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.
Usage:
robot.sound.play_note(note, length, volume)
Parameter |
Description |
---|---|
|
The musical pitch to play, written as a string (e.g., |
|
The duration of the note, given as an integer in milliseconds. |
|
Optional. The volume of the note, as an integer from 0 to 100 percent. The default is 50 percent. |
# 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.
Usage:
robot.sound.stop()
Parameters |
Description |
---|---|
This method has no parameters. |
# Cut a sound off after 1 second
robot.sound.play(ACT_SILLY)
wait(1, SECONDS)
robot.sound.stop()
Getters#
is_active#
is_active
returns a Boolean indicating whether a sound is currently playing.
True
– A sound is currently playingFalse
– No sound is playing
Usage:
robot.sound.is_active()
Parameters |
Description |
---|---|
This method has no parameters. |
# Play tada after cheer finishes
robot.sound.play(CHEER)
while robot.sound.is_active():
wait(10, MSEC)
robot.sound.play(TADA)