use-voice-control 0.1.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.
Files changed (3) hide show
  1. package/README.md +522 -0
  2. package/package.json +54 -0
  3. package/readme.md +1 -0
package/README.md ADDED
@@ -0,0 +1,522 @@
1
+ <p align="center">
2
+ <img src="https://i.imgur.com/ypVzqbg.png" width="200" />
3
+ <br />
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
+ <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://discord.gg/SJdBqBz3tV">
7
+ <img src="https://img.shields.io/discord/1110227955554209923.svg?label=Chat&logo=Discord&colorB=7289da&style=flat"
8
+ alt="Join Discord" />
9
+ </a>
10
+ <a href="https://github.com/OpenSourceAGI/qwksearch-research-agent/discussions">
11
+ <img alt="GitHub Stars" src="https://img.shields.io/github/stars/OpenSourceAGI/qwksearch-research-agent" /></a>
12
+ <br />
13
+ <a href="https://github.com/OpenSourceAGI/qwksearch-research-agent/discussions">
14
+ <img alt="GitHub Discussions"
15
+ src="https://img.shields.io/github/discussions/OpenSourceAGI/qwksearch-research-agent" />
16
+ </a>
17
+ <a href="https://github.com/OpenSourceAGI/qwksearch-research-agent/pulse" alt="Activity">
18
+ <img src="https://img.shields.io/github/commit-activity/m/OpenSourceAGI/qwksearch-research-agent" />
19
+ </a>
20
+ <img src="https://img.shields.io/github/last-commit/OpenSourceAGI/qwksearch-research-agent.svg" alt="GitHub last commit" />
21
+ <br />
22
+ <a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request">
23
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"
24
+ alt="PRs Welcome" />
25
+ </a>
26
+ <a href="https://codespaces.new/OpenSourceAGI/qwksearch-research-agent">
27
+ <img src="https://github.com/codespaces/badge.svg" width="150" height="20" />
28
+ </a>
29
+ </p>
30
+
31
+ <p align="center">
32
+ <a href="https://www.npmjs.com/package/use-voice-control">NPM</a> β€’
33
+ <a href="https://github.com/OpenSourceAGI/qwksearch-research-agent/tree/master/packages/use-voice-control">GitHub</a> β€’
34
+ <a href="https://discord.gg/SJdBqBz3tV">Discord</a>
35
+ </p>
36
+
37
+ ## use-voice-control
38
+
39
+ React hooks and components for seamless voice control and speech I/O (Speech-to-Text and Text-to-Speech). Build voice-enabled applications with client-side speech recognition and server-side or client-side speech synthesis.
40
+
41
+ ```bash
42
+ npm install use-voice-control
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 🎀 Features
48
+
49
+ ### Speech-to-Text (STT)
50
+ - **Moonshine.js**: Fast, accurate client-side speech recognition running entirely in the browser
51
+ - **WebRTC Audio Capture**: Real-time microphone input with automatic gain control
52
+ - **Multi-language Support**: Recognize speech in 100+ languages
53
+ - **Offline-First**: No external API calls required for STT
54
+
55
+ ### Text-to-Speech (TTS)
56
+ - **Kokoro TTS**: Natural-sounding synthesis on Node.js/Edge with 16 pre-trained voices
57
+ - **Deepgram TTS**: Enterprise-grade speech synthesis with 12 Aura voices
58
+ - **Server & Client Support**: Run on backend or stream to client
59
+ - **Multiple Output Formats**: WAV, PCM, or raw audio buffers
60
+
61
+ ### React Integration
62
+ - **Custom Hooks**: `useVoiceControl()`, `useSpeechRecognition()`, `useSpeechSynthesis()`
63
+ - **Pre-built Components**: Audio recorder, voice selector, playback controls
64
+ - **State Management**: Streaming, loading, error handling baked in
65
+
66
+ ---
67
+
68
+ ## πŸš€ Quick Start
69
+
70
+ ### Installation
71
+
72
+ ```bash
73
+ npm install use-voice-control
74
+ ```
75
+
76
+ ### Basic STT Example
77
+
78
+ ```ts
79
+ import { useSpeechRecognition } from 'use-voice-control/hooks';
80
+
81
+ export function VoiceInput() {
82
+ const { isListening, transcript, startListening, stopListening } = useSpeechRecognition({
83
+ language: 'en-US'
84
+ });
85
+
86
+ return (
87
+ <div>
88
+ <button onClick={startListening} disabled={isListening}>
89
+ 🎀 Start Recording
90
+ </button>
91
+ <button onClick={stopListening} disabled={!isListening}>
92
+ ⏹️ Stop
93
+ </button>
94
+ <p>You said: {transcript}</p>
95
+ </div>
96
+ );
97
+ }
98
+ ```
99
+
100
+ ### Basic TTS Example
101
+
102
+ ```ts
103
+ import { useSpeechSynthesis } from 'use-voice-control/hooks';
104
+
105
+ export function VoiceOutput() {
106
+ const { speak, isSpeaking } = useSpeechSynthesis({
107
+ provider: 'kokoro',
108
+ voice: 'af_heart' // Female voice
109
+ });
110
+
111
+ return (
112
+ <button onClick={() => speak("Hello, world!")}>
113
+ {isSpeaking ? 'πŸ”Š Speaking...' : '▢️ Play'}
114
+ </button>
115
+ );
116
+ }
117
+ ```
118
+
119
+ ---
120
+
121
+ ## πŸ“š API Reference
122
+
123
+ ### Hooks
124
+
125
+ #### `useSpeechRecognition(options)`
126
+
127
+ Captures audio from the user's microphone and converts it to text using Moonshine.js.
128
+
129
+ **Options:**
130
+ ```ts
131
+ interface SpeechRecognitionOptions {
132
+ language?: string; // Default: 'en-US'
133
+ autoStart?: boolean; // Default: false
134
+ onTranscript?: (text: string) => void;
135
+ onError?: (error: Error) => void;
136
+ autoStopTimeout?: number; // Auto-stop after silence (ms)
137
+ }
138
+ ```
139
+
140
+ **Returns:**
141
+ ```ts
142
+ {
143
+ transcript: string; // Current transcribed text
144
+ isListening: boolean; // Recording in progress
145
+ isFinal: boolean; // Transcript is final
146
+ startListening: () => void;
147
+ stopListening: () => void;
148
+ resetTranscript: () => void;
149
+ error: Error | null;
150
+ }
151
+ ```
152
+
153
+ ---
154
+
155
+ #### `useSpeechSynthesis(options)`
156
+
157
+ Converts text to speech and plays it back with optional streaming.
158
+
159
+ **Options:**
160
+ ```ts
161
+ interface SpeechSynthesisOptions {
162
+ provider?: 'kokoro' | 'deepgram'; // Default: 'kokoro'
163
+ voice?: string; // Provider-specific voice ID
164
+ rate?: number; // Speech rate (0.5 - 2.0)
165
+ pitch?: number; // Voice pitch (0.5 - 2.0)
166
+ volume?: number; // Volume (0 - 1)
167
+ onError?: (error: Error) => void;
168
+ }
169
+ ```
170
+
171
+ **Returns:**
172
+ ```ts
173
+ {
174
+ speak: (text: string) => Promise<void>;
175
+ pause: () => void;
176
+ resume: () => void;
177
+ stop: () => void;
178
+ isSpeaking: boolean;
179
+ isPaused: boolean;
180
+ currentTime: number;
181
+ duration: number;
182
+ error: Error | null;
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ #### `useVoiceControl(options)`
189
+
190
+ Combined STT + TTS hook for full voice control workflows.
191
+
192
+ **Options:**
193
+ ```ts
194
+ interface VoiceControlOptions {
195
+ sttOptions?: SpeechRecognitionOptions;
196
+ ttsOptions?: SpeechSynthesisOptions;
197
+ onTranscriptEnd?: (transcript: string) => Promise<string>;
198
+ autoPlayResponse?: boolean; // Auto-play TTS response
199
+ }
200
+ ```
201
+
202
+ **Returns:**
203
+ ```ts
204
+ {
205
+ // STT state
206
+ transcript: string;
207
+ isListening: boolean;
208
+ // TTS state
209
+ isSpeaking: boolean;
210
+ // Combined control
211
+ toggleListening: () => void;
212
+ speak: (text: string) => void;
213
+ reset: () => void;
214
+ }
215
+ ```
216
+
217
+ ---
218
+
219
+ ### Voice Options
220
+
221
+ #### Kokoro Voices
222
+
223
+ 16 professional voices optimized for natural speech synthesis:
224
+
225
+ **Female Voices:**
226
+ ```
227
+ af_heart - Warm, caring tone
228
+ af_alloy - Neutral, professional
229
+ af_aoede - Bright, energetic
230
+ af_bella - Soft, gentle
231
+ af_jessica - Friendly, conversational
232
+ af_nicole - Clear, articulate
233
+ af_river - Calm, soothing
234
+ af_sarah - Warm, approachable
235
+ af_sky - Young, vibrant
236
+ ```
237
+
238
+ **Male Voices:**
239
+ ```
240
+ am_adam - Deep, authoritative
241
+ am_echo - Resonant, smooth
242
+ am_fable - Narrative, engaging
243
+ am_fenrir - Bold, strong
244
+ am_liam - Friendly, warm
245
+ am_michael - Professional, clear
246
+ am_onyx - Dark, mysterious
247
+ ```
248
+
249
+ **Example:**
250
+ ```ts
251
+ const { speak } = useSpeechSynthesis({
252
+ provider: 'kokoro',
253
+ voice: 'af_heart'
254
+ });
255
+ ```
256
+
257
+ ---
258
+
259
+ #### Deepgram Aura Voices
260
+
261
+ 12 natural-sounding voices for enterprise applications:
262
+
263
+ ```
264
+ angus, asteria, arcas, orion, orpheus, athena,
265
+ luna, zeus, perseus, helios, hera, stella
266
+ ```
267
+
268
+ **Example:**
269
+ ```ts
270
+ const { speak } = useSpeechSynthesis({
271
+ provider: 'deepgram',
272
+ voice: 'luna'
273
+ });
274
+ ```
275
+
276
+ ---
277
+
278
+ ### Components
279
+
280
+ #### `<AudioRecorder />`
281
+
282
+ Pre-built recording interface with visual feedback.
283
+
284
+ ```tsx
285
+ import { AudioRecorder } from 'use-voice-control/components';
286
+
287
+ <AudioRecorder
288
+ onTranscript={(text) => console.log(text)}
289
+ language="en-US"
290
+ />
291
+ ```
292
+
293
+ #### `<VoiceSelector />`
294
+
295
+ Dropdown to choose between available voices.
296
+
297
+ ```tsx
298
+ import { VoiceSelector } from 'use-voice-control/components';
299
+
300
+ <VoiceSelector
301
+ provider="kokoro"
302
+ onChange={(voice) => setSelectedVoice(voice)}
303
+ />
304
+ ```
305
+
306
+ #### `<AudioPlayer />`
307
+
308
+ Controls for playback of generated speech.
309
+
310
+ ```tsx
311
+ import { AudioPlayer } from 'use-voice-control/components';
312
+
313
+ <AudioPlayer
314
+ src={audioUrl}
315
+ autoPlay={false}
316
+ />
317
+ ```
318
+
319
+ ---
320
+
321
+ ## πŸ”Œ Core API
322
+
323
+ ### Server-Side Speech Synthesis
324
+
325
+ Generate speech audio directly from the server or Edge runtime:
326
+
327
+ ```ts
328
+ import { generateSpeech } from 'use-voice-control/speech';
329
+
330
+ // Generate Kokoro speech
331
+ const audio = await generateSpeech({
332
+ text: "Hello, world!",
333
+ provider: 'kokoro',
334
+ voice: 'af_heart'
335
+ });
336
+
337
+ // Returns: { audio: ArrayBuffer, contentType: string }
338
+ ```
339
+
340
+ ### TypeScript Support
341
+
342
+ Full type definitions included:
343
+
344
+ ```ts
345
+ import type { TTSProvider, KokoroVoice, DeepgramSpeaker } from 'use-voice-control/speech';
346
+
347
+ const provider: TTSProvider = 'kokoro';
348
+ const voice: KokoroVoice = 'af_heart';
349
+ ```
350
+
351
+ ---
352
+
353
+ ## πŸ—οΈ Architecture
354
+
355
+ ### Speech-to-Text Pipeline
356
+ 1. **Audio Capture** β†’ WebRTC microphone input with automatic gain control
357
+ 2. **Buffering** β†’ Circular audio buffer with silence detection
358
+ 3. **Inference** β†’ Moonshine.js runs model in Web Worker to avoid blocking
359
+ 4. **Streaming** β†’ Real-time transcript updates as user speaks
360
+ 5. **Final Output** β†’ Complete transcript on stop or timeout
361
+
362
+ ### Text-to-Speech Pipeline
363
+ 1. **Input Processing** β†’ Text validation and segmentation
364
+ 2. **Synthesis** β†’ Kokoro or Deepgram provider synthesis
365
+ 3. **Format Conversion** β†’ Audio buffer to playable format
366
+ 4. **Streaming** β†’ Optional chunked playback
367
+ 5. **Playback Control** β†’ Native audio element with pause/resume/volume
368
+
369
+ ---
370
+
371
+ ## 🎯 Use Cases
372
+
373
+ ### Customer Support Chatbots
374
+ ```tsx
375
+ <VoiceControl
376
+ onTranscriptEnd={async (text) => {
377
+ const response = await fetchChatbotResponse(text);
378
+ return response;
379
+ }}
380
+ autoPlayResponse={true}
381
+ />
382
+ ```
383
+
384
+ ### Voice-Controlled Search
385
+ ```tsx
386
+ const { transcript, speak } = useVoiceControl();
387
+
388
+ const handleSearch = async () => {
389
+ const results = await searchAPI(transcript);
390
+ speak(`Found ${results.length} results`);
391
+ };
392
+ ```
393
+
394
+ ### Accessibility Features
395
+ ```tsx
396
+ <AudioRecorder onTranscript={setText} />
397
+ <VoiceButton onClick={() => speak(text)} />
398
+ ```
399
+
400
+ ### Multilingual Apps
401
+ ```ts
402
+ useSpeechRecognition({ language: 'es-ES' });
403
+ useSpeechSynthesis({ voice: 'af_bella' });
404
+ ```
405
+
406
+ ---
407
+
408
+ ## βš™οΈ Configuration
409
+
410
+ ### Next.js Integration
411
+
412
+ Add to `next.config.js`:
413
+
414
+ ```js
415
+ module.exports = {
416
+ webpack: (config, { isServer }) => {
417
+ if (!isServer) {
418
+ config.resolve.fallback = {
419
+ ...config.resolve.fallback,
420
+ fs: false,
421
+ path: false,
422
+ };
423
+ }
424
+ return config;
425
+ },
426
+ };
427
+ ```
428
+
429
+ ### Web Worker Setup
430
+
431
+ STT uses Web Workers automatically. Ensure your build tool supports workers:
432
+
433
+ ```ts
434
+ // Vite
435
+ import SpeechWorker from 'use-voice-control/speech/worker?worker';
436
+
437
+ // Webpack/Next.js
438
+ const SpeechWorker = require('use-voice-control/speech/worker.js');
439
+ ```
440
+
441
+ ---
442
+
443
+ ## πŸ” Privacy & Security
444
+
445
+ - **Client-side STT**: Moonshine.js runs entirely in the browserβ€”no audio leaves your device
446
+ - **Optional Server TTS**: Choose Kokoro (server-side) or Deepgram (with API key)
447
+ - **No Tracking**: No analytics or usage telemetry
448
+ - **HTTPS Required**: Microphone access requires secure context
449
+
450
+ ---
451
+
452
+ ## πŸ› Troubleshooting
453
+
454
+ ### Microphone Access Denied
455
+ - Ensure HTTPS or localhost
456
+ - Check browser permissions (Settings β†’ Privacy β†’ Microphone)
457
+ - Grant permission when prompted
458
+
459
+ ### Silent or Garbled Audio
460
+ - Adjust `volume` in `useSpeechSynthesis` options
461
+ - Try a different voice or provider
462
+ - Check speaker/headphone connection
463
+
464
+ ### STT Not Recognizing Speech
465
+ - Verify microphone is working (test in browser console)
466
+ - Speak clearly and at normal volume
467
+ - Check language setting matches spoken language
468
+
469
+ ---
470
+
471
+ ## πŸ“¦ Exports
472
+
473
+ ```ts
474
+ // Hooks
475
+ export { useSpeechRecognition } from 'use-voice-control/hooks';
476
+ export { useSpeechSynthesis } from 'use-voice-control/hooks';
477
+ export { useVoiceControl } from 'use-voice-control/hooks';
478
+
479
+ // Components
480
+ export { AudioRecorder } from 'use-voice-control/components';
481
+ export { VoiceSelector } from 'use-voice-control/components';
482
+ export { AudioPlayer } from 'use-voice-control/components';
483
+
484
+ // Core API
485
+ export { generateSpeech } from 'use-voice-control/speech';
486
+ export type { TTSProvider, TTSOptions, KokoroVoice, DeepgramSpeaker } from 'use-voice-control/speech';
487
+ ```
488
+
489
+ ---
490
+
491
+ ## πŸ“„ License
492
+
493
+ [rights.institute/PROSPER](https://rights.institute/PROSPER)
494
+
495
+ ## 🀝 Contributing
496
+
497
+ We welcome contributions! Please review [CONTRIBUTING.md](../../CONTRIBUTING.md) and open a PR.
498
+
499
+ - **Issues**: [GitHub Issues](https://github.com/OpenSourceAGI/qwksearch-research-agent/issues)
500
+ - **Discussions**: [GitHub Discussions](https://github.com/OpenSourceAGI/qwksearch-research-agent/discussions)
501
+ - **Discord**: [Join Community](https://discord.gg/SJdBqBz3tV)
502
+
503
+ ---
504
+
505
+ ## πŸ”— Related Packages
506
+
507
+ - [qwksearch-api-client](../qwksearch-api-client) - API client for search and content extraction
508
+ - [agent-toolkit](../agent-toolkit) - Multi-provider LLM agent toolkit
509
+ - [research-agent-ui](../research-agent-ui) - React UI components for research agents
510
+
511
+ ---
512
+
513
+ ## πŸ“– Documentation
514
+
515
+ - [Voice Recognition with Moonshine.js](https://github.com/openvino/openvino.js/tree/master/src/pages/docs/learn/code_examples/speech_recognition)
516
+ - [Kokoro TTS Documentation](https://huggingface.co/hexgrad/Kokoro-82M)
517
+ - [Deepgram API Reference](https://developers.deepgram.com/reference/text-to-speech)
518
+ - [Web Audio API Guide](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API)
519
+
520
+ ---
521
+
522
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome" /> Please star this repo for updates! ⭐
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "use-voice-control",
3
+ "version": "0.1.0",
4
+ "description": "React voice control with speech transcription, vocalization, and interruption (STT/TTS/VAD) support.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/OpenSourceAGI/qwksearch-research-agent.git",
8
+ "directory": "packages/use-voice-control"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ },
18
+ "./hooks": {
19
+ "types": "./dist/hooks/index.d.ts",
20
+ "import": "./dist/hooks/index.js"
21
+ },
22
+ "./components": {
23
+ "types": "./dist/components/index.d.ts",
24
+ "import": "./dist/components/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "src"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsc && vite build",
33
+ "dev": "vite build --watch",
34
+ "type-check": "tsc --noEmit"
35
+ },
36
+ "dependencies": {
37
+ "lucide-react": "^0.344.0",
38
+ "@moonshine-ai/moonshine-js": "^0.1.29",
39
+ "react": "^18.0.0",
40
+ "react-dom": "^18.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/react": "^18.0.0",
44
+ "@types/react-dom": "^18.0.0",
45
+ "typescript": "^5.3.3",
46
+ "vite": "^5.0.0",
47
+ "vite-plugin-dts": "^5.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "react": "^18.0.0",
51
+ "react-dom": "^18.0.0"
52
+ },
53
+ "license": "rights.institute/PROSPER"
54
+ }
package/readme.md ADDED
@@ -0,0 +1 @@
1
+ ![logo](https://i.imgur.com/ypVzqbg.png)