@graineai/inapp-react-native 0.39.0 → 0.40.1
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/INTEGRATION.md +113 -113
- package/README.md +13 -5
- package/dist/client.d.ts +6 -0
- package/dist/client.js +52 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.js +11 -0
- package/dist/react-native/appearance.d.ts +2 -0
- package/dist/react-native/appearance.js +2 -1
- package/dist/react-native/fab.js +14 -9
- package/dist/react-native/index.d.ts +1 -0
- package/dist/react-native/index.js +2 -1
- package/dist/react-native/voice-bar.js +31 -11
- package/dist/react-native/voice-launcher.d.ts +5 -0
- package/dist/react-native/voice-launcher.js +44 -3
- package/dist/theme.d.ts +12 -0
- package/dist/theme.js +743 -2
- package/dist/voice.d.ts +2 -0
- package/dist/voice.js +6 -2
- package/package.json +1 -1
package/dist/voice.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GraineInAppClient } from "./client.js";
|
|
2
2
|
export declare const CAPTURE_SAMPLE_RATE = 16000;
|
|
3
|
+
export declare const AGENT_PCM_RATE = 24000;
|
|
3
4
|
export declare const MIN_PLAYOUT_BUFFER_SECONDS = 0.15;
|
|
4
5
|
export interface AudioAdapter {
|
|
5
6
|
startCapture(onChunk: (base64: string) => void): Promise<void> | void;
|
|
@@ -23,6 +24,7 @@ export declare class VoiceSession {
|
|
|
23
24
|
private echo;
|
|
24
25
|
private agentAudible;
|
|
25
26
|
private lastAudioAt;
|
|
27
|
+
private audibleUntil;
|
|
26
28
|
constructor(client: GraineInAppClient, adapter: AudioAdapter, options?: VoiceSessionOptions);
|
|
27
29
|
get active(): boolean;
|
|
28
30
|
start(): Promise<void>;
|
package/dist/voice.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EchoGuard, base64ToBytes, decodeAgentAudio, decodePcm16 } from "./audio.js";
|
|
2
2
|
export const CAPTURE_SAMPLE_RATE = 16000;
|
|
3
|
+
export const AGENT_PCM_RATE = 24000;
|
|
3
4
|
export const MIN_PLAYOUT_BUFFER_SECONDS = 0.15;
|
|
4
5
|
export function base64ToPcm16(b64) {
|
|
5
6
|
return decodePcm16(base64ToBytes(b64));
|
|
@@ -15,6 +16,7 @@ export class VoiceSession {
|
|
|
15
16
|
this.echo = new EchoGuard();
|
|
16
17
|
this.agentAudible = false;
|
|
17
18
|
this.lastAudioAt = 0;
|
|
19
|
+
this.audibleUntil = 0;
|
|
18
20
|
}
|
|
19
21
|
get active() {
|
|
20
22
|
return this.capturing;
|
|
@@ -25,13 +27,14 @@ export class VoiceSession {
|
|
|
25
27
|
this.capturing = true;
|
|
26
28
|
this.offs = [
|
|
27
29
|
this.client.on("audio", ({ data, format, sampleRate, }) => {
|
|
28
|
-
const decoded = decodeAgentAudio(base64ToBytes(data), { format, sampleRate }, this.format);
|
|
30
|
+
const decoded = decodeAgentAudio(base64ToBytes(data), { format, sampleRate }, this.format, AGENT_PCM_RATE);
|
|
29
31
|
if (!decoded)
|
|
30
32
|
return;
|
|
31
33
|
if (decoded.latch)
|
|
32
34
|
this.format = decoded.latch;
|
|
33
35
|
this.lastAudioAt = Date.now();
|
|
34
36
|
this.adapter.play(decoded.pcm16, decoded.sampleRate);
|
|
37
|
+
this.audibleUntil = Date.now() + (this.adapter.bufferedSeconds?.() ?? 0) * 1000;
|
|
35
38
|
}),
|
|
36
39
|
this.client.on("clear", () => {
|
|
37
40
|
this.adapter.clear();
|
|
@@ -59,7 +62,7 @@ export class VoiceSession {
|
|
|
59
62
|
});
|
|
60
63
|
}
|
|
61
64
|
agentIsAudible() {
|
|
62
|
-
if (Date.now() - this.lastAudioAt > 1500)
|
|
65
|
+
if (Date.now() - Math.max(this.lastAudioAt, this.audibleUntil) > 1500)
|
|
63
66
|
return false;
|
|
64
67
|
const buffered = this.adapter.bufferedSeconds?.();
|
|
65
68
|
return buffered !== undefined ? buffered > 0.02 || this.agentAudible : this.agentAudible;
|
|
@@ -71,6 +74,7 @@ export class VoiceSession {
|
|
|
71
74
|
this.format = null;
|
|
72
75
|
this.agentAudible = false;
|
|
73
76
|
this.lastAudioAt = 0;
|
|
77
|
+
this.audibleUntil = 0;
|
|
74
78
|
this.echo.reset();
|
|
75
79
|
this.offs.forEach((off) => off());
|
|
76
80
|
this.offs = [];
|
package/package.json
CHANGED