rednode API - v0.50.0
    Preparing search index...

    Variable audioConst

    audio: {
        event(
            name: string,
            options?: { on?: "player" | "none" },
        ): Promise<PostedEvent>;
        eventSounds(
            event: string | number,
        ): Promise<{ event: number; sounds: number[] }>;
        play(sound: string, options?: PlayOptions): Promise<Sound>;
        playGame(
            sound: number | { event: string | number; variation?: number },
            options?: PlayOptions,
        ): Promise<GameSound>;
        playing(): Promise<SoundInfo[]>;
        searchSounds(
            query: string,
            options?: { limit?: number },
        ): Promise<SoundSearch>;
        stopAll(options?: { fadeOut?: number }): Promise<void>;
        trace(onTrace: (batch: TraceBatch) => void): Promise<() => Promise<void>>;
    } = ...

    Sound for packages: play your own audio files in the game.

    Type Declaration

    • event: function
      • Posts one of the game's sound events by name through the game's AudioSystem.Play: the game plays it through its own mix, with the event's own logic (variations, effects). The game must know the name; an unknown one plays nothing.

        By default the event plays on V, so a positional sound (footsteps, a weapon, a door) is heard where the player stands. { on: "none" } posts it with no entity, as the game plays UI sounds. Some events loop until stopped: call stop() on what this returns.

        Experimental (Sound Tools): its shape may change.

        Parameters

        • name: string
        • options: { on?: "player" | "none" } = {}

        Returns Promise<PostedEvent>

        import { audio } from "rednode";

        const e = await audio.event("amb_int_custom_megabuilding_01_ventilation");
        setTimeout(() => e.stop(), 5000);
    • eventSounds: function
      • The sound ids of an event's recordings (its variations), by its name or Wwise id, from the game's sound index: what audio.playGame picks from with { event }. Empty for a stop event, or one whose sound lives in a Wwise bank.

        Experimental (Sound Tools): its shape may change.

        Parameters

        • event: string | number

        Returns Promise<{ event: number; sounds: number[] }>

        import { audio } from "rednode";

        const { sounds } = await audio.eventSounds("lcm_fs_bare_feet_concrete_walk");
        console.log(`${sounds.length} footstep variations`);
    • play: function
      • Plays a sound: an id from the manifest's "sounds", a file's path in your package's folder, or (REDnode 0.44.0 or later) a full path in your package's data folder, pkg.dataDir, for sounds made while the package runs, such as spoken lines. Resolves once the engine has it, with a Sound; the file loads in the background and starts as soon as it is ready. The file is read at each play, so a file written again plays its new sound.

        Parameters

        Returns Promise<Sound>

        import { audio, pkg } from "rednode";
        import fs from "node:fs";
        import path from "node:path";

        const file = path.join(pkg.dataDir, "line-1.wav");
        fs.writeFileSync(file, wavBytes); // made by the package
        await audio.play(file, { category: "dialogue" });
    • playGame: function
      • Plays one of the game's own sound effects through REDnode's engine like a file of your package: the raw recording, without the game's effects or position, so you hear it wherever the sound happens in the game. The game's archives store it as Opus; it is decoded on first use. An archive in archive/pc/mod that carries the sound index wins over the game's own, so a hot-swapped sound plays its new version.

        Give a sound id (one variation, as the game's sfx_container.opusinfo lists it), or { event } with an event's name or Wwise id to play one of that event's recordings: variation (from 0) picks one, otherwise they come in turn. Stop events, and events whose sound lives in a Wwise bank, have no recordings there and reject.

        Experimental (Sound Tools): its shape may change.

        Parameters

        • sound: number | { event: string | number; variation?: number }
        • Optionaloptions: PlayOptions

        Returns Promise<GameSound>

        import { audio } from "rednode";

        const s = await audio.playGame(746693166); // a katana sound
        await s.ended;
        const step = await audio.playGame({ event: "lcm_fs_bare_feet_concrete_walk" });
        console.log(`variation ${step.variation + 1} of ${step.variations}`);
    • playing: function
    • searchSounds: function
      • Searches the game's sound events: words of a name (all must appear in the event's name or tags, in any order), an event id, or a sound id (the events that play that recording). The catalogue holds every event the game's sound index has recordings for and every event REDbridge's list names (WolvenKit's, game 1.6); names arrive a few seconds after the first search while REDbridge starts, so names says "loading" until then, and "none" without REDbridge, when only ids match.

        Experimental (Sound Tools, SP3): its shape may change.

        Parameters

        • query: string
        • options: { limit?: number } = {}

        Returns Promise<SoundSearch>

        import { audio } from "rednode";

        const { results, total } = await audio.searchSounds("katana draw");
        for (const e of results) console.log(`${e.name ?? e.event}: ${e.sounds.length} recordings`);
    • stopAll: function
      • Stops every sound of your package, fading out over fadeOut milliseconds.

        Parameters

        • Optionaloptions: { fadeOut?: number }

        Returns Promise<void>

    • trace: function
      • Listens to the game's sounds: onTrace gets, about ten times a second, the events the game posted to its audio engine (Wwise) and the sounds it loaded. Resolves once the trace runs, with a function that stops it. The trace also stops when your package stops.

        Experimental (Sound Tools, SP1): its shape may change.

        Parameters

        Returns Promise<() => Promise<void>>

        import { audio } from "rednode";

        const stop = await audio.trace(({ posts, loads }) => {
        for (const p of posts) console.log(`event ${p.name ?? p.event} on object ${p.object}`);
        for (const l of loads) console.log(`sound ${l.sound} loaded`);
        });
        setTimeout(stop, 10_000);
    import { audio } from "rednode";

    const alarm = await audio.play("sounds/alarm.ogg", { loop: true, fadeIn: 500 });
    setTimeout(() => alarm.stop({ fadeOut: 1000 }), 5000);
    const { why } = await alarm.ended; // "stopped"