> For the complete documentation index, see [llms.txt](https://sparkar-community.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sparkar-community.gitbook.io/docs/audiomodule.md).

# AudioModule

The `AudioModule` class enables sound effects.

## Example

```
//==============================================================================
// The following example demonstrates how to control audio playback by tapping
// on the screen.
//
// Project setup:
// - Import an audio file (M4A, Mono, 44.1kHz, 16 bit)
// - Create an audio playback controller and set the audio to the imported file
// - Insert a speaker and set the audio to the playback controller
// - Add the Tap Gesture capability to the project under Touch Gestures
//==============================================================================

// Load in the required modules
const Audio = require('Audio');
const TouchGestures = require('TouchGestures');

// Locate the playback controller in the Assets
const playbackController =
Audio.getPlaybackController('Audio Playback Controller');

// Play and loop the playback controller
playbackController.setPlaying(true);
playbackController.setLooping(true);

//==============================================================================
// Start and stop the audio by tapping on the screen
//==============================================================================

// Create a boolean to determine if the audio is playing
var isAudioPlaying = true;

// Subscribe to tap gestures on the screen
TouchGestures.onTap().subscribe(function() {

  // Switch the boolean controlling audio playback
  isAudioPlaying = !isAudioPlaying;

  // Start or stop the audio depending on the state of the boolean
  playbackController.setPlaying(isAudioPlaying);

});
```

## Properties

This module exposes no properties.

## Methods

| Method                  | Description                                                                                                                                  |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `getPlaybackController` | `getPlaybackController(name: String): PlaybackController` Get a playback controller from assets by name.                                     |
| `play`                  | <p><code>play(audioSource: AudioSource): void</code></p><p>Creates a new playing instance of the sound associated with this AudioSource.</p> |
| `stopAll`               | <p><code>stopAll(audioSource: AudioSource): void</code></p><p>Stops all playing instances of this AudioSource.</p>                           |

## Classes

| Class                                                                                                                | Description                                                       |
| -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [`PlaybackController`](https://sparkar.facebook.com/docs/ar-studio/reference/classes/audiomodule.playbackcontroller) | The `PlaybackController` class enables control of audio playback. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sparkar-community.gitbook.io/docs/audiomodule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
