声音#
介绍#
The VEX IQ (2nd gen) Brain can produce audio through its built-in speaker using methods from the Sound category, which play preloaded sound effects or musical notes.
对于以下示例,构造的 Brain 包含对 Sound 方法的访问权限,并且在本 API 文档的所有后续示例中引用这些方法时都将使用它。
Below is a list of all methods:
Actions — Play sounds from the Brain.
play_sound— Play a preset sound from the Brain.play_note— Play a musical note from the Brain.sound_off— Stop the currently playing sound.
行动#
play_sound#
play_sound plays one of the brain’s built-in sounds.
Usage:
brain.play_sound(sound)
范围 |
描述 |
|---|---|
|
从大脑播放的指定声音。 |
声音名称 |
播放声音 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Play the TADA sound from the brain
brain.play_sound(SoundType.TADA)
play_note#
play_note plays a specific note for a specific duration in milliseconds.
Usage:
brain.play_note(octave, note, duration)
参数 |
描述 |
|---|---|
|
Either the low or high octave:
|
|
The note to play:
|
|
可选。音符播放的时长(以毫秒为单位),最长为 500 毫秒。如果未提供时长,则默认时长为 500 毫秒。 |
# Play a quarter note C and half note F
brain.play_note(4, 0, 250)
brain.play_note(4, 3, 500)
sound_off#
sound_off stops a sound that is currently playing.
Usage:
brain.sound_off()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Stop any sound that is playing on the brain
brain.play_sound(SoundType.POWER_DOWN)
wait(0.2, SECONDS)
brain.sound_off()