Sonido#

Introducción#

El controlador de drones VEX AIR permite 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 y detener sonidos

  • play — Plays a built-in sound from a predefined list.

  • play_file — Plays a user-uploaded sound.

  • play_note — Plays a musical note with a specified pitch, octave, and duration.

  • stop — Stops any currently playing sound. Getters - Get Status of Sounds

  • is_active — Checks if a sound is currently playing.

Comportamiento#

play#

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

Uso:

controller.sound.play(sound, volume)

Parámetro

Descripción

sound

Una de las opciones de sonido integradas que se enumeran a continuación.

volume

Opcional. El volumen del sonido, como un número entero del 0 al 100 %. El valor predeterminado es 50 %.

Sonidos incorporados

Reproducir sonido

SUCCESS

FAULT

SENSING

DETECTED

OBSTACLE

LOOPING

COMPLETE

PAUSE

RESUME

SEND

RECEIVE

# Play the looping sound.
controller.sound.play(LOOPING)

# Play the looping sound at full volume.
controller.sound.play(LOOPING, 100)

# Play the looping sound. 
# Wait until the sound is finished before taking off.
controller.sound.play(LOOPING)
while controller.sound.is_active():
    wait(50, MSEC)
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.land()

play_file#

play_file plays a custom sound loaded by the user at a specified volume percentage. Since this is a non-waiting method, the drone plays the custom sound and moves to the next command without waiting for it to finish.

Uso:

controller.sound.play_file(file, volume)

Parámetro

Descripción

file

One of the custom sound files uploaded by the user, from SOUND1 to SOUND10. The sound number aligns with the number shown in the AIR Control Panel.

volume

Opcional. El volumen del sonido, como un número entero del 0 al 100 %. El valor predeterminado es 50 %.

# Upload a sound file in VEXcode.
# Play the custom sound.
controller.sound.play_file(SOUND1)

# Upload a sound file in VEXcode.
# Play the custom sound at full volume.
controller.sound.play_file(SOUND1, 100)

# Play the custom sound sound. 
# Wait until the sound is finished before taking off.
controller.sound.play_file(SOUND1)
while controller.sound.is_active():
    wait(50, MSEC)
drone.take_off(climb_to=500)
wait(1, SECONDS)
drone.land()

play_note#

play_note plays a specific note for a specific duration. Since this is a non-waiting method, the drone plays the specific note and moves to the next command without waiting for it to finish.

Uso:

controller.sound.play_note(note, duration, volume)

Parámetro

Descripción

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.

duration

La duración de la nota, expresada como un número entero en milisegundos.

volume

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
controller.sound.play_note("C5", 2000)

# Play C5 for 2 seconds at full volume
controller.sound.play_note("C5", 2000, 100)

# Play a short tune.
controller.sound.play_note("C5", 1000)
while controller.sound.is_active():
    wait(50, MSEC)
controller.sound.play_note("D5", 1000)
while controller.sound.is_active():
    wait(50, MSEC)
controller.sound.play_note("E5", 250)
while controller.sound.is_active():
    wait(50, MSEC)

stop#

stop stops a sound that is currently playing.

Uso:

controller.sound.stop()

Parámetros

Descripción

Este método no tiene parámetros.

# Upload a sound 10 seconds or greater in VEXcode.
# Stop the sound while it is playing.
controller.sound.play_file(SOUND1)
wait(6, SECONDS)
controller.sound.stop()

Captadores#

is_active#

is_active returns whether the drone is currently playing a sound as a Boolean.

  • True — A sound is currently playing

  • False — No sound is playing

Usage:
controller.sound.is_active()

Parámetros

Descripción

Este método no tiene parámetros.

# Display text once a sound starts playing
controller.sound.play(LOOPING)
while not controller.sound.is_active():
    wait(50, MSEC)
print("I hear the sound!")