# audio-context

> A WebAudio Context singleton

Latest version **1.0.3** (published 2018-01-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install audio-context
pnpm add audio-context
yarn add audio-context
bun add audio-context
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-01-11 |
| First published | 2013-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/audio-context) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Julian Gruber |
| Maintainers | dfcreative, jamen, juliangruber |
| Keywords | webaudio, audio, audiojs, context, singleton |

## Links

- npm: https://www.npmjs.com/package/audio-context
- Repository: https://github.com/audiojs/audio-context
- Issues: https://github.com/audiojs/audio-context/issues
- npm.io page: https://npm.io/package/audio-context

## Recent versions

- 1.0.3 (latest) — 2018-01-11
- 1.0.2 — 2018-01-11
- 1.0.1 — 2017-05-23
- 1.0.0 — 2017-04-30
- 0.1.0 — 2014-07-29
- 0.0.0 — 2013-12-14

## README

# audio-context [![Build Status](https://travis-ci.org/audiojs/audio-context.svg?branch=master)](https://travis-ci.org/audiojs/audio-context) [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Greenkeeper badge](https://badges.greenkeeper.io/audiojs/audio-context.svg)](https://greenkeeper.io/) [![npm](https://img.shields.io/npm/v/audio-context.svg)](https://www.npmjs.com/package/audio-context) [![license](https://img.shields.io/npm/l/audio-context.svg)](https://www.npmjs.com/package/audio-context)

Creates a WebAudio context singleton with the given options. Returns `null` if not supported.


## Example

```js
var audioCtx = require('audio-context')()
```

You can also create an [`OfflineAudioContext`](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext) in case you would like to process (faster) without any rendering.


```js
var offlineContext = require('audio-context')({offline: true})
```


## Usage

[![npm install audio-context](https://nodei.co/npm/audio-context.png?mini=true)](https://npmjs.org/package/audio-context/)

#### `ctx = createContext(options|sampleRate)`

Returns a singleton audio context for the given `sampleRate`.

The options:

- `sampleRate` - if specified, will set the context sampleRate.
- `latencyHint` - if specified, will control latency. One of `'balanced'`, `'playback'`, `'interaction'` (default) or number.
- `offline` - if specified, will create [OfflineAudioContext](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext).
- `length` - if specified, will set number of frames for offline context.
- `channels` - if specified, will set number of channels for offline context.
- `{...contextAttributes}` any other options for the context.

Handles vendor prefixing for audio contexts. Returns `null` if we are not in a browser, or if the context is not available, or if there was an error creating the context.


## Running tests

```sh
# Run tests in tape-run's default browser
npm test

# Run in a specified browser.
# See https://github.com/juliangruber/tape-run#runopts for options
npm test -- --browser firefox
```


## License

MIT

---
_Source: https://npm.io/package/audio-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
