pxt-calliope/docs/reference/music/play-sound-effect.md
Juri Wolf 5f7a8e5301
Updates for V4 (#197)
* update yotta defaults for 16kb devices

* refactor deprecated blocks

* updates for button events

* update button events

* update refference

* update docs

* update docs

* update button event blocks

* update docs

* update block id
2022-08-10 09:36:19 -07:00

1.5 KiB

play Sound Effect

Play a sound that is generated from a sound expression.

music.playSoundEffect("", SoundExpressionPlayMode.UntilDone)

This will play a Sound object created from a sound expression. The sound will play for the duration that was set in the sound expression. The sound can play on the speaker or at a pin that is set for sound output.

Your program can wait for the sound to finish before it runs its next step. To do this, set the play mode to until done. Otherwise, use background for the program to continue immediately after the sound starts.

~ reminder

Works with micro:bit V2

works with micro:bit V2 only image

This block requires the micro:bit V2 hardware. If you use this block with a micro:bit v1 board, you will see the 927 error code on the screen.

~

Parameters

  • sound: a string that is the sound expression for the sound you want to play.
  • mode: the play mode for the sound, either until done or background.

Example

Play a sound from a sound expression for 1 second.

music.playSoundEffect(music.createSoundEffect(WaveShape.Sine, 2000, 0, 1023, 0, 1000, SoundExpressionEffect.None, InterpolationCurve.Linear), SoundExpressionPlayMode.UntilDone)

See also

create sound effect, built-in sound effect, analog set pitch pin