Skip to content

🎥 Make videos programmatically with React

handle quiet audio waves

UmungoBungo48a5bfb90a48
diff --git a/packages/media-utils/src/get-wave-form-samples.ts b/packages/media-utils/src/get-wave-form-samples.ts
index 7e17680c2f..b174700b10 100644
--- a/packages/media-utils/src/get-wave-form-samples.ts
+++ b/packages/media-utils/src/get-wave-form-samples.ts
@@ -18,10 +18,18 @@ const filterData = (audioBuffer: Float32Array, samples: number) => {
return filteredData;
};
-const normalizeData = (filteredData: number[]) => {
- const max = Math.max(...filteredData);
- const multiplier = max === 0 ? 0 : max ** -1;
- return filteredData.map((n) => n * multiplier);
+const normalizeData = (filteredData) => {
+ const max = Math.max(...filteredData);
+
+ // If the maximum amplitude is below this threshold, treat it as silence
+ const MINIMUM_AMPLITUDE_THRESHOLD = 0.001;
+
+ if (max < MINIMUM_AMPLITUDE_THRESHOLD) {
+ return new Array(filteredData.length).fill(0);
+ }
+
+ const multiplier = max ** -1;
+ return filteredData.map((n) => n * multiplier);
};
export const getWaveformSamples = (