声音#
介绍#
VEX IQ(第二代)大脑可以通过其内置扬声器使用声音类别中的方法产生音频,播放预加载的声音效果或音符。
对于以下示例,构造的 Brain 包含对 Sound 方法的访问权限,并且在本 API 文档的所有后续示例中引用这些方法时都将使用它。
以下是所有方法的列表:
动作——播放来自大脑的声音。
play_sound— 播放大脑内置的声音效果之一。play_note— 从大脑中播放一个音符。sound_off— 停止当前正在播放的声音。
行动#
play_sound#
play_sound 播放大脑内置的声音之一。
Usage:
brain.play_sound(sound)
范围 |
描述 |
|---|---|
|
从大脑播放的指定声音。 |
声音名称 |
播放声音 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Play the TADA sound from the brain
brain.play_sound(SoundType.TADA)
play_note#
play_note 播放特定音符,持续特定时长。
Usage:
brain.play_note(octave, note, duration)
参数 |
描述 |
|---|---|
|
可以是低音或高音: |
|
演奏音符:
|
|
可选。音符播放的时长(以毫秒为单位),最长为 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 停止当前正在播放的声音。
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()