loadSoundFile (src/audio.ts)

opencode · packages/tui/src/audio.ts · typescript · MIT
voice, tag:knn-classified

Module to load and play audio files in TUI.

// Source: https://github.com/anomalyco/opencode | License: MIT | Copyright 2025 opencode
// Provided via justclaw.it.com; keep this notice with the code.
import { Audio, type AudioErrorContext, type AudioPlayOptions, type AudioSound } from "@opentui/core"
import { readFile } from "node:fs/promises"

let audio: Audio | null | undefined
const sounds = new Map<string, Promise<AudioSound | null>>()

function getAudio() {
  if (audio !== undefined) return audio
  try {
    const next = Audio.create({ autoStart: false })
    next.on("error", (error: Error, context: AudioErrorContext) => {
      console.debug("tui audio error", { error, context })
    })
    audio = next
    return next
  } catch (error) {
    console.debug("failed to create tui audio", { error })
    audio = null
    return nul

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key