Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Avfoundation Audio

ASecurity

Configure AVAudioSession categories, modes, route changes, interruptions, and build low-latency AVAudioEngine node graphs for recording, mixing, and audio processing in iOS and iPadOS apps.

3 stars
0 votes
0 copies
0 views
Added 9/28/2026
developmentgoswiftnodeapidocumentation

Works with

api

Security Analysis

A100/100

Scanned 9/28/2026

Install to Claude Code

$npx -y skills add thiennc-tesoglobal/ios-skills --skill avfoundation-audio --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Avfoundation Audio?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Avfoundation Audio
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/thiennc-tesoglobal-avfoundation-audio/badge)](https://www.skillsdirectory.com/skills/thiennc-tesoglobal-avfoundation-audio)

More formats (shields.io, HTML) on the badges page.

Files
SKILL.md
---
name: avfoundation-audio
description: "Configure AVAudioSession categories, modes, route changes, interruptions, and build low-latency AVAudioEngine node graphs for recording, mixing, and audio processing in iOS and iPadOS apps."
---

# AVFoundation Audio

Configure `AVAudioSession` and construct `AVAudioEngine` node graphs for playback, recording, real-time DSP, and multi-track audio pipelines in iOS and iPadOS.

## Contents

- [Audio Session Configuration](#audio-session-configuration)
- [Interruption & Route Change Handling](#interruption--route-change-handling)
- [AVAudioEngine Architecture](#avaudioengine-architecture)
- [Live Microphone Capture & Taps](#live-microphone-capture--taps)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)

---

## Audio Session Configuration

`AVAudioSession` coordinates app audio with the system audio subsystem. Defer activation until playback or recording begins to avoid prematurely silencing background audio.

```swift
import AVFAudio

@MainActor
final class AudioSessionManager {
    static let shared = AudioSessionManager()

    func configurePlayback() throws {
        let session = AVAudioSession.sharedInstance()
        try session.setCategory(.playback, mode: .moviePlayback, options: [])
        try session.setActive(true)
    }

    func configureRecording() throws {
        let session = AVAudioSession.sharedInstance()
        try session.setCategory(
            .playAndRecord,
            mode: .measurement,
            options: [.defaultToSpeaker, .allowBluetoothHFP]
        )
        try session.setActive(true)
    }

    func deactivate() throws {
        try AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
    }
}
```

### Key Categories and Modes

- `.playback`: Media playback that continues when the Ring/Silent switch is set to silent or screen locks.
- `.record`: Pure recording without playback; silences background audio.
- `.playAndRecord`: Bidirectional audio (VoIP, chat, audio recording while monitoring). Use `.defaultToSpeaker` to prevent routing audio only to receiver.
- `.ambient`: Mixes with other audio apps; silenced by Ring/Silent switch.

---

## Interruption & Route Change Handling

Always observe `AVAudioSession.interruptionNotification` and `AVAudioSession.routeChangeNotification` asynchronously using `NotificationCenter` async sequences.

```swift
import AVFAudio

actor AudioNotificationObserver {
    private var task: Task<Void, Never>?

    func startObserving(
        onInterruption: @Sendable @escaping (Bool) -> Void,
        onPauseForRouteLoss: @Sendable @escaping () -> Void
    ) {
        task = Task {
            for await notification in NotificationCenter.default.notifications(named: AVAudioSession.interruptionNotification) {
                guard let userInfo = notification.userInfo,
                      let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
                      let type = AVAudioSession.InterruptionType(rawValue: typeValue) else { continue }

                switch type {
                case .began:
                    onInterruption(true)
                case .ended:
                    let optionsValue = userInfo[AVAudioSessionInterruptionOptionKey] as? UInt ?? 0
                    let shouldResume = AVAudioSession.InterruptionOptions(rawValue: optionsValue).contains(.shouldResume)
                    onInterruption(!shouldResume)
                @unknown default:
                    break
                }
            }
        }
    }

    func stopObserving() {
        task?.cancel()
        task = nil
    }
}
```

Pause playback immediately when `AVAudioSessionRouteChangeReasonKey` indicates `.oldDeviceUnavailable` (e.g., headphones disconnected).

---

## AVAudioEngine Architecture

`AVAudioEngine` coordinates a graph of `AVAudioNode` instances (player nodes, mixer nodes, effect nodes) connected together.

```swift
import AVFAudio

@MainActor
final class AudioEngineController {
    private let engine = AVAudioEngine()
    private let playerNode = AVAudioPlayerNode()

    func setupGraph(audioFileURL: URL) throws {
        let file = try AVAudioFile(forReading: audioFileURL)
        let format = file.processingFormat

        engine.attach(playerNode)
        engine.connect(playerNode, to: engine.mainMixerNode, format: format)

        try engine.start()

        playerNode.scheduleFile(file, at: nil) {
            // Playback completed
        }
        playerNode.play()
    }

    func stop() {
        playerNode.stop()
        engine.stop()
        engine.reset()
    }
}
```

---

## Live Microphone Capture & Taps

To analyze or stream microphone PCM buffers, install an audio tap on the `inputNode`. Always remove previous taps before installing a new tap or tearing down.

```swift
import AVFAudio

final class MicrophoneTapManager: Sendable {
    private let engine = AVAudioEngine()

    func startTapping(bufferHandler: @escaping @Sendable (AVAudioPCMBuffer, AVAudioTime) -> Void) throws {
        let inputNode = engine.inputNode
        let format = inputNode.outputFormat(forBus: 0)

        inputNode.removeTap(onBus: 0)
        inputNode.installTap(onBus: 0, bufferSize: 1024, format: format) { buffer, time in
            bufferHandler(buffer, time)
        }

        engine.prepare()
        try engine.start()
    }

    func stopTapping() {
        engine.inputNode.removeTap(onBus: 0)
        engine.stop()
    }
}
```

---

## Common Mistakes

- **Activating session at app launch:** Causes unwanted background audio suspension. Deactivate or defer activation until the user requests audio.
- **Mismatching audio formats in engine connections:** Connecting nodes with incompatible sample rates or channel counts without a mixer or format converter throws an exception.
- **Duplicate tap installation:** Calling `installTap(onBus:bufferSize:format:)` on a bus that already has a tap installed crashes at runtime. Always call `removeTap(onBus:)` first.
- **Ignoring route loss:** Failing to pause playback when headphones disconnect blares audio through built-in speakers.
- **Retaining AVAudioEngine across session resets:** Handle `AVAudioEngineConfigurationChange` by rebuilding graph or restarting the engine.

---

## Review Checklist

- [ ] Does `AVAudioSession` configuration set appropriate category, mode, and options (`.defaultToSpeaker`, `.allowBluetoothHFP`)?
- [ ] Is `setActive(true)` deferred until audio playback/recording actually starts?
- [ ] Is `setActive(false, options: .notifyOthersOnDeactivation)` invoked when stopping to restore other audio apps?
- [ ] Are route changes observed, specifically pausing on `.oldDeviceUnavailable`?
- [ ] Are interruptions (`.began` and `.ended` with `.shouldResume`) handled gracefully?
- [ ] Does microphone capture check and request `AVAudioApplication.requestRecordPermission()` prior to starting?
- [ ] Are audio node taps properly removed prior to re-installing or stopping?

---

## References

- [Audio Engine Patterns](references/audio-engine-patterns.md) — Advanced mixer graphs, EQ, audio conversion, and unit tests.
- [AVFAudio Documentation](https://sosumi.ai/documentation/avfaudio) — Official Apple AVFAudio API reference.
- [AVAudioSession Guide](https://sosumi.ai/documentation/avfaudio/avaudiosession) — Audio session lifecycle, routing, and categories.
- [AVAudioEngine Guide](https://sosumi.ai/documentation/avfaudio/avaudioengine) — Real-time audio node processing graph.

Attribution

thiennc-tesoglobalthiennc-tesoglobal
View sourceMore from thiennc-tesoglobal →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284972 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10311 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →