Skip to main content

convertAudioData()v4.0.288

Part of the @remotion/webcodecs package.

💼 Important License Disclaimer
This package is licensed under the Remotion License.
We consider a team of 4 or more people a "company".

For "companies": A Remotion Company license needs to be obtained to use this package.
In a future version of @remotion/webcodecs, this package will also require the purchase of a newly created "WebCodecs Conversion Seat". Get in touch with us if you are planning to use this package.

For individuals and teams up to 3: You can use this package for free.

This is a short, non-binding explanation of our license. See the License itself for more details.

Converts an AudioData object to a new AudioData object with a different sample rate or format, or both.

Converting an audio data
tsx
import {convertAudioData} from '@remotion/webcodecs';
 
const audioData = new AudioData({
data: new Int32Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
format: 's32',
numberOfChannels: 1,
numberOfFrames: 10,
sampleRate: 44100,
timestamp: 0,
});
 
const newAudioData = convertAudioData({audioData, newSampleRate: 22050});
 
/*
{
data: [0, 2, 4, 6, 8],
format: 's32',
numberOfChannels: 1,
numberOfFrames: 5,
sampleRate: 22050,
timestamp: 0,
}
*/

Behavior

  • Rounding may occur.
  • The new sample rate must be between 3000 and 768000.
  • If no conversion is needed (same sample rate and format), the original AudioData is cloned.
  • No cleanup is done on either the input or output AudioData (call close() on them yourself).

API

Takes an object with the following properties:

audioData

The AudioData object to convert.

newSampleRate?

The new sample rate. Must be between 3000 and 768000 (only Chrome enforces this technically, but Remotion will throw an error always).

newFormat?

The new format.

See also