Skip to content

Commit d6d2c18

Browse files
committed
Update version to 1.5.1 and enhance silence detection functionality
- Bump package version from 1.5.0 to 1.5.1 in package.json. - Ensure `removeSilences` method in `MediaClip` initializes correctly based on state. - Clarify documentation for `SilenceDetectionOptions`, specifying minimum duration in milliseconds. - Update silence detection utility to convert minimum duration from milliseconds to samples for accurate processing. These changes improve the robustness and clarity of silence handling in audio processing.
1 parent 48198ff commit d6d2c18

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@diffusionstudio/core",
33
"private": false,
4-
"version": "1.5.0",
4+
"version": "1.5.1",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/clips/media/media.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends Cl
321321
* @param options - Options for silence detection
322322
*/
323323
public async removeSilences(options: SilenceRemoveOptions = {}): Promise<MediaClip<Props>[]> {
324+
if (!['READY', 'ATTACHED'].includes(this.state)) {
325+
await this.init();
326+
}
327+
324328
const silences = (await this.source.silences(options))
325329
.filter((silence) => inRange(silence, this.range))
326330
.sort((a, b) => a.start.millis - b.start.millis);

src/sources/audio.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export type SilenceDetectionOptions = {
2929
*/
3030
threshold?: number;
3131
/**
32-
* This parameter affect how accurately the algorithm captures short silences.
32+
* This parameter affects how accurately the algorithm captures short silences.
3333
* @default 1024
3434
*/
3535
hopSize?: number;
3636
/**
37-
* Setting a minimum duration for a silence period helps avoid detecting brief gaps between sounds as silences.
38-
* @default 0.5
37+
* Setting a minimum duration in **milliseconds** for a silence period helps avoid detecting brief gaps between sounds as silences.
38+
* @default 500
3939
*/
4040
minDuration?: number;
4141
};

src/sources/audio.utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ import type { AudioSlice, SilenceDetectionOptions } from './audio.types';
66
/**
77
* Detect silences in an audio buffer
88
* @param audioBuffer - The web audio buffer.
9-
* @param threshold - The threshold for silence detection.
10-
* @param hopSize - The hop size between frames in samples.
11-
* @param minDuration - Minimum duration for a silence in seconds.
12-
* @returns An array of the silences in the clip.
9+
* @param options - Options for silence detection
1310
*/
1411
export function detectSilences(
1512
audioBuffer: AudioBuffer,
1613
options: SilenceDetectionOptions = {}
1714
): AudioSlice[] {
18-
const { threshold = 0.02, hopSize = 1024, minDuration = 0.5 } = options;
15+
const { threshold = 0.02, hopSize = 1024, minDuration = 500 } = options;
1916

2017
const slices: AudioSlice[] = [];
2118
const channel = audioBuffer.getChannelData(0);
2219
const sampleRate = audioBuffer.sampleRate;
2320

24-
// Convert minDuration from seconds to samples
25-
const minSamples = Math.floor(minDuration * sampleRate);
21+
// Convert minDuration from milliseconds to samples
22+
const minSamples = Math.floor((minDuration / 1000) * sampleRate);
2623

2724
let silenceStart: number | null = null;
2825
let consecutiveSilentSamples = 0;

0 commit comments

Comments
 (0)