Ήχος#

Εισαγωγή#

Οι ήχοι του ρομπότ κωδικοποίησης 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

Προαιρετικό. Η ένταση του ήχου, ως ακέραιος αριθμός από 0% έως 100%. Η προεπιλογή είναι 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

Προαιρετικό. Η ένταση του ήχου, ως ακέραιος αριθμός από 0% έως 100%. Η προεπιλογή είναι 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

Η διάρκεια της νότας, δίνεται ως ακέραιος αριθμός σε χιλιοστά του δευτερολέπτου.

volume

Προαιρετικό. Η ένταση του ήχου, ως ακέραιος αριθμός από 0% έως 100%. Η προεπιλογή είναι 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)