@remotion/media-utils 4.0.0-2x.1 → 4.0.0-alpha.111
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.
- package/dist/audio-buffer/audio-buffer-to-wav.d.ts +0 -0
- package/dist/audio-buffer/audio-buffer-to-wav.js +0 -0
- package/dist/audio-buffer/audio-url-helpers.d.ts +4 -0
- package/dist/audio-buffer/audio-url-helpers.js +4 -0
- package/dist/fft/complex.d.ts +0 -0
- package/dist/fft/complex.js +0 -0
- package/dist/fft/exponent.d.ts +0 -0
- package/dist/fft/exponent.js +0 -0
- package/dist/fft/fft-freq.d.ts +0 -0
- package/dist/fft/fft-freq.js +0 -0
- package/dist/fft/fft.d.ts +0 -0
- package/dist/fft/fft.js +0 -0
- package/dist/fft/get-visualization.d.ts +0 -0
- package/dist/fft/get-visualization.js +0 -0
- package/dist/fft/mag.d.ts +0 -0
- package/dist/fft/mag.js +0 -0
- package/dist/fft/max-value-cached.d.ts +0 -0
- package/dist/fft/max-value-cached.js +0 -0
- package/dist/fft/smoothing.d.ts +0 -0
- package/dist/fft/smoothing.js +0 -0
- package/dist/fft/to-int-16.d.ts +0 -0
- package/dist/fft/to-int-16.js +0 -0
- package/dist/get-audio-data.d.ts +4 -0
- package/dist/get-audio-data.js +8 -1
- package/dist/get-audio-duration-in-seconds.d.ts +2 -1
- package/dist/get-audio-duration-in-seconds.js +2 -1
- package/dist/get-video-metadata.d.ts +4 -0
- package/dist/get-video-metadata.js +4 -0
- package/dist/get-wave-form-samples.d.ts +0 -0
- package/dist/get-wave-form-samples.js +0 -0
- package/dist/get-waveform-portion.d.ts +4 -0
- package/dist/get-waveform-portion.js +4 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/is-remote-asset.d.ts +0 -0
- package/dist/is-remote-asset.js +0 -0
- package/dist/p-limit.d.ts +0 -0
- package/dist/p-limit.js +0 -0
- package/dist/types.d.ts +0 -0
- package/dist/types.js +0 -0
- package/dist/use-audio-data.d.ts +7 -0
- package/dist/use-audio-data.js +7 -0
- package/dist/visualize-audio.d.ts +0 -0
- package/dist/visualize-audio.js +5 -0
- package/package.json +7 -8
- package/.prettierrc.js +0 -14
- package/dist/create-smooth-svg-path.d.ts +0 -4
- package/dist/create-smooth-svg-path.js +0 -39
- package/dist/get-audio-duration.d.ts +0 -11
- package/dist/get-audio-duration.js +0 -49
- package/dist/validate-channel.d.ts +0 -1
- package/dist/validate-channel.js +0 -21
- package/dist/visualize-audio-waveform.d.ts +0 -11
- package/dist/visualize-audio-waveform.js +0 -32
- package/tsconfig.json +0 -10
|
File without changes
|
|
File without changes
|
|
@@ -1 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This API takes an AudioBuffer instance and converts it to a Base 64 Data URL so it can be passed to an <Audio /> tag.
|
|
3
|
+
* @see [Documentation](https://www.remotion.dev/docs/audio-buffer-to-data-url)
|
|
4
|
+
*/
|
|
1
5
|
export declare const audioBufferToDataUrl: (buffer: AudioBuffer) => string;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.audioBufferToDataUrl = void 0;
|
|
4
4
|
const audio_buffer_to_wav_1 = require("./audio-buffer-to-wav");
|
|
5
|
+
/**
|
|
6
|
+
* @description This API takes an AudioBuffer instance and converts it to a Base 64 Data URL so it can be passed to an <Audio /> tag.
|
|
7
|
+
* @see [Documentation](https://www.remotion.dev/docs/audio-buffer-to-data-url)
|
|
8
|
+
*/
|
|
5
9
|
const audioBufferToDataUrl = (buffer) => {
|
|
6
10
|
const wavAsArrayBuffer = (0, audio_buffer_to_wav_1.audioBufferToWav)(buffer, {
|
|
7
11
|
float32: true,
|
package/dist/fft/complex.d.ts
CHANGED
|
File without changes
|
package/dist/fft/complex.js
CHANGED
|
File without changes
|
package/dist/fft/exponent.d.ts
CHANGED
|
File without changes
|
package/dist/fft/exponent.js
CHANGED
|
File without changes
|
package/dist/fft/fft-freq.d.ts
CHANGED
|
File without changes
|
package/dist/fft/fft-freq.js
CHANGED
|
File without changes
|
package/dist/fft/fft.d.ts
CHANGED
|
File without changes
|
package/dist/fft/fft.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/fft/mag.d.ts
CHANGED
|
File without changes
|
package/dist/fft/mag.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/fft/smoothing.d.ts
CHANGED
|
File without changes
|
package/dist/fft/smoothing.js
CHANGED
|
File without changes
|
package/dist/fft/to-int-16.d.ts
CHANGED
|
File without changes
|
package/dist/fft/to-int-16.js
CHANGED
|
File without changes
|
package/dist/get-audio-data.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { AudioData } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @description Takes an audio src, loads it and returns data and metadata for the specified source.
|
|
4
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-audio-data)
|
|
5
|
+
*/
|
|
2
6
|
export declare const getAudioData: (src: string) => Promise<AudioData>;
|
package/dist/get-audio-data.js
CHANGED
|
@@ -7,7 +7,10 @@ const metadataCache = {};
|
|
|
7
7
|
const limit = (0, p_limit_1.pLimit)(3);
|
|
8
8
|
const fetchWithCorsCatch = async (src) => {
|
|
9
9
|
try {
|
|
10
|
-
const response = await fetch(src
|
|
10
|
+
const response = await fetch(src, {
|
|
11
|
+
mode: 'cors',
|
|
12
|
+
referrerPolicy: 'no-referrer-when-downgrade',
|
|
13
|
+
});
|
|
11
14
|
return response;
|
|
12
15
|
}
|
|
13
16
|
catch (err) {
|
|
@@ -51,6 +54,10 @@ const fn = async (src) => {
|
|
|
51
54
|
metadataCache[src] = metadata;
|
|
52
55
|
return metadata;
|
|
53
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* @description Takes an audio src, loads it and returns data and metadata for the specified source.
|
|
59
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-audio-data)
|
|
60
|
+
*/
|
|
54
61
|
const getAudioData = (src) => {
|
|
55
62
|
return limit(fn, src);
|
|
56
63
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get the audio file passed in parameter duration in seconds
|
|
2
|
+
* @default Get the audio file passed in parameter duration in seconds
|
|
3
3
|
* @async
|
|
4
4
|
* @param src path to the audio file
|
|
5
5
|
* @return {number} duration of the audio file in seconds
|
|
6
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-audio-duration-in-seconds)
|
|
6
7
|
*/
|
|
7
8
|
export declare const getAudioDurationInSeconds: (src: string) => Promise<number>;
|
|
8
9
|
/**
|
|
@@ -33,10 +33,11 @@ const fn = (src) => {
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
|
-
* Get the audio file passed in parameter duration in seconds
|
|
36
|
+
* @default Get the audio file passed in parameter duration in seconds
|
|
37
37
|
* @async
|
|
38
38
|
* @param src path to the audio file
|
|
39
39
|
* @return {number} duration of the audio file in seconds
|
|
40
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-audio-duration-in-seconds)
|
|
40
41
|
*/
|
|
41
42
|
const getAudioDurationInSeconds = (src) => {
|
|
42
43
|
return limit(fn, src);
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { VideoMetadata } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @description Takes a src to a video, loads it and returns metadata for the specified source.
|
|
4
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-video-metadata)
|
|
5
|
+
*/
|
|
2
6
|
export declare const getVideoMetadata: (src: string) => Promise<VideoMetadata>;
|
|
@@ -45,6 +45,10 @@ const fn = (src) => {
|
|
|
45
45
|
video.addEventListener('error', onError, { once: true });
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* @description Takes a src to a video, loads it and returns metadata for the specified source.
|
|
50
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-video-metadata)
|
|
51
|
+
*/
|
|
48
52
|
const getVideoMetadata = (src) => {
|
|
49
53
|
return limit(fn, src);
|
|
50
54
|
};
|
|
File without changes
|
|
File without changes
|
|
@@ -3,6 +3,10 @@ declare type Bar = {
|
|
|
3
3
|
index: number;
|
|
4
4
|
amplitude: number;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* @description Takes bulky waveform data (for example fetched by getAudioData()) and returns a trimmed and simplified version of it, for simpler visualization
|
|
8
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-waveform-portion)
|
|
9
|
+
*/
|
|
6
10
|
export declare const getWaveformPortion: ({ audioData, startTimeInSeconds, durationInSeconds, numberOfSamples, }: {
|
|
7
11
|
audioData: AudioData;
|
|
8
12
|
startTimeInSeconds: number;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getWaveformPortion = void 0;
|
|
4
4
|
const get_wave_form_samples_1 = require("./get-wave-form-samples");
|
|
5
|
+
/**
|
|
6
|
+
* @description Takes bulky waveform data (for example fetched by getAudioData()) and returns a trimmed and simplified version of it, for simpler visualization
|
|
7
|
+
* @see [Documentation](https://www.remotion.dev/docs/get-waveform-portion)
|
|
8
|
+
*/
|
|
5
9
|
const getWaveformPortion = ({ audioData, startTimeInSeconds, durationInSeconds, numberOfSamples, }) => {
|
|
6
10
|
const startSample = Math.floor((startTimeInSeconds / audioData.durationInSeconds) *
|
|
7
11
|
audioData.channelWaveforms[0].length);
|
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/is-remote-asset.js
CHANGED
|
File without changes
|
package/dist/p-limit.d.ts
CHANGED
|
File without changes
|
package/dist/p-limit.js
CHANGED
|
File without changes
|
package/dist/types.d.ts
CHANGED
|
File without changes
|
package/dist/types.js
CHANGED
|
File without changes
|
package/dist/use-audio-data.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import type { AudioData } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @description Wraps the getAudioData() function into a hook and does 3 things:
|
|
4
|
+
* @description Keeps the audio data in a state
|
|
5
|
+
* @description Wraps the function in a delayRender() / continueRender() pattern.
|
|
6
|
+
* @description Handles the case where the component gets unmounted while the fetching is in progress and a React error is thrown.
|
|
7
|
+
* @see [Documentation](https://www.remotion.dev/docs/use-audio-data)
|
|
8
|
+
*/
|
|
2
9
|
export declare const useAudioData: (src: string) => AudioData | null;
|
package/dist/use-audio-data.js
CHANGED
|
@@ -4,6 +4,13 @@ exports.useAudioData = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const remotion_1 = require("remotion");
|
|
6
6
|
const get_audio_data_1 = require("./get-audio-data");
|
|
7
|
+
/**
|
|
8
|
+
* @description Wraps the getAudioData() function into a hook and does 3 things:
|
|
9
|
+
* @description Keeps the audio data in a state
|
|
10
|
+
* @description Wraps the function in a delayRender() / continueRender() pattern.
|
|
11
|
+
* @description Handles the case where the component gets unmounted while the fetching is in progress and a React error is thrown.
|
|
12
|
+
* @see [Documentation](https://www.remotion.dev/docs/use-audio-data)
|
|
13
|
+
*/
|
|
7
14
|
const useAudioData = (src) => {
|
|
8
15
|
if (!src) {
|
|
9
16
|
throw new TypeError("useAudioData requires a 'src' parameter");
|
|
File without changes
|
package/dist/visualize-audio.js
CHANGED
|
@@ -4,6 +4,11 @@ exports.visualizeAudio = void 0;
|
|
|
4
4
|
const get_visualization_1 = require("./fft/get-visualization");
|
|
5
5
|
const max_value_cached_1 = require("./fft/max-value-cached");
|
|
6
6
|
const cache = {};
|
|
7
|
+
/**
|
|
8
|
+
* @description Takes in AudioData (preferably fetched by the useAudioData() hook) and processes it in a way that makes visualizing the audio that is playing at the current frame easy.
|
|
9
|
+
* @description part of @remotion/media-utils
|
|
10
|
+
* @see [Documentation](https://www.remotion.dev/docs/visualize-audio)
|
|
11
|
+
*/
|
|
7
12
|
const visualizeAudioFrame = ({ audioData: metadata, frame, fps, numberOfSamples, }) => {
|
|
8
13
|
const cacheKey = metadata.resultId + frame + fps + numberOfSamples;
|
|
9
14
|
if (cache[cacheKey]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/media-utils",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-alpha.111+6fd1a79a5",
|
|
4
4
|
"description": "Utility functions for audio and video",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"watch": "tsc -w",
|
|
10
10
|
"build": "tsc -d"
|
|
11
11
|
},
|
|
12
|
-
"author": "",
|
|
12
|
+
"author": "Jonny Burger <jonny@remotion.dev>",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
15
15
|
"url": "https://github.com/remotion-dev/remotion"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"remotion": "4.0.0-
|
|
21
|
+
"remotion": "4.0.0-alpha.111+6fd1a79a5"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": ">=16.8.0",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@jonny/eslint-config": "3.0.266",
|
|
29
29
|
"@types/node": "^16.7.5",
|
|
30
|
-
"@types/react": "18.0.
|
|
31
|
-
"eslint": "8.
|
|
32
|
-
"prettier": "^2.
|
|
30
|
+
"@types/react": "18.0.26",
|
|
31
|
+
"eslint": "8.25.0",
|
|
32
|
+
"prettier": "^2.7.1",
|
|
33
33
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
34
34
|
"typescript": "^4.7.0"
|
|
35
35
|
},
|
|
@@ -38,11 +38,10 @@
|
|
|
38
38
|
"ffmpeg",
|
|
39
39
|
"video",
|
|
40
40
|
"react",
|
|
41
|
-
"puppeteer",
|
|
42
41
|
"player"
|
|
43
42
|
],
|
|
44
43
|
"publishConfig": {
|
|
45
44
|
"access": "public"
|
|
46
45
|
},
|
|
47
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "6fd1a79a5bab8c77aa15cab08a51916419c1c4b4"
|
|
48
47
|
}
|
package/.prettierrc.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.smoothenSvgPath = void 0;
|
|
4
|
-
const line = (pointA, pointB) => {
|
|
5
|
-
const lengthX = pointB[0] - pointA[0];
|
|
6
|
-
const lengthY = pointB[1] - pointA[1];
|
|
7
|
-
return {
|
|
8
|
-
length: Math.sqrt(lengthX ** 2 + lengthY ** 2),
|
|
9
|
-
angle: Math.atan2(lengthY, lengthX),
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
const controlPoint = (current, previous, next, reverse) => {
|
|
13
|
-
const p = previous || current;
|
|
14
|
-
const n = next || current;
|
|
15
|
-
// The smoothing ratio
|
|
16
|
-
const smoothing = 0.2;
|
|
17
|
-
// Properties of the opposed-line
|
|
18
|
-
const o = line(p, n);
|
|
19
|
-
const angle = o.angle + (reverse ? Math.PI : 0);
|
|
20
|
-
const length = o.length * smoothing;
|
|
21
|
-
const x = current[0] + Math.cos(angle) * length;
|
|
22
|
-
const y = current[1] + Math.sin(angle) * length;
|
|
23
|
-
return [x, y];
|
|
24
|
-
};
|
|
25
|
-
const smoothenSvgPath = (points) => {
|
|
26
|
-
return points.reduce((acc, current, i, a) => {
|
|
27
|
-
if (i === 0) {
|
|
28
|
-
return `M ${current[0]},${current[1]}`;
|
|
29
|
-
}
|
|
30
|
-
const [x, y] = current;
|
|
31
|
-
const previous = a[i - 1];
|
|
32
|
-
const twoPrevious = a[i - 2];
|
|
33
|
-
const next = a[i + 1];
|
|
34
|
-
const [cp1x, cp1y] = controlPoint(previous, twoPrevious, current, false);
|
|
35
|
-
const [cp2x, cp2y] = controlPoint(current, previous, next, true);
|
|
36
|
-
return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${x},${y}`;
|
|
37
|
-
}, '');
|
|
38
|
-
};
|
|
39
|
-
exports.smoothenSvgPath = smoothenSvgPath;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the audio file passed in parameter duration in seconds
|
|
3
|
-
* @async
|
|
4
|
-
* @param src path to the audio file
|
|
5
|
-
* @return {number} duration of the audio file in seconds
|
|
6
|
-
*/
|
|
7
|
-
export declare const getAudioDurationInSeconds: (src: string) => Promise<number>;
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Renamed to `getAudioDurationInSeconds`
|
|
10
|
-
*/
|
|
11
|
-
export declare const getAudioDuration: (src: string) => Promise<number>;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAudioDuration = exports.getAudioDurationInSeconds = void 0;
|
|
4
|
-
const p_limit_1 = require("./p-limit");
|
|
5
|
-
const limit = (0, p_limit_1.pLimit)(3);
|
|
6
|
-
const metadataCache = {};
|
|
7
|
-
const fn = (src) => {
|
|
8
|
-
if (metadataCache[src]) {
|
|
9
|
-
return Promise.resolve(metadataCache[src]);
|
|
10
|
-
}
|
|
11
|
-
if (typeof document === 'undefined') {
|
|
12
|
-
throw new Error('getAudioDuration() is only available in the browser.');
|
|
13
|
-
}
|
|
14
|
-
const audio = document.createElement('audio');
|
|
15
|
-
audio.src = src;
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
const onError = () => {
|
|
18
|
-
reject(audio.error);
|
|
19
|
-
cleanup();
|
|
20
|
-
};
|
|
21
|
-
const onLoadedMetadata = () => {
|
|
22
|
-
metadataCache[src] = audio.duration;
|
|
23
|
-
resolve(audio.duration);
|
|
24
|
-
cleanup();
|
|
25
|
-
};
|
|
26
|
-
const cleanup = () => {
|
|
27
|
-
audio.removeEventListener('loadedmetadata', onLoadedMetadata);
|
|
28
|
-
audio.removeEventListener('error', onError);
|
|
29
|
-
audio.remove();
|
|
30
|
-
};
|
|
31
|
-
audio.addEventListener('loadedmetadata', onLoadedMetadata, { once: true });
|
|
32
|
-
audio.addEventListener('error', onError, { once: true });
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Get the audio file passed in parameter duration in seconds
|
|
37
|
-
* @async
|
|
38
|
-
* @param src path to the audio file
|
|
39
|
-
* @return {number} duration of the audio file in seconds
|
|
40
|
-
*/
|
|
41
|
-
const getAudioDurationInSeconds = (src) => {
|
|
42
|
-
return limit(fn, src);
|
|
43
|
-
};
|
|
44
|
-
exports.getAudioDurationInSeconds = getAudioDurationInSeconds;
|
|
45
|
-
/**
|
|
46
|
-
* @deprecated Renamed to `getAudioDurationInSeconds`
|
|
47
|
-
*/
|
|
48
|
-
const getAudioDuration = (src) => (0, exports.getAudioDurationInSeconds)(src);
|
|
49
|
-
exports.getAudioDuration = getAudioDuration;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const validateChannel: (channel: unknown, numberOfChannels: number) => void;
|
package/dist/validate-channel.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateChannel = void 0;
|
|
4
|
-
const validateChannel = (channel, numberOfChannels) => {
|
|
5
|
-
if (typeof channel !== 'number') {
|
|
6
|
-
throw new TypeError(`"channel" must be a number`);
|
|
7
|
-
}
|
|
8
|
-
if (channel % 1 !== 0) {
|
|
9
|
-
throw new TypeError(`"channel" must an integer, got ${channel}`);
|
|
10
|
-
}
|
|
11
|
-
if (Number.isNaN(channel)) {
|
|
12
|
-
throw new TypeError(`The channel parameter is NaN.`);
|
|
13
|
-
}
|
|
14
|
-
if (channel < 0) {
|
|
15
|
-
throw new TypeError('"channel" cannot be negative');
|
|
16
|
-
}
|
|
17
|
-
if (channel > numberOfChannels - 1) {
|
|
18
|
-
throw new TypeError(`"channel" must be ${numberOfChannels - 1} or lower. The audio has ${numberOfChannels} channels`);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
exports.validateChannel = validateChannel;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AudioData } from './types';
|
|
2
|
-
declare type FnParameters = {
|
|
3
|
-
audioData: AudioData;
|
|
4
|
-
frame: number;
|
|
5
|
-
fps: number;
|
|
6
|
-
windowInSeconds: number;
|
|
7
|
-
numberOfSamples: number;
|
|
8
|
-
channel: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const visualizeAudioWaveform: ({ ...parameters }: FnParameters) => number[];
|
|
11
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.visualizeAudioWaveform = void 0;
|
|
4
|
-
const get_waveform_portion_1 = require("./get-waveform-portion");
|
|
5
|
-
const cache = {};
|
|
6
|
-
const visualizeAudioWaveformFrame = ({ audioData, frame, fps, numberOfSamples, windowInSeconds, channel, }) => {
|
|
7
|
-
if (windowInSeconds * audioData.sampleRate < numberOfSamples) {
|
|
8
|
-
throw new TypeError(windowInSeconds +
|
|
9
|
-
's audiodata does not have ' +
|
|
10
|
-
numberOfSamples +
|
|
11
|
-
' bars. Increase windowInSeconds or decrease numberOfSamples');
|
|
12
|
-
}
|
|
13
|
-
const cacheKey = audioData.resultId + frame + fps + numberOfSamples + 'waveform';
|
|
14
|
-
if (cache[cacheKey]) {
|
|
15
|
-
return cache[cacheKey];
|
|
16
|
-
}
|
|
17
|
-
const time = frame / fps;
|
|
18
|
-
const startTimeInSeconds = time - windowInSeconds / 2;
|
|
19
|
-
return (0, get_waveform_portion_1.getWaveformPortion)({
|
|
20
|
-
audioData,
|
|
21
|
-
startTimeInSeconds,
|
|
22
|
-
durationInSeconds: windowInSeconds,
|
|
23
|
-
numberOfSamples,
|
|
24
|
-
outputRange: 'minus-one-to-one',
|
|
25
|
-
channel,
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
const visualizeAudioWaveform = ({ ...parameters }) => {
|
|
29
|
-
const data = visualizeAudioWaveformFrame(parameters);
|
|
30
|
-
return data.map((value) => value.amplitude);
|
|
31
|
-
};
|
|
32
|
-
exports.visualizeAudioWaveform = visualizeAudioWaveform;
|