> ## 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

# Class: LoopbackSource

Defined in: [index.d.ts:647](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L647)

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.

## Constructors

### Constructor

> **new LoopbackSource**(`channels`, `sampleRate`): `LoopbackSource`

Defined in: [index.d.ts:658](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L658)

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

##### channels

`number`

##### sampleRate

`number`

#### Returns

`LoopbackSource`

## Accessors

### channels

#### Get Signature

> **get** **channels**(): `number`

Defined in: [index.d.ts:670](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L670)

Number of interleaved channels (1 = mono, 2 = stereo).

##### Returns

`number`

***

### sampleRate

#### Get Signature

> **get** **sampleRate**(): `number`

Defined in: [index.d.ts:672](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L672)

Samples per second per channel (e.g. 44100, 48000).

##### Returns

`number`

## Methods

### drain()

> **drain**(): [`SamplesBuffer`](SamplesBuffer.mdx)

Defined in: [index.d.ts:686](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L686)

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`](SamplesBuffer.mdx)

***

### record()

> **record**(`durationMs`): [`SamplesBuffer`](SamplesBuffer.mdx)

Defined in: [index.d.ts:678](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L678)

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

##### durationMs

`number`

#### Returns

[`SamplesBuffer`](SamplesBuffer.mdx)

***

### start()

> **start**(): `void`

Defined in: [index.d.ts:663](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L663)

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

#### Returns

`void`

***

### stop()

> **stop**(): `void`

Defined in: [index.d.ts:668](https://github.com/simular-ai/simulang-js-internal/blob/d2b85c3277cbb16ce50c0781e1db8ad2c8a5690e/index.d.ts#L668)

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

#### Returns

`void`
