@drawdream/livespeech 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DrawDream Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # LiveSpeech SDK for TypeScript
2
+
3
+ [![npm](https://img.shields.io/npm/v/@drawdream/livespeech.svg)](https://www.npmjs.com/package/@drawdream/livespeech)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ A TypeScript/JavaScript SDK for real-time speech-to-speech AI conversations.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @drawdream/livespeech
12
+ # or
13
+ yarn add @drawdream/livespeech
14
+ # or
15
+ pnpm add @drawdream/livespeech
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```typescript
21
+ import { LiveSpeechClient, Region } from '@drawdream/livespeech';
22
+
23
+ const client = new LiveSpeechClient({
24
+ region: 'ap-northeast-2', // or Region.AP_NORTHEAST_2
25
+ apiKey: 'your-api-key',
26
+ });
27
+
28
+ // Handle events
29
+ client.setTranscriptHandler((text, isFinal) => {
30
+ console.log(`Transcript: ${text} (final: ${isFinal})`);
31
+ });
32
+
33
+ client.setResponseHandler((text, isFinal) => {
34
+ console.log(`AI Response: ${text}`);
35
+ });
36
+
37
+ client.setAudioHandler((audioData) => {
38
+ // Play audio through speakers
39
+ });
40
+
41
+ // Connect and start session
42
+ await client.connect();
43
+ await client.startSession({
44
+ prePrompt: 'You are a helpful assistant.',
45
+ });
46
+
47
+ // Send audio
48
+ client.sendAudio(audioBuffer);
49
+ ```
50
+
51
+ ## API Reference
52
+
53
+ ### Regions
54
+
55
+ The SDK provides built-in region support, so you don't need to remember endpoint URLs:
56
+
57
+ | Region | Identifier | Location |
58
+ |--------|------------|----------|
59
+ | `ap-northeast-2` | `Region.AP_NORTHEAST_2` | Asia Pacific (Seoul) |
60
+ | `us-west-2` | `Region.US_WEST_2` | US West (Oregon) - Coming soon |
61
+
62
+ ### LiveSpeechClient
63
+
64
+ #### Constructor Options
65
+
66
+ | Option | Type | Default | Description |
67
+ |--------|------|---------|-------------|
68
+ | `region` | `string` | **required** | Region identifier |
69
+ | `apiKey` | `string` | **required** | API key for authentication |
70
+ | `connectionTimeout` | `number` | `30000` | Connection timeout in ms |
71
+ | `autoReconnect` | `boolean` | `true` | Auto-reconnect on disconnect |
72
+ | `maxReconnectAttempts` | `number` | `5` | Max reconnection attempts |
73
+ | `reconnectDelay` | `number` | `1000` | Base reconnection delay in ms |
74
+ | `debug` | `boolean` | `false` | Enable debug logging |
75
+
76
+ #### Methods
77
+
78
+ | Method | Description |
79
+ |--------|-------------|
80
+ | `connect()` | Connect to the server |
81
+ | `disconnect()` | Disconnect from the server |
82
+ | `startSession(config)` | Start a conversation session |
83
+ | `endSession()` | End the current session |
84
+ | `sendAudio(data, options?)` | Send audio data to be transcribed |
85
+
86
+ #### Event Handlers
87
+
88
+ ```typescript
89
+ // Simple handlers
90
+ client.setTranscriptHandler((text, isFinal) => {});
91
+ client.setResponseHandler((text, isFinal) => {});
92
+ client.setAudioHandler((audioData) => {});
93
+ client.setErrorHandler((error) => {});
94
+
95
+ // Full event API
96
+ client.on('connected', (event) => {});
97
+ client.on('disconnected', (event) => {});
98
+ client.on('sessionStarted', (event) => {});
99
+ client.on('sessionEnded', (event) => {});
100
+ client.on('transcript', (event) => {});
101
+ client.on('response', (event) => {});
102
+ client.on('audio', (event) => {});
103
+ client.on('error', (event) => {});
104
+ client.on('reconnecting', (event) => {});
105
+ ```
106
+
107
+ ### SessionConfig
108
+
109
+ | Option | Type | Default | Description |
110
+ |--------|------|---------|-------------|
111
+ | `prePrompt` | `string` | **required** | System prompt for the AI |
112
+ | `voiceId` | `string` | `'en-US-Standard-A'` | TTS voice ID |
113
+ | `languageCode` | `string` | `'en-US'` | Language for STT |
114
+ | `inputFormat` | `AudioFormat` | `'pcm16'` | Input audio format |
115
+ | `outputFormat` | `AudioFormat` | `'pcm16'` | Output audio format |
116
+ | `sampleRate` | `number` | `16000` | Sample rate in Hz |
117
+ | `metadata` | `Record<string,string>` | `{}` | Custom metadata |
118
+
119
+ ## Audio Utilities
120
+
121
+ The SDK includes audio encoding/decoding utilities:
122
+
123
+ ```typescript
124
+ import {
125
+ encodeAudioToBase64,
126
+ decodeBase64ToAudio,
127
+ float32ToInt16,
128
+ int16ToFloat32,
129
+ wrapPcmInWav,
130
+ } from '@drawdream/livespeech';
131
+
132
+ // Convert Float32 audio samples to PCM16
133
+ const pcmData = float32ToInt16(float32Samples);
134
+
135
+ // Create WAV file from PCM data
136
+ const wavFile = wrapPcmInWav(pcmData, { sampleRate: 16000 });
137
+ ```
138
+
139
+ ## Browser Usage
140
+
141
+ The SDK works in both Node.js and browser environments:
142
+
143
+ ```html
144
+ <script type="module">
145
+ import { LiveSpeechClient } from '@drawdream/livespeech';
146
+
147
+ // Use the Web Audio API to capture microphone
148
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
149
+ const audioContext = new AudioContext({ sampleRate: 16000 });
150
+ // ... process audio and send to client
151
+ </script>
152
+ ```
153
+
154
+ ## License
155
+
156
+ MIT