Speaker API

Functionspeaker.playNote
Play a note with the given volume and pitch.

The instrument name corresponds to those provided by Note Blocks. It may be one of the following strings: base, basedrum, bell, chime, flute, guitar, hat, snare orxylophone.

Volume may be any number between 0 and 3 inclusive. 1 is the default, with 3 being the volume of a normal note block. Like note blocks, a higher volume does not imply a louder sound, merely that it can be heard further away.

The pitch may be a number between 0 and 24 inclusive, defaulting to 1. This represents the number of times one has right-clicked a noteblock. 0 representing F♯ and 24 representing F♯ 2 octaves higher.

This will return true if the note could be played or false if too many notes have been played in a single tick.
Syntax speaker.playNote(
  • instrument : string
  • volume? : number
  • pitch? : number
)
Returns boolean success
Part of CC:Tweaked (source)
API speaker
ExamplePlay a note
Play a note.
Code
<nowiki>
local speaker = peripheral.find("speaker")
speaker.playNote("guitar")
    </nowiki>
Functionspeaker.playSound
Play a sound with the given volume and pitch.

The sound name corresponds to a resource name in sound.json file. For instance minecraft:entity.player.levelup is the sound one hears when leveling up.

Like .playNote, the volume may be any value between 0 and 3 defaulting to 1.

The pitch argument is slightly different. Instead this may be any value between 0 and 2, with a larger value representing a higher pitch. One may convert from .playNote to .playSound pitches with the following equation: 2 ^ ((pitch - 12) / 12).

This will return true if the sound could be played or false if too many sounds were played in a single tick.
Syntax speaker.playSound(
  • name : string
  • volume? : number
  • pitch? : number
)
Returns boolean success
Part of CC:Tweaked (source)
API speaker
ExamplePlay a sound
Play a sound.
Code
<nowiki>
local speaker = peripheral.find("speaker")
speaker.playSound("minecraft:entity.player.levelup")
    </nowiki>
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.