Skip to content

Commit

Permalink
Lazy load audio visualizer (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
samhirtarif authored Jun 10, 2023
1 parent 135871c commit 5694c7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-audio-voice-recorder",
"private": false,
"version": "1.2.0",
"version": "1.2.1",
"license": "MIT",
"author": "",
"repository": {
Expand Down
32 changes: 19 additions & 13 deletions src/components/AudioRecordingComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useEffect, ReactElement } from "react";
import React, { useState, useEffect, ReactElement, Suspense } from "react";
import { Props } from "./interfaces";
import useAudioRecorder from "../hooks/useAudioRecorder";
import { LiveAudioVisualizer } from "react-audio-visualize";

import micSVG from "../icons/mic.svg";
import pauseSVG from "../icons/pause.svg";
Expand All @@ -10,6 +9,11 @@ import saveSVG from "../icons/save.svg";
import discardSVG from "../icons/stop.svg";
import "../styles/audio-recorder.css";

const LiveAudioVisualizer = React.lazy(async () => {
const { LiveAudioVisualizer } = await import("react-audio-visualize");
return { default: LiveAudioVisualizer };
});

/**
* Usage: https://github.com/samhirtarif/react-audio-recorder#audiorecorder-component
*
Expand Down Expand Up @@ -117,17 +121,19 @@ const AudioRecorder: (props: Props) => ReactElement = ({
}`}
>
{mediaRecorder && (
<LiveAudioVisualizer
mediaRecorder={mediaRecorder}
barWidth={2}
gap={2}
width={140}
height={30}
fftSize={512}
maxDecibels={-10}
minDecibels={-80}
smoothingTimeConstant={0.4}
/>
<Suspense fallback={<></>}>
<LiveAudioVisualizer
mediaRecorder={mediaRecorder}
barWidth={2}
gap={2}
width={140}
height={30}
fftSize={512}
maxDecibels={-10}
minDecibels={-80}
smoothingTimeConstant={0.4}
/>
</Suspense>
)}
</span>
) : (
Expand Down

0 comments on commit 5694c7b

Please sign in to comment.