声音#
介绍#
VEX EXP 大脑可以通过其内置扬声器使用声音类别中的方法产生音频,播放预加载的声音效果或音符。
对于以下示例,构造的 Brain 包含对 Sound 方法的访问,并且在本 API 文档中所有后续示例中引用这些方法时都将使用它。
以下是所有方法的列表:
动作——播放来自大脑的声音。
play_sound— Play a preset sound from the Brain.play_note— Play a musical note from the Brain.
行动#
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)