{"id":15393163,"url":"https://github.com/birdofpreyru/react-native-audio","last_synced_at":"2025-04-07T18:13:01.011Z","repository":{"id":41801307,"uuid":"372618456","full_name":"birdofpreyru/react-native-audio","owner":"birdofpreyru","description":"React Native: access to the audio input stream, and audio sample player","archived":false,"fork":false,"pushed_at":"2025-02-21T16:35:03.000Z","size":5523,"stargazers_count":44,"open_issues_count":6,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T17:17:08.627Z","etag":null,"topics":["android","audio","ios","react-native"],"latest_commit_sha":null,"homepage":"https://dr.pogodin.studio/docs/react-native-audio","language":"Objective-C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/birdofpreyru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"birdofpreyru"}},"created_at":"2021-05-31T20:12:36.000Z","updated_at":"2025-03-26T09:49:03.000Z","dependencies_parsed_at":"2023-09-24T13:10:58.500Z","dependency_job_id":"24a93935-9895-4f98-85b0-6eef6cec6b4f","html_url":"https://github.com/birdofpreyru/react-native-audio","commit_stats":{"total_commits":132,"total_committers":3,"mean_commits":44.0,"dds":"0.015151515151515138","last_synced_commit":"3e4cf205ede709a08ab9d54a932d3e29bd67a72b"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/birdofpreyru%2Freact-native-audio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/birdofpreyru%2Freact-native-audio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/birdofpreyru%2Freact-native-audio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/birdofpreyru%2Freact-native-audio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/birdofpreyru","download_url":"https://codeload.github.com/birdofpreyru/react-native-audio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704571,"owners_count":20982298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","audio","ios","react-native"],"created_at":"2024-10-01T15:18:05.401Z","updated_at":"2025-04-07T18:13:00.991Z","avatar_url":"https://github.com/birdofpreyru.png","language":"Objective-C++","funding_links":["https://github.com/sponsors/birdofpreyru"],"categories":[],"sub_categories":[],"readme":"# React Native Audio\n\n[![Latest NPM Release](https://img.shields.io/npm/v/@dr.pogodin/react-native-audio.svg)](https://www.npmjs.com/package/@dr.pogodin/react-native-audio)\n[![NPM Downloads](https://img.shields.io/npm/dm/@dr.pogodin/react-native-audio.svg)](https://www.npmjs.com/package/@dr.pogodin/react-native-audio)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/birdofpreyru/react-native-audio/tree/master.svg?style=shield)](https://app.circleci.com/pipelines/github/birdofpreyru/react-native-audio)\n[![GitHub Repo stars](https://img.shields.io/github/stars/birdofpreyru/react-native-audio?style=social)](https://github.com/birdofpreyru/react-native-audio)\n[![Dr. Pogodin Studio](https://raw.githubusercontent.com/birdofpreyru/react-native-audio/master/.README/logo-dr-pogodin-studio.svg)](https://dr.pogodin.studio/docs/react-native-audio)\n\nReact Native (RN) Audio library for Android, iOS, and macOS (Catalyst) platforms, with support of\n[new][New RN Architecture] and [old][Old RN Architecture] RN architectures.\nIt covers:\n- Input audio stream (microphone) listening / recording.\n- Audio samples playback.\n- Utility functions for audio system management.\n- _More stuff to come_...\n\n[![Sponsor](https://raw.githubusercontent.com/birdofpreyru/react-native-audio/master/.README/sponsor.svg)](https://github.com/sponsors/birdofpreyru)\n\n### Sponsored By\n[\u003cimg width=36 src=\"https://avatars.githubusercontent.com/u/521341?s=36\u0026v=4\" /\u003e](https://github.com/liamjones)\n\n### [Contributors](https://github.com/birdofpreyru/react-native-audio/graphs/contributors)\n[\u003cimg width=36 src=\"https://avatars.githubusercontent.com/u/84858035?s=36\u0026v=4\" /\u003e](https://github.com/Siminn-teiturg)\n[\u003cimg width=36 src=\"https://avatars.githubusercontent.com/u/20144632?s=36\u0026v=4\" /\u003e](https://github.com/birdofpreyru)\n\n## Content\n- [Installation]\n- [Getting Started]\n- [API Reference]\n  - [Classes]\n    - [InputAudioStream] \u0026mdash; Represents individual input audio streams.\n      - [constructor()][InputAudioStream.constructor()] \u0026mdash; Creates\n        a new [InputAudioStream] instance.\n      - [.addChunkListener()] \u0026mdash; Adds a new audio data chunk listener to\n        the stream.\n      - [.addErrorListener()][InputAudioStream.addErrorListener()] \u0026mdash; Adds a new error listener to the stream.\n      - [.destroy()][InputAudioStream.destroy()] \u0026mdash; Destroys the stream\n        \u0026mdash; stops recording, and releases all related resources.\n      - [.mute()] \u0026mdash; Mutes the stream.\n      - [.removeChunkListener()] \u0026mdash; Removes an audio data chunk listener\n        from the stream.\n      - [.removeErrorListener()][InputAudioStream.removeErrorListener()] \u0026mdash;\n        Removes an error listener from the stream.\n      - [.start()] \u0026mdash; Starts the audio stream recording.\n      - [.stop()][InputAudioStream.stop()] \u0026mdash; Stops the stream.\n      - [.unmute()] \u0026mdash; Unmutes a previously muted stream.\n      - [.active] \u0026mdash; _true_ when the stream is started and recoding.\n      - [.audioFormat] \u0026mdash; Holds the audio format value provided to\n        the [constructor()][InputAudioStream.constructor()].\n      - [.audioSource] \u0026mdash; Holds the audio source value provided to\n        the [constructor()][InputAudioStream.constructor()].\n      - [.channelConfig] \u0026mdash; Holds the channel mode value provided to\n        the [constructor()][InputAudioStream.constructor()].\n      - [.muted] \u0026mdash; _true_ when the stream is muted.\n      - [.sampleRate] \u0026mdash; Holds the stream's sample rate in [[Hz]].\n      - [.samplingSize] \u0026mdash; Holds the stream's sampling (audio data chunk)\n        size, per channel.\n      - [.stopInBackground] \u0026mdash; _true_ if the stream is configured to stop\n        automatically when the app leaves foreground, and to start again when it\n        returns to the foreground.\n    - [SamplePlayer] \u0026mdash; Represents an audio sample player.\n      - [constructor()][SamplePlayer.constructor()] \u0026mdash; Creates a new\n        [SamplePlayer] instance.\n      - [.addErrorListener()][SamplePlayer.addErrorListener()] \u0026mdash; Adds a new\n        error listener to the player.\n      - [.destroy()][SamplePlayer.destroy()] \u0026mdash; Destroys the player,\n        releasing all related resources.\n      - [.load()] \u0026mdash; Loads an (additional) audio sample.\n      - [.play()] \u0026mdash; Plays an audio sample.\n      - [.removeErrorListener()][SamplePlayer.removeErrorListener()] \u0026mdash;\n        Removes an error listener from the player.\n      - [.stop()][SamplePlayer.stop()] \u0026mdash; Stops an audio sample playback.\n      - [.unload()] \u0026mdash; Unloads an audio sample.\n  - [Constants]\n    - [AUDIO_FORMATS] \u0026mdash; Provides valid [.audioFormat] values.\n    - [AUDIO_SOURCES] \u0026mdash; Provides valid [.audioSource] values.\n    - [CHANNEL_CONFIGS] \u0026mdash; Provides valid [.channelConfig] values.\n    - [IS_MAC_CATALYST] \u0026mdash; _true_ if app is running on macOS (Catalyst).\n  - [Functions]\n    - [configAudioSystem()] \u0026mdash; Configures audio system (input \u0026 output devices)\n      for iOS, does nothing on Android.\n    - [getInputAvailable()] \u0026mdash; Resolves _true_ if device has an available\n      audio input source.\n  - [Types]\n    - [ChunkListener] \u0026mdash; The type of audio data chunk listeners that can be\n      connected to a stream with [.addChunkListener()] method.\n    - [ErrorListener] \u0026mdash; The type of error listeners that can be connected to\n      [InputAudioStream] and [SamplePlayer] instances using their corresponding\n      `.addErrorListener()` methods (see [stream method][InputAudioStream.addErrorListener()],\n      and [player method][SamplePlayer.addErrorListener()]).\n\n## Installation\n[Installation]: #installation\n\n- Install the package and its peer dependencies\n  ```sh\n  npx install-peerdeps @dr.pogodin/react-native-audio\n  ```\n\n- Follow [react-native-permissions] documentation to setup your app for asking\n  the user for the _RECORD\\_AUDIO_ (Android) and/or _Microphone_ (iOS) permissions.\n  **react-native-audio** library will automatically ask for these permissions,\n  if needed, when a stream [.start()] method is called, provided the app has\n  been correctly configured to ask for them.\n\n## Getting Started\n[Getting Started]: #getting-started\n\nA better _Getting Started_ tutorial is to be written, however the main idea\nis this:\n\n```js\nimport {\n  AUDIO_FORMATS,\n  AUDIO_SOURCES,\n  CHANNEL_CONFIGS,\n  InputAudioStream,\n} from \"@dr.pogodin/react-native-audio\";\n\nfunction createAndStartAudioStream() {\n  const stream = new InputAudioStream(\n    AUDIO_SOURCES.RAW,\n    44100, // Sample rate in Hz.\n    CHANNEL_CONFIGS.MONO,\n    AUDIO_FORMATS.PCM_16BIT,\n    4096, // Sampling size.\n  );\n\n  stream.addErrorListener((error) =\u003e {\n    // Do something with a stream error.\n  });\n\n  stream.addChunkListener((chunk, chunkId) =\u003e {\n    // Pause the stream for the chunk processing. The point is: if your chunk\n    // processing in this function is too slow, and chunks arrive faster than\n    // this callback is able to handle them, it will rapidly crash the app,\n    // with out of memory error. Muting the stream ignores any new chunks\n    // until stream.unmute() is called, thus protecting from the crash.\n    // And if your chunk processing is rapid enough, not chunks won't be\n    // skipped. The \"chunkId\" argument is just sequential chunk numbers,\n    // by which you may judge whether any chunks have been skipped between\n    // this callback calls or not.\n    stream.mute();\n\n    // Do something with the chunk.\n\n    // Resumes the stream.\n    stream.unmute();\n  });\n\n  stream.start();\n\n  // Call stream.destroy() to stop the stream and release any associated\n  // resources. If you need to temporarily stop and then resume the stream,\n  // use .mute() and .unmute() methods instead.\n}\n```\nand on top of this the library will include other auxiliary methods related\nto audio input and output.\n\n## API Reference\n[API Reference]: #api-reference\n\n## Classes\n[Classes]: #classes\n\n### InputAudioStream\n[InputAudioStream]: #inputaudiostream\n```tsx\nclass InputAudioStream;\n```\n\nThe [InputAudioStream] class, as its name suggests, represents individual input\naudio streams, capturing audio data in the configured format from the specified\naudio source.\n\n\u003ca id=\"inputaudiostream-constructor\"\u003e\u003c/a\u003e\n#### constructor()\n[InputAudioStream.constructor()]: #inputaudiostream-constructor\n```tsx\nconst stream = new InputAudioStream(\n  audioSource: AUDIO_SOURCES,\n  sampleRate: number,\n  channelConfig: CHANNEL_CONFIGS,\n  audioFormat: AUDIO_FORMATS,\n  samplingSize: number,\n  stopInBackground: boolean = true,\n);\n```\nCreates a new [InputAudioStream] instance. The newly created stream does not\nrecord audio, neither consumes resources at the native side until its [.start()]\nmethod is called.\n\n- `audioSource` \u0026mdash; [AUDIO_SOURCES] \u0026mdash; The audio source this stream\n  will listen to. Currently, it is supported for Android only; on iOS this value\n  is just ignored, and the stream captures audio data from the default input\n  source of the device.\n- `sampleRate` \u0026mdash; **number** \u0026mdash; Sample rate [[Hz]].\n  44100 Hz is the recommended value, as it is the only rate that is\n  guaranteed to work on all Android (and many other) devices.\n- `channelConfig` \u0026mdash; [CHANNEL_CONFIGS] \u0026mdash; _Mono_ or _Stereo_ stream\n  mode.\n- `audioFormat` \u0026mdash; [AUDIO_FORMATS] \u0026mdash; Audio format.\n- `samplingSize` \u0026mdash; **number** \u0026mdash; Sampling (data chunk) size,\n  expressed as the number of samples per channel in the chunk.\n- `stopInBackground` \u0026mdash; **boolean** \u0026mdash; Optional. It _true_ (default)\n  the stream will automatically pause itself when the app leaves the foreground,\n  and the stream will automatically resume itself when the app returns to\n  the foreground.\n\n#### .addChunkListener()\n[.addChunkListener()]: #addchunklistener\n```ts\nstream.addChunkListener(listener: ChunkListener): void;\n```\nAdds a new audio data chunk listener to the stream. See [.removeChunkListener()]\nto subsequently remove the listener from the stream.\n\n**Note:** It is safe to call it repeatedly for the same listener \u0026 stream pair\n\u0026mdash; the listener still won't be added to the stream more than once.\n\n- `listener` \u0026mdash; [ChunkListener] \u0026mdash; The callback to call with audio\n  data chunks when they arrive.\n\n\u003ca id=\"inputaudiostream-adderrorlistener\"\u003e\u003c/a\u003e\n#### .addErrorListener()\n[InputAudioStream.addErrorListener()]: #inputaudiostream-adderrorlistener\n```ts\nstream.addErrorListener(listener: ErrorListener): void;\n```\nAdds a new error listener to the stream. See [.removeErrorListener()][InputAudioStream.removeErrorListener()]\nto subsequently remove the listener from the stream.\n\n**Note:** It is safe to call it repeatedly for the same listener \u0026 stream pair\n\u0026mdash; the listener still won't be added to the stream more than once.\n\n- `listener` \u0026mdash; [ErrorListener] \u0026mdash; The callback to call with error\n  details, if any error happens in the stream.\n\n\u003ca id=\"inputaudiostream-destroy\"\u003e\u003c/a\u003e\n#### .destroy()\n[InputAudioStream.destroy()]: #inputaudiostream-destroy\n```ts\nstream.destroy(): void;\n```\nDestroys the stream \u0026mdash; stops the recording, and releases all related\nresources, both at the native and JS sides. Once a stream is destroyed,\nit cannot be re-used.\n\n#### .mute()\n[.mute()]: #mute\n```ts\nstream.mute(): void;\n```\nMutes the stream. A muted stream still continues to capture audio data chunks\nfrom the audio source, and thus keeps incrementing chunk IDs (see [ChunkListener]),\nbut it discards all data chunks immediately after the capture, without sending\nthem to the JavaScript layer, thus causing the minimal performance and memory\noverhead possible without interrupting the recording.\n\nCalling [.mute()] on a muted, or non-active (not recording) audio stream has\nno effect. See also [.active], [.muted].\n\n#### .removeChunkListener()\n[.removeChunkListener()]: #removechunklistener\n```ts\nstream.removeChunkListener(listener: ChunkListener): void;\n```\nRemoves the listener from the stream. No operation if given `listener` is not\nconnected to the stream. See [.addChunkListener()] to add the listener.\n- `listener` \u0026mdash; [ChunkListener] \u0026mdash; The listener to disconnect.\n\n#### .removeErrorListener()\n[InputAudioStream.removeErrorListener()]: #removeerrorlistener\n```ts\nstream.removeErrorListener(listener: ErrorListener): void;\n```\nRemoves the listener from the stream. No operation if given `listener` is not\nconnected to the stream. See [.addErrorListener()][InputAudioStream.addErrorListener()] to connect the listener.\n\n- `listener` \u0026mdash; [ErrorListener] \u0026mdash; The listener to disconnect.\n\n#### .start()\n[.start()]: #start\n```ts\nstream.start(): Promise\u003cboolean\u003e;\n```\nStarts the audio stream recording. This method actually initializes the stream\non the native side, and starts the recording.\n\n**Note:** If necessary, this method will ask app user for the audio recoding\npermission, using the [react-native-permissions] library.\n\n- Resolves to **boolean** value \u0026mdash; _true_ if the stream has started\n  successfully and is [.active], _false_ otherwise.\n\n\u003ca id=\"inputaudiostream-stop\"\u003e\u003c/a\u003e\n#### .stop()\n[InputAudioStream.stop()]: #inputaudiostream-stop\n```ts\nstream.stop(): Promise\u003cvoid\u003e;\n```\nStops the stream. Unlike the [.mute()] method, [.stop()][InputAudioStream.stop()] actually stops\nthe audio stream and releases its resources on the native side; however,\nunlike the [.destroy()][InputAudioStream.destroy()] method, it does not release its resource in the JS\nlayer (_i.e._ does not drop references to all connected listeners), thus\nallowing to [.start()] this stream instance again (which will technically\nwill init a new stream on the native side, but it will be opaque to the end\nuser on the JS side).\n\n- Resolves once the stream is stopped.\n\n#### .unmute()\n[.unmute()]: #unmute\n```ts\nstream.unmute(): void;\n```\nUnmutes a previously [.muted] stream. It has no effect if called on inactive\n(non started), or already muted stream.\n\n#### .active\n[.active]: #active\n```ts\nstream.active: boolean;\n```\nRead-only. _true_ when the stream is [started][.start()] and recording, _false_\notherwise.\n\n**Note:** [.active] will be _true_ for a started and [.muted] stream.\n\n#### .audioFormat\n[.audioFormat]: #audioformat\n```ts\nstream.audioFormat: AUDIO_FORMATS;\n```\nRead-only. Holds the audio format value provided to [InputAudioStream]'s\n[constructor()][InputAudioStream.constructor()]. [AUDIO_FORMATS] enum provides valid format values.\n\n#### .audioSource\n[.audioSource]: #audiosource\n```ts\nstream.audioSource: AUDIO_SOURCES;\n```\nRead-only. Holds the audio source value provided to [InputAudioStream]'s\n[constructor()][InputAudioStream.constructor()]. As of now it only has an affect on Android devices, and it is\nignored for iOS. [AUDIO_SOURCES] enum provides valid audio source values.\n\n#### .channelConfig\n[.channelConfig]: #channelconfig\n```ts\nstream.channelConfig: CHANNEL_CONFIGS;\n```\nRead-only. Holds the channel mode (_Mono_ or _Stereo_) value provided to\n[InputAudioStream]'s [constructor()][InputAudioStream.constructor()]. [CHANNEL_CONFIGS] enum provides valid\nchannel mode values.\n\n#### .muted\n[.muted]: #muted\n```ts\nstream.muted: boolean;\n```\nRead-only. _true_ when the stream is muted by [.mute()], _false_ otherwise.\n\n#### .sampleRate\n[.sampleRate]: #samplerate\n```ts\nstream.sampleRate: number;\n```\nRead-only. Holds the stream's sample rate provided to the stream [constructor()][InputAudioStream.constructor()],\nin [[Hz]].\n\n#### .samplingSize\n[.samplingSize]: #samplingsize\n```ts\nstream.samplingSize: number;\n```\nRead-only. Holds the stream's sampling (audio data chunk) size, provided to\nthe stream [constructor()][InputAudioStream.constructor()]. The value is the number of samples per channel,\nthus for multi-channel streams the actual chunk size will be a multiple of\nthis number, and also the sample size in bytes may vary for different\n[.audioFormat].\n\n#### .stopInBackground\n[.stopInBackground]: #stopinbackground\n```ts\nstream.stopInBackground: boolean;\n```\nRead-only. _true_ if the stream is set to automatically [.stop()][InputAudioStream.stop()] when the app\nleaves foreground, and [.start()] again when it returns to the foreground.\n\n### SamplePlayer\n[SamplePlayer]: #sampleplayer\n```ts\nclass SamplePlayer;\n```\nRepresents an audio sample player. It is intended for loading into the memory\na set of short audio fragments, which then can be played at demand with a low\nlatency.\n\nOn Android we use [SoundPool](https://developer.android.com/reference/android/media/SoundPool)\nfor the underlying implementation, you may check its documentation for further\ndetails. In particular note: _each decoded sound is internally limited to one\nmegabyte storage, whcih represents approximately 5.6 seconds at 44.1Hz stereo\n(the duration is proportionally longer at lower sample rates or a channel mask\nof mono)._\n\n\u003ca id=\"sampleplayer-constructor\"\u003e\u003c/a\u003e\n#### constructor()\n[SamplePlayer.constructor()]: #sampleplayer-constructor\n```ts\nconst player = new SamplePlayer();\n```\nCreates a new [SamplePlayer] instance. Note that this creation of [SamplePlayer]\ninstance already allocates some resources at the native side, thus to release\nthose resources you MUST USE its [.destroy()][SamplePlayer.destroy()] method\nonce the instance is not needed anymore.\n\n\u003ca id=\"sampleplayer-adderrorlistener\"\u003e\u003c/a\u003e\n#### .addErrorListener()\n[SamplePlayer.addErrorListener()]: #sampleplayer-adderrorlistener\n```ts\nplayer.addErrorListener(listener: ErrorListener): void;\n```\nAdds an error listener to the player. Does nothing if given `listener` is\nalready added to this player.\n\n- `listener` \u0026mdash; [ErrorListener] \u0026mdash; Error listener.\n\n\u003ca id=\"sampleplayer-destroy\"\u003e\u003c/a\u003e\n#### .destroy()\n[SamplePlayer.destroy()]: #sampleplayer-destroy\n```ts\nplayer.destroy(): Promise\u003cvoid\u003e;\n```\nDestroys player instance, releasing all related resources. Once destroyed\nthe player instance can't be reused.\n- Resolves once completed.\n\n#### .load()\n[.load()]: #load\n```ts\nplayer.load(sampleName: string, samplePath: string): Promise\u003cvoid\u003e;\n```\nLoads an (additional) audio sample into the player.\n- `sampleName` \u0026mdash; **string** \u0026mdash; Sample name, by which you'll refer\n  to the loaded sample in other methods, like [.play()], [SamplePlayer.stop()],\n  and [.unload()]. If it matches a name of a previously loaded sample, that\n  sample will be replaced.\n- `samplePath` \u0026mdash; **string** \u0026mdash; Path to the sample file on the device.\n  For now, only loading samples from regular files is supported (_e.g._ not\n  possible to load from Android asset, without first copying the asset into\n  a regular file).\n- Resolves once the sample is loaded and decoded, thus ready to be played.\n\n#### .play()\n[.play()]: #play\n```ts\nplayer.play(sampleName: string, loop: boolean): Promise\u003cvoid\u003e;\n```\nPlays an audio sample, previously loaded with [.load()] method.\n\n**NOTE:** In the current implementation, starting a sample playback always stops\nthe ongoing playback of a sample previously played by the same player, if any.\nThere is no technical barrier to support playback of multiple samples at\nthe same time, it just needs some more development effort.\n\n**NOTE:** Use [.addErrorListener()][SamplePlayer.addErrorListener()] method to\nrecieve details of any errors that happen during the playback. Although [.play()]\nitself rejects if the playback fails to start, that rejection message does not\nprovide any details beyond the fact of the failure, and it also does not capture\nany further errors (as the playback itself is asynchronous).\n\n- `sampleName` \u0026mdash; **string** \u0026mdash; Sample name, assinged when loading it\n  with the [.load()] method.\n- `loop` \u0026mdash; **boolean** \u0026mdash; Set _true_ to infinitely loop the sample;\n  or _false_ to play it once.\n- Resolves once the playback is launched; rejects if the playback fails to start\n  due to some error.\n\n\u003ca id=\"sampleplayer-removeerrorlistener\"\u003e\u003c/a\u003e\n#### .removeErrorListener()\n[SamplePlayer.removeErrorListener()]: #sampleplayer-removeerrorlistener\n```ts\nplayer.removeErrorListener(listener: ErrorListener): void;\n```\nRemoves `listener` from this `player`, or does nothing if the listener is not\nconnected to the player.\n\n- `listener` \u0026mdash; [ErrorListener] \u0026mdash; Error listener to disconnect.\n\n\u003ca id=\"sampleplayer-stop\"\u003e\u003c/a\u003e\n#### .stop()\n[SamplePlayer.stop()]: #sampleplayer-stop\n```ts\nplayer.stop(sampleName: string): Promise\u003cvoid\u003e;\n```\nStops sample playback, does nothing if the sample is not being played by this\nplayer.\n- `sampleName` \u0026mdash; **string** \u0026mdash; Sample name.\n- Resolves once completed.\n\n#### .unload()\n[.unload()]: #unload\n```ts\nplayer.unload(sampleName: string): Promise\u003cvoid\u003e;\n```\nUnloads an audio sample previouly loaded into this player.\n- `sampleName` \u0026mdash; **string** \u0026mdash; Sample name.\n- Resolves once completed.\n\n## Constants\n[Constants]: #constants\n\n### AUDIO_FORMATS\n[AUDIO_FORMATS]: #audio_formats\n```ts\nenum AUDIO_FORMATS {\n  PCM_8BIT: number;\n  PCM_16BIT: number;\n  PCM_FLOAT: number;\n};\n```\nProvides valid [.audioFormat] values. See\n[Android documentation](https://developer.android.com/reference/android/media/AudioFormat#encoding)\nfor exact definitions of these three formats; they should be the same on iOS\ndevices.\n\n**Note:** At least Android allows for other audio formats, which we may include\nhere in future.\n\n### AUDIO_SOURCES\n[AUDIO_SOURCES]: #audio_sources\n```ts\nenum AUDIO_SOURCES {\n  CAMCODER: number;\n  DEFAULT: number;\n  MIC: number;\n  REMOTE_SUBMIX: number;\n  RAW: number;\n  VOICE_CALL: number;\n  VOICE_COMMUNICATION: number;\n  VOICE_DOWNLINK: number;\n  VOICE_PERFORMANCE: number;\n  VOICE_RECOGNITION: number;\n  VOICE_UPLINK: number;\n};\n```\nProvides valid [.audioSource] values. As of now, they have effect for Android\ndevices only, and for them they represent corresponding values of\n[MediaRecorder.AudioSource](https://developer.android.com/reference/android/media/MediaRecorder.AudioSource).\n\n### CHANNEL_CONFIGS\n[CHANNEL_CONFIGS]: #channel_configs\n```ts\nenum CHANNEL_CONFIGS {\n  MONO: number;\n  STEREO: number;\n};\n```\nProvides valid [.channelConfig] values.\n\n**Note:** As of now, it provides only two values, _MONO_ and _STEREO_, however,\nat least Android seems to support additional channels, which might be added in\nfuture, see\n[Android's AudioFormat documentation](https://developer.android.com/reference/android/media/AudioFormat).\n\n### IS_MAC_CATALYST\n[IS_MAC_CATALYST]: #is_mac_catalyst\n```ts\nconst IS_MAC_CATALYST: boolean;\n```\nEquals _true_ if the app is running on the macOS (Catalyst) platform;\n_false_ otherwise.\n\n## Functions\n[Functions]: #functions\n\n### configAudioSystem()\n[configAudioSystem()]: #configaudiosystem\n```ts\nfunction configAudioSystem(): Promise\u003cvoid\u003e;\n```\nConfigures audio system (input \u0026 output devices).\n\nCurrently it does nothing on Android; on iOS it (re-)configures the audio\nsession, setting the _Play \u0026 Record_ category and activating the session.\n\n**Note:** On iOS, if _Play \u0026 Record_ category is not available on the device,\nit sets the _Playback_ category instead; and if neither category is available,\nthe function rejects its result promise. The function also sets the following\noptions for the iOS audio session: _AllowBluetooth_, _AllowBluetoothA2DP_, and\n_DefaultToSpeaker_.\n\nSee [iOS documentation](https://developer.apple.com/documentation/avfaudio/avaudiosession?language=objc)\nfor further details about iOS audio sessions and categories.\n\n- Resolves once completed.\n\n### getInputAvailable()\n[getInputAvailable()]: #getinputavailable\n```ts\nfunction getInputAvailable(): Promise\u003cboolean\u003e;\n```\n- Resolves _true_ if device has an available audio input source,\n  _false_ otherwise.\n\n## Types\n[Types]: #types\n\n### ChunkListener\n[ChunkListener]: #chunklistener\n```ts\ntype ChunkListener = (chunk: Buffer, chunkId: number) =\u003e void;\n```\nThe type of audio data chunk listeners that can be connected to an\n[InputAudioStream] with [.addChunkListener()] method.\n\n- `chunk` \u0026mdash; [Buffer] \u0026mdash; Audio data chunk in the format specified\n  upon the audio stream [construction][InputAudioStream.constructor()]. [Buffer] implementation\n  for RN is provided by [the `buffer` library](https://www.npmjs.com/package/buffer).\n- `chunkId` \u0026mdash; **number** \u0026mdash; Consequtive chunk number. When a stream\n  is [.muted] the chunk numbers are still incremented for discarted audio chunks,\n  thus `chunkId` may be used to judge whether any chunks were missed while\n  a stream was muted.\n\n### ErrorListener\n[ErrorListener]: #errorlistener\n```ts\ntype ErrorListener = (error: Error) =\u003e void;\n```\nThe type of error listeners that can be connected to an [InputAudioStream] with\n[.addErrorListener()][InputAudioStream.addErrorListener()] method.\n\n- `error` \u0026mdash; [Error] \u0026mdash; Stream error.\n\n\u003c!-- Global references. --\u003e\n[Buffer]: https://nodejs.org/api/buffer.html\n[Error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error\n[Hz]: https://en.wikipedia.org/wiki/Hertz\n[New RN Architecture]: https://reactnative.dev/docs/the-new-architecture/pillars-turbomodules\n[Old RN Architecture]: https://reactnative.dev/docs/native-modules-intro\n[react-native-permissions]: https://github.com/zoontek/react-native-permissions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbirdofpreyru%2Freact-native-audio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbirdofpreyru%2Freact-native-audio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbirdofpreyru%2Freact-native-audio/lists"}