@layercode/js-sdk 1.0.8 → 1.0.10

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Output of AudioAnalysis for the frequency domain of the audio
3
+ * @typedef {Object} AudioAnalysisOutputType
4
+ * @property {Float32Array} values Amplitude of this frequency between {0, 1} inclusive
5
+ * @property {number[]} frequencies Raw frequency bucket values
6
+ * @property {string[]} labels Labels for the frequency bucket values
7
+ */
8
+ /**
9
+ * Analyzes audio for visual output
10
+ * @class
11
+ */
12
+ export class AudioAnalysis {
13
+ /**
14
+ * Retrieves frequency domain data from an AnalyserNode adjusted to a decibel range
15
+ * returns human-readable formatting and labels
16
+ * @param {AnalyserNode} analyser
17
+ * @param {number} sampleRate
18
+ * @param {Float32Array} [fftResult]
19
+ * @param {"frequency"|"music"|"voice"} [analysisType]
20
+ * @param {number} [minDecibels] default -100
21
+ * @param {number} [maxDecibels] default -30
22
+ * @returns {AudioAnalysisOutputType}
23
+ */
24
+ static getFrequencies(analyser: AnalyserNode, sampleRate: number, fftResult?: Float32Array, analysisType?: "frequency" | "music" | "voice", minDecibels?: number, maxDecibels?: number): AudioAnalysisOutputType;
25
+ /**
26
+ * Creates a new AudioAnalysis instance for an HTMLAudioElement
27
+ * @param {HTMLAudioElement} audioElement
28
+ * @param {AudioBuffer|null} [audioBuffer] If provided, will cache all frequency domain data from the buffer
29
+ * @returns {AudioAnalysis}
30
+ */
31
+ constructor(audioElement: HTMLAudioElement, audioBuffer?: AudioBuffer | null);
32
+ fftResults: any[];
33
+ audio: HTMLAudioElement;
34
+ context: OfflineAudioContext | AudioContext;
35
+ analyser: AnalyserNode;
36
+ sampleRate: number;
37
+ audioBuffer: AudioBuffer | null;
38
+ /**
39
+ * Gets the current frequency domain data from the playing audio track
40
+ * @param {"frequency"|"music"|"voice"} [analysisType]
41
+ * @param {number} [minDecibels] default -100
42
+ * @param {number} [maxDecibels] default -30
43
+ * @returns {AudioAnalysisOutputType}
44
+ */
45
+ getFrequencies(analysisType?: "frequency" | "music" | "voice", minDecibels?: number, maxDecibels?: number): AudioAnalysisOutputType;
46
+ /**
47
+ * Resume the internal AudioContext if it was suspended due to the lack of
48
+ * user interaction when the AudioAnalysis was instantiated.
49
+ * @returns {Promise<true>}
50
+ */
51
+ resumeIfSuspended(): Promise<true>;
52
+ }
53
+ /**
54
+ * Output of AudioAnalysis for the frequency domain of the audio
55
+ */
56
+ export type AudioAnalysisOutputType = {
57
+ /**
58
+ * Amplitude of this frequency between {0, 1} inclusive
59
+ */
60
+ values: Float32Array;
61
+ /**
62
+ * Raw frequency bucket values
63
+ */
64
+ frequencies: number[];
65
+ /**
66
+ * Labels for the frequency bucket values
67
+ */
68
+ labels: string[];
69
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * All note frequencies from 1st to 8th octave
3
+ * in format "A#8" (A#, 8th octave)
4
+ */
5
+ export const noteFrequencies: any[];
6
+ export const noteFrequencyLabels: any[];
7
+ export const voiceFrequencies: any[];
8
+ export const voiceFrequencyLabels: any[];
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Raw wav audio file contents
3
+ * @typedef {Object} WavPackerAudioType
4
+ * @property {Blob} blob
5
+ * @property {string} url
6
+ * @property {number} channelCount
7
+ * @property {number} sampleRate
8
+ * @property {number} duration
9
+ */
10
+ /**
11
+ * Utility class for assembling PCM16 "audio/wav" data
12
+ * @class
13
+ */
14
+ export class WavPacker {
15
+ /**
16
+ * Converts Float32Array of amplitude data to ArrayBuffer in Int16Array format
17
+ * @param {Float32Array} float32Array
18
+ * @returns {ArrayBuffer}
19
+ */
20
+ static floatTo16BitPCM(float32Array: Float32Array): ArrayBuffer;
21
+ /**
22
+ * Concatenates two ArrayBuffers
23
+ * @param {ArrayBuffer} leftBuffer
24
+ * @param {ArrayBuffer} rightBuffer
25
+ * @returns {ArrayBuffer}
26
+ */
27
+ static mergeBuffers(leftBuffer: ArrayBuffer, rightBuffer: ArrayBuffer): ArrayBuffer;
28
+ /**
29
+ * Packs data into an Int16 format
30
+ * @private
31
+ * @param {number} size 0 = 1x Int16, 1 = 2x Int16
32
+ * @param {number} arg value to pack
33
+ * @returns
34
+ */
35
+ private _packData;
36
+ /**
37
+ * Packs audio into "audio/wav" Blob
38
+ * @param {number} sampleRate
39
+ * @param {{bitsPerSample: number, channels: Array<Float32Array>, data: Int16Array}} audio
40
+ * @returns {WavPackerAudioType}
41
+ */
42
+ pack(sampleRate: number, audio: {
43
+ bitsPerSample: number;
44
+ channels: Array<Float32Array>;
45
+ data: Int16Array;
46
+ }): WavPackerAudioType;
47
+ }
48
+ /**
49
+ * Raw wav audio file contents
50
+ */
51
+ export type WavPackerAudioType = {
52
+ blob: Blob;
53
+ url: string;
54
+ channelCount: number;
55
+ sampleRate: number;
56
+ duration: number;
57
+ };
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
+ "author": "Layercode",
3
+ "license": "MIT",
2
4
  "name": "@layercode/js-sdk",
3
- "version": "1.0.8",
5
+ "version": "1.0.10",
4
6
  "description": "Layercode JavaScript SDK for browser usage",
5
7
  "type": "module",
6
8
  "main": "dist/layercode-js-sdk.esm.js",
@@ -29,8 +31,6 @@
29
31
  "sdk",
30
32
  "browser"
31
33
  ],
32
- "author": "Layercode",
33
- "license": "MIT",
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },