@volley/recognition-client-sdk 0.1.200
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 +168 -0
- package/dist/browser-CDQ_TzeH.d.ts +1039 -0
- package/dist/index.d.ts +461 -0
- package/dist/index.js +2332 -0
- package/dist/index.js.map +1 -0
- package/dist/recog-client-sdk.browser.d.ts +2 -0
- package/dist/recog-client-sdk.browser.js +1843 -0
- package/dist/recog-client-sdk.browser.js.map +1 -0
- package/package.json +73 -0
- package/src/browser.ts +24 -0
- package/src/config-builder.ts +213 -0
- package/src/factory.ts +43 -0
- package/src/index.ts +86 -0
- package/src/recognition-client.spec.ts +551 -0
- package/src/recognition-client.ts +595 -0
- package/src/recognition-client.types.ts +260 -0
- package/src/simplified-vgf-recognition-client.spec.ts +671 -0
- package/src/simplified-vgf-recognition-client.ts +339 -0
- package/src/utils/audio-ring-buffer.ts +170 -0
- package/src/utils/message-handler.ts +131 -0
- package/src/utils/url-builder.ts +70 -0
- package/src/vgf-recognition-mapper.ts +225 -0
- package/src/vgf-recognition-state.ts +89 -0
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# @volley/recognition-client-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for real-time speech recognition via WebSocket.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @volley/recognition-client-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createClientWithBuilder } from '@volley/recognition-client-sdk';
|
|
15
|
+
|
|
16
|
+
// Create client with builder pattern
|
|
17
|
+
const client = createClientWithBuilder(builder =>
|
|
18
|
+
builder
|
|
19
|
+
.url('ws://localhost:3101/ws/v1/recognize')
|
|
20
|
+
.provider('deepgram')
|
|
21
|
+
.model('nova-2')
|
|
22
|
+
.onTranscript(result => {
|
|
23
|
+
console.log('Final:', result.finalTranscript);
|
|
24
|
+
console.log('Interim:', result.pendingTranscript);
|
|
25
|
+
})
|
|
26
|
+
.onError(error => console.error(error))
|
|
27
|
+
.build()
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Stream audio
|
|
31
|
+
await client.connect();
|
|
32
|
+
client.sendAudio(pcm16AudioChunk); // Call repeatedly with audio chunks
|
|
33
|
+
await client.stopRecording(); // Wait for final transcript
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
### Basic Setup
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
builder
|
|
42
|
+
.url('ws://localhost:3101/ws/v1/recognize')
|
|
43
|
+
.provider('deepgram') // deepgram, google, assemblyai
|
|
44
|
+
.model('nova-2') // Provider-specific model
|
|
45
|
+
.language('en') // Language code
|
|
46
|
+
.interimResults(true) // Enable partial transcripts
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Event Handlers
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
builder
|
|
53
|
+
.onTranscript(result => {}) // Handle transcription results
|
|
54
|
+
.onError(error => {}) // Handle errors
|
|
55
|
+
.onConnected(() => {}) // Connection established
|
|
56
|
+
.onDisconnected((code) => {}) // Connection closed
|
|
57
|
+
.onMetadata(meta => {}) // Timing information
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Optional Parameters
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
builder
|
|
64
|
+
.gameContext({ // Context for better recognition
|
|
65
|
+
gameId: 'session-123',
|
|
66
|
+
prompt: 'Expected responses: yes, no, maybe'
|
|
67
|
+
})
|
|
68
|
+
.userId('user-123') // User identification
|
|
69
|
+
.platform('web') // Platform identifier
|
|
70
|
+
.logger((level, msg, data) => {}) // Custom logging
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## API Reference
|
|
74
|
+
|
|
75
|
+
### Client Methods
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
await client.connect(); // Establish connection
|
|
79
|
+
client.sendAudio(chunk); // Send PCM16 audio
|
|
80
|
+
await client.stopRecording(); // End and get final transcript
|
|
81
|
+
client.getAudioUtteranceId(); // Get session UUID
|
|
82
|
+
client.getState(); // Get current state
|
|
83
|
+
client.isConnected(); // Check connection status
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### TranscriptionResult
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
{
|
|
90
|
+
finalTranscript?: string; // Confirmed text
|
|
91
|
+
pendingTranscript?: string; // Yet to confirm text (can change by ASR vendors)
|
|
92
|
+
is_finished?: boolean; // Transcription complete (last one)
|
|
93
|
+
voiceStart?: number; // Voice activity start (ms)
|
|
94
|
+
voiceDuration?: number; // Voice duration (ms)
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Providers
|
|
99
|
+
|
|
100
|
+
### Deepgram
|
|
101
|
+
```typescript
|
|
102
|
+
builder.provider('deepgram').model('nova-2') // or 'nova-2-general'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Audio Format
|
|
107
|
+
|
|
108
|
+
The SDK expects PCM16 audio:
|
|
109
|
+
- Format: Linear PCM (16-bit signed integers)
|
|
110
|
+
- Sample Rate: 16kHz recommended
|
|
111
|
+
- Channels: Mono
|
|
112
|
+
Please reach out to AI team if ther are essential reasons that we need other formats.
|
|
113
|
+
|
|
114
|
+
## Error Handling
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
builder.onError(error => {
|
|
118
|
+
console.error(`Error ${error.code}: ${error.message}`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Check disconnection type
|
|
122
|
+
import { isNormalDisconnection } from '@volley/recognition-client-sdk';
|
|
123
|
+
|
|
124
|
+
builder.onDisconnected((code, reason) => {
|
|
125
|
+
if (!isNormalDisconnection(code)) {
|
|
126
|
+
console.error('Unexpected disconnect:', code);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Publishing
|
|
132
|
+
|
|
133
|
+
This package uses automated publishing via semantic-release with npm Trusted Publishers (OIDC).
|
|
134
|
+
|
|
135
|
+
### First-Time Setup (One-time)
|
|
136
|
+
|
|
137
|
+
After the first manual publish, configure npm Trusted Publishers:
|
|
138
|
+
|
|
139
|
+
1. Go to https://www.npmjs.com/package/@volley/recognition-client-sdk/access
|
|
140
|
+
2. Click "Add publisher" → Select "GitHub Actions"
|
|
141
|
+
3. Configure:
|
|
142
|
+
- **Organization**: `Volley-Inc`
|
|
143
|
+
- **Repository**: `recognition-service`
|
|
144
|
+
- **Workflow**: `sdk-release.yml`
|
|
145
|
+
- **Environment**: Leave empty (not required)
|
|
146
|
+
|
|
147
|
+
### How It Works
|
|
148
|
+
|
|
149
|
+
- **Automated releases**: Push to `dev` branch triggers semantic-release
|
|
150
|
+
- **Version bumping**: Based on conventional commits (feat/fix/BREAKING CHANGE)
|
|
151
|
+
- **No tokens needed**: Uses OIDC authentication with npm
|
|
152
|
+
- **Provenance**: Automatic supply chain attestation
|
|
153
|
+
- **Path filtering**: Only releases when SDK or libs change
|
|
154
|
+
|
|
155
|
+
### Manual Publishing (Not Recommended)
|
|
156
|
+
|
|
157
|
+
If needed for testing:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cd packages/client-sdk-ts
|
|
161
|
+
npm login --scope=@volley
|
|
162
|
+
pnpm build
|
|
163
|
+
npm publish --provenance --access public
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Proprietary
|