Skip to content

Commit 454dc7a

Browse files
authored
Add readme + linting workflow (#1)
1 parent a3f33e5 commit 454dc7a

File tree

8 files changed

+162
-19
lines changed

8 files changed

+162
-19
lines changed

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run ESLint
2+
on: [pull_request]
3+
4+
env:
5+
GITHUB_TOKEN: ${{ github.token }}
6+
jobs:
7+
eslint:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-node@v2
12+
with:
13+
node-version: "16.x"
14+
- name: install dependencies
15+
run: npm ci
16+
- uses: reviewdog/action-eslint@v1
17+
with:
18+
reporter: github-pr-review
19+
eslint_flags: "src/"
20+
fail_on_error: "true"
21+
level: "warning"

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# **react-audio-visualize**
2+
An audio visualizer for React. Provides separate components to visualize both live audio and audio blobs.
3+
4+
## Installation
5+
```sh
6+
npm install react-audio-visualize
7+
```
8+
9+
## **AudioVisualizer** Component ([Example](https://stackblitz.com/edit/stackblitz-starters-kjpu5q?file=src%2FApp.tsx))
10+
11+
![screenshot](./assets/AudioVisualizer.png)
12+
13+
```js
14+
import React, { useState } from 'react';
15+
import { AudioVisualizer } from 'react-audio-visualize';
16+
17+
const Visualizer = () => {
18+
const [blob, setBlob] = useState<Blob>();
19+
20+
// set blob somewhere in code
21+
22+
return (
23+
<div>
24+
{blob && (
25+
<AudioVisualizer
26+
blob={blob}
27+
width={500}
28+
height={75}
29+
barWidth={1}
30+
gap={0}
31+
barColor={'#f76565'}
32+
/>
33+
)}
34+
</div>
35+
)
36+
}
37+
38+
```
39+
40+
| Props | Description | Default | Optional |
41+
| :------------ |:--------------- |:--------------- | :--------------- |
42+
| **`blob`** | Audio blob to visualize | N/A | No |
43+
| **`width`** | Width of the visualizer | N/A | No |
44+
| **`height`** | Height of the visualizer | N/A | No |
45+
| **`barWidth`** | Width of each individual bar in the visualization | `2` | Yes |
46+
| **`gap`** | Gap between each bar in the visualization | `1` | Yes |
47+
| **`backgroundColor`** | BackgroundColor for the visualization | `transparent` | Yes |
48+
| **`barColor`** | Color for the bars that have not yet been played | `"rgb(184, 184, 184)""` | Yes |
49+
| **`barPlayedColor`** | Color for the bars that have been played | `"rgb(160, 198, 255)""` | Yes |
50+
| **`currentTime`** | Current time stamp till which the audio blob has been played. Visualized bars that fall before the current time will have `barPlayerColor`, while that ones that fall after will have `barColor` | N/A | Yes |
51+
| **`style`** | Custom styles that can be passed to the visualization canvas | N/A | Yes |
52+
53+
---
54+
55+
## **LiveAudioVisualizer** Component ([Example](https://stackblitz.com/edit/stackblitz-starters-kjpu5q?file=src%2FApp.tsx))
56+
57+
![livevisualizergif](./assets/LiveAudioVisualizer.gif)
58+
59+
```js
60+
import React, { useState } from 'react';
61+
import { LiveAudioVisualizer } from 'react-audio-visualize';
62+
63+
const Visualizer = () => {
64+
const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder>();
65+
66+
// set media recorder somewhere in code
67+
68+
return (
69+
<div>
70+
{mediaRecorder && (
71+
<LiveAudioVisualizer
72+
mediaRecorder={mediaRecorder}
73+
width={200}
74+
height={75}
75+
/>
76+
)}
77+
</div>
78+
)
79+
}
80+
81+
```
82+
83+
| Props | Description | Default | Optional |
84+
| :------------ |:--------------- |:--------------- | :--------------- |
85+
| **`mediaRecorder`** | Media recorder who's stream needs to visualized | N/A | No |
86+
| **`width`** | Width of the visualizer | `100%` | Yes |
87+
| **`height`** | Height of the visualizer | `100%` | Yes |
88+
| **`barWidth`** | Width of each individual bar in the visualization | `2` | Yes |
89+
| **`gap`** | Gap between each bar in the visualization | `1` | Yes |
90+
| **`backgroundColor`** | BackgroundColor for the visualization | `transparent` | Yes |
91+
| **`barColor`** | Color for the bars that have not yet been played | `"rgb(160, 198, 255)"` | Yes |
92+
| **`fftSize`** | An unsigned integer, representing the window size of the FFT, given in number of samples. For more [details](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize) | `1024` | Yes |
93+
| **`maxDecibels`** | A double, representing the maximum decibel value for scaling the FFT analysis data. For more [details](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/maxDecibels) | `-10` | Yes |
94+
| **`minDecibels`** | A double, representing the minimum decibel value for scaling the FFT analysis data, where 0 dB is the loudest possible sound. For more [details](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/minDecibels) | `-90` | Yes |
95+
| **`smoothingTimeConstant`** | A double within the range 0 to 1 (0 meaning no time averaging). For more [details](https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant) | `0.4` | Yes |
96+
97+
98+

assets/AudioVisualizer.png

10.9 KB
Loading

assets/LiveAudioVisualizer.gif

346 KB
Loading

package-lock.json

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
{
22
"name": "react-audio-visualize",
3-
"private": true,
4-
"version": "0.0.0",
3+
"private": false,
4+
"version": "0.0.3",
55
"license": "MIT",
66
"author": "",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/samhirtarif/"
9+
"url": "https://github.com/samhirtarif/react-audio-visualize.git"
1010
},
11-
"keywords": [],
11+
"keywords": [
12+
"audio",
13+
"visualize",
14+
"visualise",
15+
"visualizer",
16+
"visualiser",
17+
"audio visualiser",
18+
"audio visualizer",
19+
"audio visualize",
20+
"audio visualise",
21+
"audio waveform",
22+
"waveform",
23+
"audio visualization",
24+
"visualization"
25+
],
1226
"files": [
1327
"dist",
14-
"README.md"
28+
"README.md",
29+
"assets"
1530
],
1631
"main": "./dist/react-audio-visualize.umd.js",
1732
"module": "./dist/react-audio-visualize.es.js",
@@ -29,10 +44,6 @@
2944
"lint": "eslint src/**/*.ts{,x}",
3045
"lint:fix": "npm run lint -- --fix"
3146
},
32-
"dependencies": {
33-
"react": "^18.2.0",
34-
"react-dom": "^18.2.0"
35-
},
3647
"devDependencies": {
3748
"@types/node": "^20.2.1",
3849
"@types/react": "^18.0.28",
@@ -49,8 +60,14 @@
4960
"eslint-plugin-react-refresh": "^0.3.4",
5061
"path": "^0.12.7",
5162
"prettier": "^2.8.8",
63+
"react": "^18.2.0",
64+
"react-dom": "^18.2.0",
5265
"typescript": "^5.0.2",
5366
"vite": "^4.3.2",
5467
"vite-plugin-dts": "^2.3.0"
68+
},
69+
"peerDependencies": {
70+
"react": "^18.2.0",
71+
"react-dom": "^18.2.0"
5572
}
5673
}

src/AudioVisualizer/AudioVisualizer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Props {
77
/**
88
* Audio blob to visualize
99
*/
10-
blob?: Blob;
10+
blob: Blob;
1111
/**
1212
* Width of the visualizer
1313
*/

src/LiveAudioVisualizer/LiveAudioVisualizer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface Props {
3737
*/
3838
barColor?: string;
3939
/**
40-
* An unsigned integer, representing the window size of the FFT, given in number of samples.
40+
* An unsigned integer, representing the window size of the FFT, given in number of samples.
4141
* A higher value will result in more details in the frequency domain but fewer details in the amplitude domain.
4242
* For more details {@link https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/fftSize MDN AnalyserNode: fftSize property}
4343
* Default: `1024`
@@ -68,7 +68,7 @@ export interface Props {
6868
minDecibels?: number;
6969
/**
7070
* A double within the range 0 to 1 (0 meaning no time averaging). The default value is 0.8.
71-
* If 0 is set, there is no averaging done, whereas a value of 1 means "overlap the previous and current buffer quite a lot while computing the value",
71+
* If 0 is set, there is no averaging done, whereas a value of 1 means "overlap the previous and current buffer quite a lot while computing the value",
7272
* which essentially smooths the changes across
7373
* For more details {@link https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode/smoothingTimeConstant MDN AnalyserNode: smoothingTimeConstant property}
7474
* Default: `0.4`

0 commit comments

Comments
 (0)