Ήχος#
Εισαγωγή#
Το χειριστήριο VEX AIR Drone επιτρέπει στους χρήστες να αναπαράγουν ενσωματωμένους ήχους, προσαρμοσμένα αρχεία ήχου και μουσικές νότες. Περιλαμβάνει επίσης χειριστήρια για τη διακοπή ήχων και την ανίχνευση της αναπαραγωγής ήχου.
Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:
Ενέργειες - Αναπαραγωγή και διακοπή ήχων
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 - Λήψη Κατάστασης Ήχων
is_active— Checks if a sound is currently playing.
Ενέργειες#
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.
Χρήση:
controller.sound.play(sound, volume)
Παράμετρος |
Περιγραφή |
|---|---|
|
Μία από τις ενσωματωμένες επιλογές ήχου που αναφέρονται παρακάτω. |
|
Προαιρετικό. Η ένταση του ήχου, ως ακέραιος αριθμός από 0% έως 100%. Η προεπιλογή είναι 50%. |
Ενσωματωμένοι ήχοι |
Αναπαραγωγή ήχου |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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.
Χρήση:
controller.sound.play_file(file, volume)
Παράμετρος |
Περιγραφή |
|---|---|
|
One of the custom sound files uploaded by the user, from |
|
Προαιρετικό. Η ένταση του ήχου, ως ακέραιος αριθμός από 0% έως 100%. Η προεπιλογή είναι 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.
Χρήση:
controller.sound.play_note(note, duration, volume)
Παράμετρος |
Περιγραφή |
|---|---|
|
The musical pitch to play, written as a string (e.g., |
|
Η διάρκεια της νότας, δίνεται ως ακέραιος αριθμός σε χιλιοστά του δευτερολέπτου. |
|
Προαιρετικό. Η ένταση του ήχου της νότας, ως ακέραιος αριθμός από 0% έως 100%. Η προεπιλογή είναι 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.
Χρήση:
controller.sound.stop()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# 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()
Αποκτητές#
is_active#
is_active returns a Boolean indicating whether the drone is currently playing a sound.
True— A sound is currently playingFalse— No sound is playing
Usage:
controller.sound.is_active()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# 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!")