> ## Documentation Index
> Fetch the complete documentation index at: https://docs.simular.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LoopbackSource

> A loopback capture source that records system audio output (what the user hears through their speakers or headphones).

Loopback capture is inherently platform-specific: macOS uses
`ScreenCaptureKit` (requires screen-recording permission), Windows
uses WASAPI loopback mode, and Linux uses PulseAudio/PipeWire
monitor sources.

## Constructor

```typescript
LoopbackSource(channels: number, sampleRate: number): LoopbackSource
```

Opens a loopback capture stream for the given format.

`channels` is the number of interleaved channels (1 = mono,
2 = stereo). `sample_rate` is samples per second per channel
(e.g. 44100, 48000).

The stream does not begin producing samples until `start()` is
called.

### Parameters

<ResponseField name={"channels"} type={"number"} required />

<ResponseField name={"sampleRate"} type={"number"} required />

### Returns

`LoopbackSource`

## Properties

<ResponseField name={"channels"} type={"number"} required>
  Number of interleaved channels (1 = mono, 2 = stereo).
</ResponseField>

<ResponseField name={"sampleRate"} type={"number"} required>
  Samples per second per channel (e.g. 44100, 48000).
</ResponseField>

## Methods

### drain()

```typescript
drain(): SamplesBuffer
```

Drains all buffered samples and returns them as a `SamplesBuffer`.

Typical usage: call `start()`, do work while audio accumulates in
the background, call `stop()`, then call `drain()` to collect
everything that was captured.

#### Returns

`SamplesBuffer`

### record()

```typescript
record(durationMs: number): SamplesBuffer
```

Blocks for exactly `duration_ms` and returns the captured audio as
a `SamplesBuffer`. Useful for streaming fixed-size chunks while
the source is still running.

#### Parameters

<ResponseField name={"durationMs"} type={"number"} required />

#### Returns

`SamplesBuffer`

### start()

```typescript
start(): void
```

Begin capturing system audio. Must be called before `record()`
or `drain()`.

### stop()

```typescript
stop(): void
```

Stop capturing. May be started again with `start()`. After
stopping, call `drain()` to collect remaining buffered samples.
