use-read-aloud 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -16
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -18,21 +18,47 @@ npm install use-read-aloud
|
|
|
18
18
|
|
|
19
19
|
```tsx
|
|
20
20
|
import { useReadAloud } from "use-read-aloud";
|
|
21
|
+
import { useState } from "react";
|
|
22
|
+
import {
|
|
23
|
+
FastForward,
|
|
24
|
+
Minus,
|
|
25
|
+
Pause,
|
|
26
|
+
Play,
|
|
27
|
+
Plus,
|
|
28
|
+
Rewind,
|
|
29
|
+
RotateCcw,
|
|
30
|
+
Volume2,
|
|
31
|
+
} from "lucide-react";
|
|
21
32
|
|
|
22
33
|
function AudioPlayer({ text }: { text: string }) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
const [playBackSpeed, setPlayBackSpeed] = useState<number>(1);
|
|
35
|
+
|
|
36
|
+
const { isPaused, togglePlay, fastForward, seekBackward, replay } =
|
|
37
|
+
useReadAloud(text, {
|
|
38
|
+
rate: playBackSpeed,
|
|
39
|
+
});
|
|
27
40
|
|
|
28
41
|
return (
|
|
29
42
|
<div>
|
|
30
|
-
<button onClick={
|
|
31
|
-
|
|
43
|
+
<button onClick={seekBackward}>
|
|
44
|
+
<Rewind />
|
|
32
45
|
</button>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
<button onClick={togglePlay}>{isPaused ? <Play /> : <Pause />}</button>
|
|
47
|
+
<button onClick={fastForward}>
|
|
48
|
+
<FastForward />
|
|
49
|
+
</button>
|
|
50
|
+
<button onClick={replay}>
|
|
51
|
+
<RotateCcw />
|
|
52
|
+
</button>
|
|
53
|
+
<span>
|
|
54
|
+
<button onClick={() => setPlayBackSpeed(playBackSpeed - 0.25)}>
|
|
55
|
+
<Minus />
|
|
56
|
+
</button>
|
|
57
|
+
{`${playBackSpeed}x`}
|
|
58
|
+
<button onClick={() => setPlayBackSpeed(playBackSpeed + 0.25)}>
|
|
59
|
+
<Plus />
|
|
60
|
+
</button>
|
|
61
|
+
</span>
|
|
36
62
|
</div>
|
|
37
63
|
);
|
|
38
64
|
}
|
|
@@ -41,14 +67,14 @@ function AudioPlayer({ text }: { text: string }) {
|
|
|
41
67
|
## API
|
|
42
68
|
|
|
43
69
|
```
|
|
44
|
-
useReadAloud(
|
|
70
|
+
useReadAloud(text, options?)
|
|
45
71
|
```
|
|
46
72
|
|
|
47
73
|
### Parameters
|
|
48
74
|
|
|
49
|
-
-
|
|
75
|
+
- text - the text to be read.
|
|
50
76
|
|
|
51
|
-
- options
|
|
77
|
+
- options - options to specify rate and pitch of the speech
|
|
52
78
|
|
|
53
79
|
```ts
|
|
54
80
|
type Options = {
|
|
@@ -61,11 +87,13 @@ type Options = {
|
|
|
61
87
|
|
|
62
88
|
```ts
|
|
63
89
|
{
|
|
64
|
-
isReading: boolean;
|
|
65
90
|
isPaused: boolean;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
91
|
+
play: () => void;
|
|
92
|
+
pause: () => void;
|
|
93
|
+
replay: () => void;
|
|
94
|
+
seekBackward: () => void;
|
|
95
|
+
fastForward: () => void;
|
|
96
|
+
togglePlay: () => void;
|
|
69
97
|
}
|
|
70
98
|
```
|
|
71
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-read-aloud",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A React hook for reading text aloud using the Web Speech API",
|
|
6
6
|
"author": "Siva Murugan",
|
|
@@ -23,13 +23,16 @@
|
|
|
23
23
|
"dev": "vite",
|
|
24
24
|
"types": "tsc --emitDeclarationOnly",
|
|
25
25
|
"build": "vite build && tsc --emitDeclarationOnly",
|
|
26
|
-
"lint": "eslint ."
|
|
26
|
+
"lint": "eslint .",
|
|
27
|
+
"test": "vitest"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
30
|
"react": ">=18"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@eslint/js": "^9.39.1",
|
|
34
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
35
|
+
"@testing-library/react": "^16.3.1",
|
|
33
36
|
"@types/node": "^24.10.1",
|
|
34
37
|
"@types/react": "^19.2.5",
|
|
35
38
|
"@types/react-dom": "^19.2.3",
|
|
@@ -38,9 +41,11 @@
|
|
|
38
41
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
39
42
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
40
43
|
"globals": "^16.5.0",
|
|
44
|
+
"happy-dom": "^20.0.11",
|
|
41
45
|
"typescript": "~5.9.3",
|
|
42
46
|
"typescript-eslint": "^8.46.4",
|
|
43
|
-
"vite": "^7.2.4"
|
|
47
|
+
"vite": "^7.2.4",
|
|
48
|
+
"vitest": "^4.0.16"
|
|
44
49
|
},
|
|
45
50
|
"repository": {
|
|
46
51
|
"type": "git",
|