@remotion/media-utils 4.0.119 → 4.0.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,10 @@
1
1
  import type { AudioData } from './types';
2
+ type Options = {
3
+ sampleRate?: number;
4
+ };
2
5
  /**
3
6
  * @description Takes an audio src, loads it and returns data and metadata for the specified source.
4
7
  * @see [Documentation](https://www.remotion.dev/docs/get-audio-data)
5
8
  */
6
- export declare const getAudioData: (src: string) => Promise<AudioData>;
9
+ export declare const getAudioData: (src: string, options?: Options) => Promise<AudioData>;
10
+ export {};
@@ -27,14 +27,17 @@ const fetchWithCorsCatch = async (src) => {
27
27
  throw err;
28
28
  }
29
29
  };
30
- const fn = async (src) => {
30
+ const fn = async (src, options) => {
31
+ var _a;
31
32
  if (metadataCache[src]) {
32
33
  return metadataCache[src];
33
34
  }
34
35
  if (typeof document === 'undefined') {
35
36
  throw new Error('getAudioData() is only available in the browser.');
36
37
  }
37
- const audioContext = new AudioContext();
38
+ const audioContext = new AudioContext({
39
+ sampleRate: (_a = options === null || options === void 0 ? void 0 : options.sampleRate) !== null && _a !== void 0 ? _a : 48000,
40
+ });
38
41
  const response = await fetchWithCorsCatch(src);
39
42
  const arrayBuffer = await response.arrayBuffer();
40
43
  const wave = await audioContext.decodeAudioData(arrayBuffer);
@@ -45,7 +48,7 @@ const fn = async (src) => {
45
48
  });
46
49
  const metadata = {
47
50
  channelWaveforms,
48
- sampleRate: audioContext.sampleRate,
51
+ sampleRate: wave.sampleRate,
49
52
  durationInSeconds: wave.duration,
50
53
  numberOfChannels: wave.numberOfChannels,
51
54
  resultId: String(Math.random()),
@@ -58,7 +61,7 @@ const fn = async (src) => {
58
61
  * @description Takes an audio src, loads it and returns data and metadata for the specified source.
59
62
  * @see [Documentation](https://www.remotion.dev/docs/get-audio-data)
60
63
  */
61
- const getAudioData = (src) => {
62
- return limit(fn, src);
64
+ const getAudioData = (src, options) => {
65
+ return limit(fn, src, options);
63
66
  };
64
67
  exports.getAudioData = getAudioData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remotion/media-utils",
3
- "version": "4.0.119",
3
+ "version": "4.0.121",
4
4
  "description": "Utility functions for audio and video",
5
5
  "main": "dist/index.js",
6
6
  "sideEffects": false,
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/remotion-dev/remotion/issues"
14
14
  },
15
15
  "dependencies": {
16
- "remotion": "4.0.119"
16
+ "remotion": "4.0.121"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": ">=16.8.0",