Something went wrong. Try again.
Plays short audio files such as a terminal bell through PipeWire on Linux and WASAPI on Windows.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! Plays short audio files through the system's sound output, for//! applications that want a sound played and nothing more.//!//! A `Sound` is an audio file decoded once into memory; a `Player` is the//! application's connection to the system's sound output, through which//! Sounds are played.//!//! ```zig//! var bell = try chime.Sound.load(gpa, io, std.Io.Dir.cwd(), "bell.flac", .{});//! defer bell.deinit(gpa);//!//! var player = try chime.Player.init(gpa, io, .{ .name = "harrier" });//! defer player.deinit();//! defer player.release(&bell);//!//! _ = try player.play(&bell, 0.8);//! ```
const std = @import("std");const builtin = @import("builtin");
comptime { switch (builtin.os.tag) { .linux, .windows => {}, else => @compileError("zig-chime has no sound output for " ++ @tagName(builtin.os.tag) ++ " yet; Linux and Windows are supported"), }}
pub const Sound = @import("Sound.zig");pub const Format = Sound.Format;pub const detect = @import("decode.zig").detect;
pub const PlayerWith = @import("player.zig").PlayerWith;pub const Outcome = @import("player.zig").Outcome;/// The Player for the platform being built for.pub const Player = PlayerWith(backend.native);
/// Where the sound goes. `native` is the platform's own; `Null` plays nothing/// and records what it was asked, for testing an application without a sound/// device.pub const backend = struct { pub const native = switch (builtin.os.tag) { .linux => @import("backend/pipewire.zig"), .windows => @import("backend/wasapi.zig"), else => unreachable, }; pub const Null = @import("backend/null.zig");};
test { // Compiled for the target even though the tests drive `backend.Null`, so // that a check build for Windows type-checks the WASAPI backend. std.testing.refAllDecls(backend.native); std.testing.refAllDecls(Player); _ = Sound; _ = @import("decode.zig"); _ = @import("player.zig");}