System Audio Capture with crystal-audio

VerifiedCaution

Capture system audio (what the computer is playing) using crystal-audio. Covers ProcessTap (macOS 14.2+), ScreenCaptureKit fallback (macOS 13.0+), and the low-level SystemAudioCapture API for real-time processing.

Sby Skills Guide Bot
DevelopmentIntermediate
7/24/2026
Claude CodeCursorCodex
#macos#audio-capture#crystal-lang#realtime-audio#screencapturekit

Recommended for

Automated summary

Usage guide for the Crystal crystal-audio library to capture a Mac's system audio through ProcessTap (macOS 14.2+) or ScreenCaptureKit (macOS 13+).

Strengths

  • Automatic API selection based on macOS version, with exposed detection helpers (MacOS.process_tap?, screen_capture_kit?)
  • Covers both the high-level Recorder and the low-level SystemAudioCapture API for real-time processing
  • Explicit real-time safety rules (no allocation, no mutexes inside the callback)
  • Documents audio formats and simultaneous mic + system recording

Limitations

  • macOS only, no Windows or Linux support
  • The native ObjC extension section (system_audio_tap) is truncated and incomplete
  • The real-time callback imposes strict constraints (ring buffers, atomics) that beginners rarely master
When to use it

When writing Crystal code that records or analyzes in real time what the Mac is playing, including alongside the microphone.

When not to use it

If you target a platform other than macOS, or just need plain microphone capture without real-time processing.

Security analysis

Caution
Quality score80/100

The content is documentation for a legitimate audio-capture library and contains no destructive commands, obfuscated payloads, curl|sh installs, or secret exfiltration. The risk is moderate rather than low because it equips the agent with Bash/Write and instructs building programs that continuously record all system audio to disk, a surveillance-capable action that should stay user-initiated and permission-gated. Rated caution rather than risky due to absence of any malicious or unsafe directives.

Findings
  • •Skill is built around recording all system audio output, which is inherently privacy-sensitive (can capture calls, meetings, notifications) and writes raw audio to /tmp files.
  • •Declared allowed-tools include Bash, Write, and Edit with no explicit scoping guidance, so an agent could write/execute arbitrary Crystal code or overwrite files when following the examples.
  • •On macOS 13.0–14.1 the Screen Recording permission is requested; the skill correctly notes user consent, but agents should not enable this silently.
  • •No pinning/verification of the third-party 'crystal-audio' dependency before use.
How this analysis is made

Examples

Record system audio to WAV
Write a Crystal script using crystal-audio that records 30 seconds of system audio to /tmp/system_audio.wav and then stops.
Live RMS volume meter
Using CrystalAudio::SystemAudioCapture, write a Crystal program that prints the RMS volume of the system audio in the callback for 10 seconds.
Mic plus system recording
Create a Crystal recorder with RecordingSource::Both that saves system audio to /tmp/meeting_system.wav and microphone audio to /tmp/meeting_mic.wav.

name: system-audio description: | Capture system audio (what the computer is playing) using crystal-audio. Covers ProcessTap (macOS 14.2+), ScreenCaptureKit fallback (macOS 13.0+), and the low-level SystemAudioCapture API for real-time audio processing. allowed-tools: Read, Write, Edit, Glob, Grep, Bash version: "0.1.0"

System Audio Capture with crystal-audio

Overview

crystal-audio captures system audio — everything playing through the computer's speakers — using two macOS APIs selected automatically based on OS version:

| macOS Version | API | Permission Required | |---------------|-----|-------------------| | 14.2+ (Sonoma) | ProcessTap | None | | 13.0-14.1 (Ventura) | ScreenCaptureKit | Screen Recording |

Quick Start

require "crystal_audio"

rec = CrystalAudio::Recorder.new(
  source: CrystalAudio::RecordingSource::System,
  output_path: "/tmp/system_audio.wav"
)

rec.start
sleep 30.seconds
rec.stop

Output: stereo WAV, 48 kHz, 16-bit PCM.

Version Detection

The library detects macOS version at runtime:

CrystalAudio::MacOS.version
# => {major: 15, minor: 3, patch: 0}

CrystalAudio::MacOS.process_tap?
# => true on macOS 14.2+

CrystalAudio::MacOS.screen_capture_kit?
# => true on macOS 13.0+

Low-Level API: SystemAudioCapture

For real-time audio processing (visualization, streaming, analysis), use the SystemAudioCapture class directly:

require "crystal_audio"

tap = CrystalAudio::SystemAudioCapture.new

tap.start do |frames, frame_count, channels|
  # frames: Slice(Float32) — interleaved PCM (L, R, L, R, ...)
  # frame_count: UInt32 — number of sample frames
  # channels: UInt32 — channel count (typically 2)

  # Calculate RMS volume
  sum = 0.0_f64
  frames.each { |s| sum += s.to_f64 * s.to_f64 }
  rms = Math.sqrt(sum / frames.size)
  puts "Volume: #{(rms * 100).round(1)}%"
end

sleep 10.seconds
tap.stop

Real-Time Safety

The callback runs on a real-time audio thread. Inside the callback:

  • DO NOT allocate Crystal objects (no String.new, no Array.new, etc.)
  • DO NOT acquire mutexes or call Fiber.yield
  • DO write to pre-allocated buffers
  • DO use atomic operations for signaling
  • DO keep the callback as short as possible

For processing that requires allocations, copy data to a ring buffer and process on another thread.

Audio Format Details

| Property | Microphone | System Audio | |----------|-----------|--------------| | Sample Rate | 44,100 Hz | 48,000 Hz | | Channels | 1 (mono) | 2 (stereo) | | Bit Depth | 16-bit int | 32-bit float (callback) / 16-bit int (WAV) | | Buffer | ~185ms | ~10ms |

Recording Both Streams

rec = CrystalAudio::Recorder.new(
  source: CrystalAudio::RecordingSource::Both,
  output_path: "/tmp/meeting_system.wav",
  mic_output_path: "/tmp/meeting_mic.wav"
)

rec.start
# Both streams record simultaneously
# System: 48kHz stereo
# Mic: 44.1kHz mono
rec.stop

Permissions

macOS 14.2+ (ProcessTap)

No special permissions needed. ProcessTap captures audio directly from the audio server without screen recording access.

macOS 13.0-14.1 (ScreenCaptureKit)

Requires Screen Recording permission. The user will be prompted on first use. Add to your Info.plist:

<key>NSAudioCaptureUsageDescription</key>
<string>Capture system audio output</string>

Checking Permission Programmatically

The library handles permission prompts automatically. If the user denies permission, rec.start will raise an exception.

Native Extension: system_audio_tap

The system audio capture is implemented in ObjC (ext/system_audio_tap.m) because it requires ObjC APIs (ScreenCaptureKit, AudioProcessTap). The C API:

// Create a system audio tap
void *system_audio_tap_create(
    void (*callback)(void *ctx, void *buf, uint32_t frames, uint32_t channels),
    void *ctx
);

// Start audio delivery
int system_audio_tap_start(void *tap);

// Stop audio delivery
int system_audio_tap_stop(void *tap);

// Cleanup
void system_audio_tap_destroy(void *tap);

Limitations

  • iOS: System audio capture is not available on iOS (Apple's sandbox prevents it)
  • Simulator: System audio capture only works on macOS; the iOS Simulator runs macOS but the sandboxed app can't access ProcessTap/SCK
  • Headless: Works in headless environments (no display needed) on macOS 14.2+ with ProcessTap
  • Multiple taps: Only one system audio tap can be active at a time per process

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/system-audio-capture-with-crystal-audio-mryiqgyz/download' --output '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md.part' && mv '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md.part' '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Tools declared by the author (check availability in your agent): Read, Write, Edit, Glob, Grep, Bash

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md' && test -s '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/system-audio' && cp -R '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz' '.claude/skills/system-audio'

Cursor
test -f '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md' && test -s '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/system-audio' && cp -R '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz' '.cursor/skills/system-audio'

Codex
test -f '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md' && test -s '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/system-audio' && cp -R '.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz' '.agents/skills/system-audio'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz'

openskills read 'system-audio-capture-with-crystal-audio-mryiqgyz'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/system-audio-capture-with-crystal-audio-mryiqgyz/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills