Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Library that finds the synchronization point between two or more audio clips.
synaudio
synaudio
is a JavaScript library that finds the synchronization points between two or more similar audio clips.
npm i synaudio
Create a new instance of SynAudio
.
import SynAudio from 'synaudio';
const synAudio = new SynAudio({
correlationSampleSize: 5000,
initialGranularity: 16,
});
SynAudio can synchronize two clips: one base and one comparison. The comparison clip must be a subset of the base clip in order for there to be a valid match. If you don't know the ordering of the clips, see Sync Multiple Clips
Call the sync
, syncWorker
, or syncWorkerConcurrent
method on the instance to find the synchronization point in samples between two audio clips.
// example "base" object
const base = {
channelData: [leftChannelFloat32Array, rightChannelFloat32Array]
samplesDecoded: 5678
};
// example "comparison" object
const comparison = {
channelData: [leftChannelFloat32Array, rightChannelFloat32Array]
samplesDecoded: 1234
}
const {
sampleOffset, // position relative to `base` where `comparison` matches best
correlation, // covariance coefficient of the match [ ranging -1 (worst) to 1 (best) ]
} = await synAudio.syncWorkerConcurrent(
base, // audio data to use a base for the comparison
comparison, // audio data to compare against the base
4 // number of threads to spawn
);
syncMultiple
will find the best linear match(es) between a set of two or more clips. Internally, SynAudio will determine the correlation of every order combination of each clip and then will find the path(s) in this graph where the correlation is the highest.
Call the syncMultiple
method on the instance to find the best synchronization path between two or more audio clips.
// example "clips" array
const clips = [
{
name: "clip1",
data: {
channelData: [leftChannelFloat32Array, rightChannelFloat32Array]
samplesDecoded: 64445
}
},
{
name: "clip2",
data: {
channelData: [leftChannelFloat32Array, rightChannelFloat32Array]
samplesDecoded: 24323
}
},
{
name: "clip3",
data: {
channelData: [leftChannelFloat32Array, rightChannelFloat32Array]
samplesDecoded: 45675
}
}
];
const results = await synAudio.syncMultiple(
clips, // array of clips to compare
8 // number of threads to spawn
);
The results
object will contain a two dimensional array of of match groups containing matching clips. Each match group represents an ordered list of matching audio clips where each clip relates to the previous. The sample offset within each match group is relative to the first clip in the series.
options.correlationThreshold
) found between the clips in the two match groups. If a clip were to exist that relates the two groups together, then the result would contain only one match group, and relate all other clips to the first one in sequential order.// results example
[
// first match group (no relation to second group)
[
{
name: "cut_1601425_Mpeg", // first clip in match
sampleOffset: 0,
},
{
name: "cut_2450800_Mpeg",
correlation: 0.9846370220184326,
sampleOffset: 849375, // position where this clip starts relative to the first clip
},
{
name: "cut_2577070_Mpeg",
correlation: 0.9878544973345423,
sampleOffset: 975645, // position where this clip starts relative to the first clip
},
],
// second match group (no relation to first group)
[
{
name: "cut_194648_Mpeg",
sampleOffset: 0,
},
{
name: "cut_287549_Mpeg",
correlation: 0.9885798096656799,
sampleOffset: 92901, // position where this clip starts relative to the first clip
},
]
]
SynAudio
Class that that finds the synchronization point between two or more similar audio clips.
new SynAudio({
correlationSampleSize: 1234,
initialGranularity: 1
});
declare interface SynAudioOptions {
correlationSampleSize?: number; // default 11025
initialGranularity?: number; // default 16
correlationThreshold?: number; // default 0.5
}
correlationSampleSize
optional, defaults to 11025
initialGranularity
optional, defaults to 16
correlationThreshold
optional, defaults to 0.5
syncMultiple
declare class SynAudio {
constructor(options?: SynAudioOptions);
/*
* Two Clips
*/
public async sync(
base: PCMAudio,
comparison: PCMAudio
): Promise<TwoClipMatch>;
public syncWorker(
base: PCMAudio,
comparison: PCMAudio
): Promise<TwoClipMatch>;
public syncWorkerConcurrent(
base: PCMAudio,
comparison: PCMAudio,
threads?: number // default 1
): Promise<TwoClipMatch>;
/*
* Multiple Clips
*/
public syncMultiple(
clips: AudioClip[],
threads?: number // default 8
): Promise<MultipleClipMatchList[]>;
}
sync(base: PCMAudio, comparison: PCMAudio): Promise<TwoClipMatch>
base
Audio data to compare againstcomparison
Audio data to use as a comparisonTwoClipMatch
that contains the correlation
and sampleOffset
syncWorker(base: PCMAudio, comparison: PCMAudio): Promise<TwoClipMatch>
base
Audio data to compare againstcomparison
Audio data to use as a comparisonTwoClipMatch
that contains the correlation
and sampleOffset
syncWorkerConcurrent(base: PCMAudio, comparison: PCMAudio, threads: number): Promise<TwoClipMatch>
base
Audio data to compare againstcomparison
Audio data to use as a comparisonthreads
Number of threads to spawn optional, defaults to 1TwoClipMatch
that contains the correlation
and sampleOffset
syncMultiple(clips: AudioClip[], threads?: number): Promise<MultipleClipMatch[][]>
clips
Array of AudioClip
(s) to comparethreads
Maximum number of threads to spawn optional, defaults to 8MultipleClipMatchList[]
Two dimensional array containing a list of each matching audio clip groupsinterface PCMAudio {
channelData: Float32Array[];
samplesDecoded: number;
}
channelData
samplesDecoded
interface AudioClip {
name: string;
data: PCMAudio;
}
name
data
interface TwoClipMatch {
correlation: number;
sampleOffset: number;
}
correlation
base
and comparison
audio at the sampleOffset
sampleOffset
base
where comparison
has the highest correlationdeclare type MultipleClipMatchList =
| []
| [MultipleClipMatchFirst, ...MultipleClipMatch];
declare interface MultipleClipMatchFirst {
name: string;
sampleOffset: 0;
}
declare interface MultipleClipMatch {
name: string;
correlation: number;
sampleOffset: number;
}
name
correlation
sampleOffset
source
the Emscripten path in the terminal you want build in.
$ source path/to/emsdk/emsdk_env.sh
npm i
to install the dependencies.make clean
and make
to build the libraries.
make -j8
where 8
is the number of CPU cores on your system to speed up the build.dist
folder.npm run test
to run the test suite.FAQs
Library that finds the synchronization point between two or more audio clips.
We found that synaudio demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.