use-voice-control 0.1.35 → 0.1.37
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 +2 -5
- package/package.json +5 -1
- package/speech/api-client.ts +68 -0
package/README.md
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
<br />
|
|
4
4
|
<a href="https://www.npmjs.com/package/use-voice-control"><img src="https://img.shields.io/npm/dm/use-voice-control.svg" alt="NPM Monthly Downloads"></a>
|
|
5
5
|
<a href="https://www.npmjs.com/package/use-voice-control"><img src="https://img.shields.io/npm/v/use-voice-control.svg" alt="npm version"></a>
|
|
6
|
-
<a href="https://
|
|
7
|
-
<img
|
|
8
|
-
src="https://img.shields.io/bundlephobia/minzip/use-voice-control?style=flat&label=size"
|
|
9
|
-
alt="npm bundle size "
|
|
10
|
-
/>
|
|
6
|
+
<a href="https://packagephobia.com/result?p=use-voice-control" target="_blank" rel="noopener noreferrer">
|
|
7
|
+
<img src="https://packagephobia.com/badge?p=use-voice-control" alt="install size" />
|
|
11
8
|
</a>
|
|
12
9
|
<a href="https://discord.gg/SJdBqBz3tV">
|
|
13
10
|
<img src="https://img.shields.io/discord/1110227955554209923.svg?label=Chat&logo=Discord&colorB=7289da&style=flat"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-voice-control",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
4
4
|
"description": "React voice control with speech transcription, vocalization, and interruption (STT/TTS/VAD) support.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./api-client": {
|
|
19
|
+
"types": "./speech/api-client.ts",
|
|
20
|
+
"import": "./speech/api-client.ts"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TTSOptions } from "./types/types";
|
|
2
|
+
|
|
3
|
+
export async function generateSpeechFromText(
|
|
4
|
+
text: string,
|
|
5
|
+
provider: "kokoro" | "deepgram" = "kokoro",
|
|
6
|
+
voice?: string
|
|
7
|
+
): Promise<Blob> {
|
|
8
|
+
const options: TTSOptions = {
|
|
9
|
+
text,
|
|
10
|
+
provider,
|
|
11
|
+
voice,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const response = await fetch("/api/speech/tts", {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(options),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const error = await response.json();
|
|
24
|
+
throw new Error(error.error || `TTS failed: ${response.statusText}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const contentType = response.headers.get("Content-Type") || "audio/wav";
|
|
28
|
+
return new Blob([await response.arrayBuffer()], { type: contentType });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function createAudioURL(
|
|
32
|
+
text: string,
|
|
33
|
+
provider: "kokoro" | "deepgram" = "kokoro",
|
|
34
|
+
voice?: string
|
|
35
|
+
): Promise<string> {
|
|
36
|
+
const blob = await generateSpeechFromText(text, provider, voice);
|
|
37
|
+
return URL.createObjectURL(blob);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function speakText(
|
|
41
|
+
text: string,
|
|
42
|
+
provider: "kokoro" | "deepgram" = "kokoro",
|
|
43
|
+
voice?: string
|
|
44
|
+
): Promise<void> {
|
|
45
|
+
const audioURL = await createAudioURL(text, provider, voice);
|
|
46
|
+
const audio = new Audio(audioURL);
|
|
47
|
+
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
audio.addEventListener("ended", () => {
|
|
50
|
+
URL.revokeObjectURL(audioURL);
|
|
51
|
+
resolve();
|
|
52
|
+
});
|
|
53
|
+
audio.addEventListener("error", () => {
|
|
54
|
+
URL.revokeObjectURL(audioURL);
|
|
55
|
+
reject(new Error("Audio playback failed"));
|
|
56
|
+
});
|
|
57
|
+
audio.play().catch(reject);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function checkSTTAPI(): Promise<boolean> {
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch("/api/speech/stt", { method: "GET" });
|
|
64
|
+
return response.ok;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|