Sonido#
Introducción#
Los sonidos del robot de codificación VEX AIM permiten reproducir sonidos integrados, archivos de audio personalizados y notas musicales. También incluye controles para detener sonidos y detectar si se está reproduciendo audio. A continuación, se muestra una lista de todos los métodos disponibles:
Acciones: Reproducir o detener sonidos.
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 – Verifica el estado del sonido.
is_active– Returns whether a sound is currently playing.
Comportamiento#
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.
Uso:
robot.sound.play(sound, volume)
Parámetro |
Descripción |
|---|---|
|
Una de las opciones de sonido integradas que se enumeran a continuación. |
|
Opcional. El volumen del sonido, como un número entero del 0 al 100 %. El valor predeterminado es 50 %. |
Sonidos incorporados |
Reproducir sonido |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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.
Uso:
robot.sound.play_file(file, volume)
Parámetro |
Descripción |
|---|---|
|
One of the custom sound files uploaded by the user, from |
|
Opcional. El volumen del sonido, como un número entero del 0 al 100 %. El valor predeterminado es 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.
Uso:
robot.sound.play_note(note, length, volume)
Parámetro |
Descripción |
|---|---|
|
The musical pitch to play, written as a string (e.g., |
|
La duración de la nota, expresada como un número entero en milisegundos. |
|
Opcional. El volumen de la nota, como un número entero del 0 al 100 %. El valor predeterminado es 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.
Uso:
robot.sound.stop()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Cut a sound off after 1 second
robot.sound.play(ACT_SILLY)
wait(1, SECONDS)
robot.sound.stop()
Captadores#
is_active#
is_active returns a Boolean indicating whether a sound is currently playing.
True– A sound is currently playingFalse– No sound is playing
Uso:
robot.sound.is_active()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Play tada after cheer finishes
robot.sound.play(CHEER)
while robot.sound.is_active():
wait(10, MSEC)
robot.sound.play(TADA)