Skip to content

Speakers

Overview

The Speakers section of the cee API provides methods for controlling audio output on a ComputerCraft computer or peripheral device. These functions allow programs to play musical notes, generate sounds, and control speaker behavior using either global cee. prefixed calls or object-oriented method syntax.

Audio is generated through a simulated sound synthesis system that supports multiple simultaneous tones and complex note sequences. The speaker system integrates with the cee framework for unified hardware interaction across various devices.

Calling Conventions / Prefixes

Methods in this section can be invoked using either of two styles:

  • Global prefix: Use cee. followed by the method name. lua cee.speaker.playNote("c4", 440, 1)

  • Object-oriented syntax: Call methods directly on a speaker object returned by cee.getSpeaker() or similar discovery functions. lua local speaker = cee.getSpeaker() speaker.playNote("c4", 440, 1)

If you're unsure which style to use, it is generally safe to default to the global prefix (cee.) for maximum compatibility and clarity.

API Reference Table

Signature Arguments & Types Description
speaker.playNote(inst, v, p) inst (string), v (number), p (number) Note block instrument, pitch 0-24.
speaker.playSound(name, v, p) name (string), v (number), p (number) Any registered sound event.
speaker.playAudio(pcm, v) pcm (table), v (number) Raw 8-bit PCM at 48kHz.
speaker.stop() None Stop whatever is playing.
speaker.hasPower() None Gate is up (>= 60V).
speaker.getVoltageFactor() None 0-1: how loud this rail allows.
speaker.getStatus() None Why it is not playing, as a table.
speaker.speakPCM(tbl, v) tbl (table), v (number) 16-bit samples, 48kHz mono.
speaker.speakOgg(bytes, v) bytes (string/table), v (number) An Ogg Vorbis file.
speaker.speakMp3(bytes, v) bytes (string/table), v (number) An MP3 file, if a decoder is installed.
speaker.speakWav(bytes, v) bytes (string/table), v (number) A WAV, AIFF or AU file.
speaker.speakAudio(bytes, v) bytes (string/table), v (number) Any of the above, sniffed.
speaker.speakFile(bytes, v) bytes (string/table), v (number) The same as speakAudio.
speaker.speakPacked(bytes, v) bytes (string/table), v (number) The same as speakAudio.
speaker.speakStop() None Stop the high-quality path.
speaker.speakIsPlaying() None A payload is still being sent.
speaker.speakSampleRate() None 48000.
speaker.speakMaxBytes() None Largest file it will accept.
speaker.speakMaxSamples() None Largest speakPCM table.
speaker.speakSupportedFiles() None Formats it will try to decode.
speaker.speakOpen(fmt, v) fmt (string), v (number) Start feeding a track in pieces.
speaker.speakAppend(bytes) bytes (string) Add the next piece.
speaker.speakEnd() None Play what has been fed.
speaker.speakBuffered() None Bytes fed so far.
speaker.speakMaxSessionBytes() None Largest track fed this way.

Lua Code Examples

Play a single note

local spk = cee.getSpeaker(1)
if spk then
    spk.playNote("harp", 12, 1)
end

Play high-quality audio / file

local spk = cee.getSpeaker(1)
if spk then
    local file = fs.open("audio.ogg", "rb")
    local data = file.readAll()
    file.close()

    spk.speakOgg(data, 1.0)
end

Stop all sounds

local spk = cee.getSpeaker(1)
if spk then
    spk.stop()
    spk.speakStop()
    print("All sounds stopped.")
end