@lokutor/sdk 1.1.15 → 1.1.19
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/dist/index.d.mts +152 -5
- package/dist/index.d.ts +152 -5
- package/dist/index.js +439 -45
- package/dist/index.mjs +472 -51
- package/package.json +11 -16
- package/src/audio-utils.ts +253 -0
- package/src/browser-audio.ts +395 -0
- package/src/client.ts +886 -0
- package/src/index.ts +25 -0
- package/src/node-audio.ts +115 -0
- package/src/types.ts +270 -0
- package/dist/chunk-SNNPJP5R.mjs +0 -42
- package/dist/node-audio.d.mts +0 -25
- package/dist/node-audio.d.ts +0 -25
- package/dist/node-audio.js +0 -132
- package/dist/node-audio.mjs +0 -88
package/dist/node-audio.mjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AUDIO_CONFIG
|
|
3
|
-
} from "./chunk-SNNPJP5R.mjs";
|
|
4
|
-
|
|
5
|
-
// src/node-audio.ts
|
|
6
|
-
var NodeAudioManager = class {
|
|
7
|
-
speaker = null;
|
|
8
|
-
recorder = null;
|
|
9
|
-
recordingStream = null;
|
|
10
|
-
isMuted = false;
|
|
11
|
-
isListening = false;
|
|
12
|
-
constructor() {
|
|
13
|
-
}
|
|
14
|
-
async init() {
|
|
15
|
-
try {
|
|
16
|
-
const Speaker = await import("speaker").catch(() => null);
|
|
17
|
-
if (!Speaker) {
|
|
18
|
-
console.warn('\u26A0\uFE0F Package "speaker" is missing. Hardware output will be disabled.');
|
|
19
|
-
console.warn("\u{1F449} Run: npm install speaker");
|
|
20
|
-
}
|
|
21
|
-
} catch (e) {
|
|
22
|
-
console.error("Error initializing Node audio:", e);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async startMicrophone(onAudioInput) {
|
|
26
|
-
if (this.isListening) return;
|
|
27
|
-
const recorder = await import("node-record-lpcm16").catch(() => null);
|
|
28
|
-
if (!recorder) {
|
|
29
|
-
throw new Error('Package "node-record-lpcm16" is missing. Microphone input failed.\n\u{1F449} Run: npm install node-record-lpcm16');
|
|
30
|
-
}
|
|
31
|
-
this.recorder = recorder;
|
|
32
|
-
this.recordingStream = recorder.record({
|
|
33
|
-
sampleRate: AUDIO_CONFIG.SAMPLE_RATE,
|
|
34
|
-
threshold: 0,
|
|
35
|
-
verbose: false,
|
|
36
|
-
recordProgram: "sox"
|
|
37
|
-
});
|
|
38
|
-
this.recordingStream.stream().on("data", (chunk) => {
|
|
39
|
-
if (!this.isMuted && onAudioInput) {
|
|
40
|
-
onAudioInput(new Uint8Array(chunk));
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
this.isListening = true;
|
|
44
|
-
}
|
|
45
|
-
stopMicrophone() {
|
|
46
|
-
if (this.recordingStream) {
|
|
47
|
-
this.recordingStream.stop();
|
|
48
|
-
this.recordingStream = null;
|
|
49
|
-
}
|
|
50
|
-
this.isListening = false;
|
|
51
|
-
}
|
|
52
|
-
async playAudio(pcm16Data) {
|
|
53
|
-
try {
|
|
54
|
-
if (!this.speaker) {
|
|
55
|
-
const Speaker = (await import("speaker")).default;
|
|
56
|
-
this.speaker = new Speaker({
|
|
57
|
-
channels: AUDIO_CONFIG.CHANNELS,
|
|
58
|
-
bitDepth: 16,
|
|
59
|
-
sampleRate: AUDIO_CONFIG.SPEAKER_SAMPLE_RATE
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
this.speaker.write(Buffer.from(pcm16Data));
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
stopPlayback() {
|
|
67
|
-
if (this.speaker) {
|
|
68
|
-
this.speaker.end();
|
|
69
|
-
this.speaker = null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
cleanup() {
|
|
73
|
-
this.stopMicrophone();
|
|
74
|
-
this.stopPlayback();
|
|
75
|
-
}
|
|
76
|
-
isMicMuted() {
|
|
77
|
-
return this.isMuted;
|
|
78
|
-
}
|
|
79
|
-
setMuted(muted) {
|
|
80
|
-
this.isMuted = muted;
|
|
81
|
-
}
|
|
82
|
-
getAmplitude() {
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
export {
|
|
87
|
-
NodeAudioManager
|
|
88
|
-
};
|