From 27a6e3b03374bea70060d4274a90e4d24cd4dd35 Mon Sep 17 00:00:00 2001 From: Mohammadreza Fallahfaal Date: Fri, 5 Dec 2025 15:17:53 +0330 Subject: [PATCH] Update README.md to enhance documentation and add new features - Revised description for clarity and conciseness. - Added new properties (width, height, style) to VoiceRecorderProps for customization. - Expanded the UseVoiceRecorderReturn type with a new 'restart' method. - Introduced a time formatting function for better time display in the UI. - Updated the example UI to include the restart functionality and improved button layout. - Added a new features section to highlight capabilities of the voice recorder. --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 04499e64..8c75ee1c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # react-voice-recorder-kit -A lightweight, dependency-free React voice recorder library with a simple waveform visualization. +A lightweight React voice recorder library with waveform visualization and no UI framework dependencies. * No UI framework dependencies (pure React + inline CSS) * Built-in animated waveform (40 bars) @@ -95,6 +95,9 @@ type VoiceRecorderProps = { autoStart?: boolean onStop?: (file: File, url: string) => void onDelete?: () => void + width?: string | number + height?: string | number + style?: CSSProperties } ``` @@ -103,6 +106,9 @@ type VoiceRecorderProps = { | autoStart | boolean | true | Automatically start recording on mount | | onStop | (file: File, url: string) => void | undefined | Callback after recording stops | | onDelete | () => void | undefined | Callback after recording is deleted | +| width | string \| number | '100%' | Component width | +| height | string \| number | undefined | Component height | +| style | CSSProperties | undefined | Additional styles for container | --- @@ -144,9 +150,28 @@ type UseVoiceRecorderReturn = { stop: () => void togglePlay: () => void deleteRecording: () => void + restart: () => void } ``` +| Property | Type | Description | +| --------------- | -------------- | ---------------------------------------------- | +| isRecording | boolean | Whether recording is active | +| isStopped | boolean | Whether recording has stopped | +| isPlaying | boolean | Whether playback is active | +| isPaused | boolean | Whether recording is paused | +| seconds | number | Time in seconds | +| levels | number[] | Array of 40 audio levels (0 to 1) | +| error | string \| null | Error message if any | +| audioUrl | string \| null | URL of the recorded audio file | +| audioFile | File \| null | Recorded audio file | +| start | () => void | Start recording | +| togglePause | () => void | Pause or resume recording | +| stop | () => void | Stop recording | +| togglePlay | () => void | Play or pause playback of recorded file | +| deleteRecording | () => void | Delete recording and reset to initial state | +| restart | () => void | Restart recording (only available when paused) | + --- ## Full Example Using Hook (Custom UI) @@ -171,27 +196,45 @@ export default function CustomRecorder() { togglePause, stop, togglePlay, - deleteRecording + deleteRecording, + restart } = useVoiceRecorder({ autoStart: false }) + const formatTime = (secs: number) => { + const minutes = Math.floor(secs / 60) + const sec = secs % 60 + return `${minutes}:${sec.toString().padStart(2, '0')}` + } + return (

Custom Voice Recorder

- Time: {seconds}s + Time: {formatTime(seconds)}
- + - + {isPaused && ( + + )} + - +
{error && ( @@ -222,8 +265,8 @@ export default function CustomRecorder() { background: '#444' }} /> - )} - )} + ) + })}
{audioUrl && ( @@ -238,6 +281,20 @@ export default function CustomRecorder() { --- +## Features + +* Voice recording using MediaRecorder API +* Animated waveform visualization during recording and playback +* Pause/resume support +* Playback support for recorded files +* Time display in MM:SS format +* Error handling and error message display +* Ready-to-use UI with control buttons +* Customizable style and size +* No external dependencies + +--- + ## License MIT