> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/audio/audio/redact-audio-file.md).

# Redact audio using JavaScript

Learn how to redact audio programmatically using JavaScript. This snippet demonstrates how to redact specific time ranges in audio files, ensuring seamless operation and customization. The Apryse Web

Here is an example of redacting audio programmatically. `redactAudio` redacts ranges of time in the audio.

{% tabs %}
{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
await redactAudio({
  start: startTime,
  end: endTime,
});
```

{% endcode %}
{% endtab %}
{% endtabs %}

The `start` and `end` keys are both expected to be in seconds. Returns a promise that resolves when the operation is complete. Note that `redactAudio` should not be invoked simultaneously more than once. You must wait for the previous operation to finish before beginning another.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}

<pre class="language-js" data-line-numbers><code class="lang-js">import React, { useRef, useEffect } from 'react';
import WebViewer from '@pdftron/webviewer';
import { initializeAudioViewer } from '@pdftron/webviewer-audio';

const App = () => {
  const viewer = useRef(null);

  useEffect(() => {
    WebViewer(
      {
        path: '/webviewer/lib',
      },
      viewer.current
    ).then(async (instance) => {
      // Extends WebViewer to allow loading media files (.mp3, .mp4, ogg, webm, etc.)
      const { loadAudio, redactAudio } = await initializeAudioViewer(instance, {
        license: '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>',
      });

      // Load a media element at a specific url. Can be a local or public link
      // If local it needs to be relative to lib/ui/index.html.
      // Or at the root. (eg '/audio.mp3')
      const audioUrl = '/audio.mp3';
      loadAudio(audioUrl);

      instance.Core.documentViewer.addEventListener('documentLoaded', async () => {
        // Redact the audio track 0.5 - 2.0 seconds and 2.5 - 4.0 seconds.
        await redactAudio([{ start: 0.5, end: 2.0 }, { start: 2.5, end: 4.0 }]);
      });
    });
  }, []);

  return (
    &#x3C;div className="App">
      &#x3C;div className="webviewer" ref={viewer} />
    &#x3C;/div>
  );
};

export default App;
</code></pre>

{% endtab %}

{% tab title="JavaScript (SDK v7.0+)" %}

<pre class="language-js" data-line-numbers><code class="lang-js">import React, { useRef, useEffect } from 'react';
import WebViewer from '@pdftron/webviewer';
import { initializeAudioViewer } from '@pdftron/webviewer-audio';

const App = () => {
  const viewer = useRef(null);

  useEffect(() => {
    WebViewer(
      {
        path: '/webviewer/lib',
      },
      viewer.current
    ).then(async (instance) => {
      // Extends WebViewer to allow loading media files (.mp3, .mp4, ogg, webm, etc.)
      const { loadAudio, redactAudio } = await initializeAudioViewer(instance, {
        license: '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>',
      });

      // Load a media element at a specific url. Can be a local or public link
      // If local it needs to be relative to lib/ui/index.html.
      // Or at the root. (eg '/audio.mp3')
      const audioUrl = '/audio.mp3';
      loadAudio(audioUrl);

      instance.docViewer.on('documentLoaded', async () => {
        // Redact the audio track 0.5 - 2.0 seconds and 2.5 - 4.0 seconds.
        await redactAudio([{ start: 0.5, end: 2.0 }, { start: 2.5, end: 4.0 }]);
      });
    });
  }, []);

  return (
    &#x3C;div className="App">
      &#x3C;div className="webviewer" ref={viewer} />
    &#x3C;/div>
  );
};

export default App;
</code></pre>

{% endtab %}
{% endtabs %}

The user can also apply the redactions through UI.

Also see the [React sample](https://github.com/ApryseSDK/webviewer-audio-sample/), for a complete solution, with further customizations.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/audio/audio/redact-audio-file.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
