@guideai/react-native 0.9.0 → 0.10.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/README.md +6 -3
- package/dist/{GuideAIChat-BFu10t6D.cjs → GuideAIChat-BtbkPIvE.cjs} +285 -26
- package/dist/GuideAIChat-BtbkPIvE.cjs.map +1 -0
- package/dist/{GuideAIChat-Ba6n1ePs.js → GuideAIChat-CKW6dgl_.js} +286 -27
- package/dist/GuideAIChat-CKW6dgl_.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +58 -6
- package/dist/index.mjs +2 -2
- package/dist/ui.cjs +2 -2
- package/dist/ui.d.ts +13 -3
- package/dist/ui.mjs +3 -3
- package/dist/{useConversations-C-OmzdeA.js → useConversations-BljCr0Od.js} +1067 -43
- package/dist/useConversations-BljCr0Od.js.map +1 -0
- package/dist/{useConversations-Chn_GKOz.cjs → useConversations-UiwD_WVF.cjs} +1067 -43
- package/dist/useConversations-UiwD_WVF.cjs.map +1 -0
- package/dist/voice.cjs +61 -23
- package/dist/voice.cjs.map +1 -1
- package/dist/voice.d.ts +13 -3
- package/dist/voice.mjs +62 -24
- package/dist/voice.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/GuideAIChat-BFu10t6D.cjs.map +0 -1
- package/dist/GuideAIChat-BQQ8lUKs.js +0 -2795
- package/dist/GuideAIChat-BQQ8lUKs.js.map +0 -1
- package/dist/GuideAIChat-Ba6n1ePs.js.map +0 -1
- package/dist/GuideAIChat-CNmEo5bZ.cjs +0 -2794
- package/dist/GuideAIChat-CNmEo5bZ.cjs.map +0 -1
- package/dist/GuideAIChat-CxyWFl_o.cjs +0 -2493
- package/dist/GuideAIChat-CxyWFl_o.cjs.map +0 -1
- package/dist/GuideAIChat-DOC4zx-a.js +0 -2494
- package/dist/GuideAIChat-DOC4zx-a.js.map +0 -1
- package/dist/GuideAIChat-SU0CVNby.js +0 -2795
- package/dist/GuideAIChat-SU0CVNby.js.map +0 -1
- package/dist/GuideAIChat-W8KQ4Y6i.cjs +0 -2794
- package/dist/GuideAIChat-W8KQ4Y6i.cjs.map +0 -1
- package/dist/useConversations-B_7km_uH.js +0 -4243
- package/dist/useConversations-B_7km_uH.js.map +0 -1
- package/dist/useConversations-C-OmzdeA.js.map +0 -1
- package/dist/useConversations-CJEaVqch.cjs +0 -4290
- package/dist/useConversations-CJEaVqch.cjs.map +0 -1
- package/dist/useConversations-CTbQBTz-.cjs +0 -4242
- package/dist/useConversations-CTbQBTz-.cjs.map +0 -1
- package/dist/useConversations-Chn_GKOz.cjs.map +0 -1
- package/dist/useConversations-Ckyqbxqi.cjs +0 -4299
- package/dist/useConversations-Ckyqbxqi.cjs.map +0 -1
- package/dist/useConversations-DzhYCIiY.js +0 -4300
- package/dist/useConversations-DzhYCIiY.js.map +0 -1
- package/dist/useConversations-SbhtYN_R.js +0 -4291
- package/dist/useConversations-SbhtYN_R.js.map +0 -1
package/dist/voice.cjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const expoAudio = require("expo-audio");
|
|
5
|
-
const useConversations = require("./useConversations-
|
|
5
|
+
const useConversations = require("./useConversations-UiwD_WVF.cjs");
|
|
6
6
|
const expoFileSystem = require("expo-file-system");
|
|
7
7
|
const jsxRuntime = require("react/jsx-runtime");
|
|
8
|
-
const GuideAIChat = require("./GuideAIChat-
|
|
8
|
+
const GuideAIChat = require("./GuideAIChat-BtbkPIvE.cjs");
|
|
9
9
|
const CATALOG = {
|
|
10
10
|
en: {
|
|
11
11
|
label: "English",
|
|
12
12
|
transcriptionLanguages: ["en"],
|
|
13
|
-
transcriptionPrompt: "
|
|
13
|
+
transcriptionPrompt: "A website visitor speaking English with the site's assistant.",
|
|
14
14
|
speechInstructions: "Speak in English only."
|
|
15
15
|
},
|
|
16
16
|
// Nigerian Pidgin has no recognizer or voice of its own at our providers.
|
|
@@ -20,33 +20,33 @@ const CATALOG = {
|
|
|
20
20
|
pcm: {
|
|
21
21
|
label: "Nigerian Pidgin",
|
|
22
22
|
transcriptionLanguages: ["en"],
|
|
23
|
-
transcriptionPrompt: "
|
|
23
|
+
transcriptionPrompt: "A website visitor speaking Nigerian Pidgin English (Naija) with the site's assistant. Common words: wetin, abeg, dey, una, oya, wahala, sabi, abi, sef, don, na, dem, pikin, how far, no wahala, I no fit, make I, wey.",
|
|
24
24
|
speechInstructions: "Speak in Nigerian Pidgin English with a warm Nigerian accent."
|
|
25
25
|
},
|
|
26
26
|
fr: {
|
|
27
27
|
label: "French",
|
|
28
28
|
transcriptionLanguages: ["fr"],
|
|
29
|
-
transcriptionPrompt: "
|
|
29
|
+
transcriptionPrompt: "A website visitor speaking French with the site's assistant."
|
|
30
30
|
},
|
|
31
31
|
pt: {
|
|
32
32
|
label: "Portuguese",
|
|
33
33
|
transcriptionLanguages: ["pt"],
|
|
34
|
-
transcriptionPrompt: "
|
|
34
|
+
transcriptionPrompt: "A website visitor speaking Portuguese with the site's assistant."
|
|
35
35
|
},
|
|
36
36
|
es: {
|
|
37
37
|
label: "Spanish",
|
|
38
38
|
transcriptionLanguages: ["es"],
|
|
39
|
-
transcriptionPrompt: "
|
|
39
|
+
transcriptionPrompt: "A website visitor speaking Spanish with the site's assistant."
|
|
40
40
|
},
|
|
41
41
|
ar: {
|
|
42
42
|
label: "Arabic",
|
|
43
43
|
transcriptionLanguages: ["ar"],
|
|
44
|
-
transcriptionPrompt: "
|
|
44
|
+
transcriptionPrompt: "A website visitor speaking Arabic with the site's assistant."
|
|
45
45
|
},
|
|
46
46
|
"zh-cn": {
|
|
47
47
|
label: "Chinese (Mandarin)",
|
|
48
48
|
transcriptionLanguages: ["zh-cn"],
|
|
49
|
-
transcriptionPrompt: "
|
|
49
|
+
transcriptionPrompt: "A website visitor speaking Mandarin Chinese with the site's assistant."
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
function normalizeVoiceLanguageCode(code) {
|
|
@@ -63,7 +63,7 @@ function resolveVoiceLanguage(code) {
|
|
|
63
63
|
code: canonicalCode(normalized),
|
|
64
64
|
label: displayLanguageName(normalized),
|
|
65
65
|
transcriptionLanguages: [primary],
|
|
66
|
-
transcriptionPrompt: `
|
|
66
|
+
transcriptionPrompt: `A website visitor speaking ${displayLanguageName(normalized)} with the site's assistant.`
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
function isUnexpectedTranscriptScript(text, language) {
|
|
@@ -1396,6 +1396,11 @@ function isEchoOf(heard, spoken) {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
return inOrder / last >= 0.5;
|
|
1398
1398
|
}
|
|
1399
|
+
function isPromptEcho(heard, language) {
|
|
1400
|
+
const prompt = language == null ? void 0 : language.transcriptionPrompt;
|
|
1401
|
+
if (!prompt || normalizeUtterance(heard).length < 3) return false;
|
|
1402
|
+
return isEchoOf(heard, prompt);
|
|
1403
|
+
}
|
|
1399
1404
|
function createFenceFilter() {
|
|
1400
1405
|
let carry = "";
|
|
1401
1406
|
let inFence = false;
|
|
@@ -1802,7 +1807,7 @@ class PipelineVoiceAgent {
|
|
|
1802
1807
|
if (!this.greeting) this.player.cue();
|
|
1803
1808
|
}
|
|
1804
1809
|
async handleEvent(event) {
|
|
1805
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1810
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1806
1811
|
if (SESSION_UPDATED_EVENTS.has(event.type) || SESSION_CREATED_EVENTS.has(event.type) && !this.awaitingSessionUpdate) {
|
|
1807
1812
|
this.markReady();
|
|
1808
1813
|
return;
|
|
@@ -1865,7 +1870,9 @@ class PipelineVoiceAgent {
|
|
|
1865
1870
|
this.fillerDucked = false;
|
|
1866
1871
|
this.player.duck(1);
|
|
1867
1872
|
}
|
|
1868
|
-
|
|
1873
|
+
const promptEcho = !!text && isPromptEcho(text, this.options.language);
|
|
1874
|
+
if (promptEcho) this.telemetry.record("prompt_echo_ignored", 1, (_f = this.options.language) == null ? void 0 : _f.code);
|
|
1875
|
+
if (text && (promptEcho || this.isOwnEcho(text))) {
|
|
1869
1876
|
if (this.pendingInterruption) {
|
|
1870
1877
|
this.clearPendingInterruption();
|
|
1871
1878
|
this.player.duck(1);
|
|
@@ -1877,7 +1884,7 @@ class PipelineVoiceAgent {
|
|
|
1877
1884
|
return;
|
|
1878
1885
|
}
|
|
1879
1886
|
if (this.pendingInterruption) {
|
|
1880
|
-
const answersQuestion2 = !!text && !!((
|
|
1887
|
+
const answersQuestion2 = !!text && !!((_h = (_g = this.options.host).hasPendingConfirmation) == null ? void 0 : _h.call(_g)) && isConfirmationAnswer(text);
|
|
1881
1888
|
if (!text || isBackchannel(text) && !answersQuestion2) {
|
|
1882
1889
|
this.clearPendingInterruption();
|
|
1883
1890
|
this.player.duck(1);
|
|
@@ -1887,11 +1894,11 @@ class PipelineVoiceAgent {
|
|
|
1887
1894
|
}
|
|
1888
1895
|
this.confirmInterruption();
|
|
1889
1896
|
}
|
|
1890
|
-
const answersQuestion = this.lastAnswerAsked || !!((
|
|
1897
|
+
const answersQuestion = this.lastAnswerAsked || !!((_j = (_i = this.options.host).hasPendingConfirmation) == null ? void 0 : _j.call(_i));
|
|
1891
1898
|
if (!text || isFillerOnly(text, answersQuestion)) {
|
|
1892
1899
|
if (text) this.telemetry.record("filler_ignored", 1);
|
|
1893
1900
|
this.currentTurnId = null;
|
|
1894
|
-
if ((
|
|
1901
|
+
if ((_k = this.held) == null ? void 0 : _k.sendIfNothingFollows) {
|
|
1895
1902
|
const held = this.held;
|
|
1896
1903
|
this.clearHeld();
|
|
1897
1904
|
await this.commitTurn(held.text, held.turnId);
|
|
@@ -1906,7 +1913,7 @@ class PipelineVoiceAgent {
|
|
|
1906
1913
|
await this.takeTurn(text, null, answersQuestion);
|
|
1907
1914
|
return;
|
|
1908
1915
|
}
|
|
1909
|
-
const turnId = (
|
|
1916
|
+
const turnId = (_m = (_l = this.held) == null ? void 0 : _l.turnId) != null ? _m : this.currentTurnId;
|
|
1910
1917
|
const said = this.held ? `${this.held.text} ${text}` : text;
|
|
1911
1918
|
this.clearHeld();
|
|
1912
1919
|
this.currentTurnId = null;
|
|
@@ -1914,8 +1921,8 @@ class PipelineVoiceAgent {
|
|
|
1914
1921
|
return;
|
|
1915
1922
|
}
|
|
1916
1923
|
case "error": {
|
|
1917
|
-
const message = ((
|
|
1918
|
-
throw ((
|
|
1924
|
+
const message = ((_n = event.error) == null ? void 0 : _n.message) || "Realtime transcription failed.";
|
|
1925
|
+
throw ((_o = event.error) == null ? void 0 : _o.type) === "provider" ? new VoiceProviderError(message) : new Error(message);
|
|
1919
1926
|
}
|
|
1920
1927
|
default:
|
|
1921
1928
|
return;
|
|
@@ -2386,6 +2393,7 @@ class SonioxSttTransport {
|
|
|
2386
2393
|
this.muted = false;
|
|
2387
2394
|
this.finalText = "";
|
|
2388
2395
|
this.utteranceId = null;
|
|
2396
|
+
this.finishWaiter = null;
|
|
2389
2397
|
this.eventListeners = /* @__PURE__ */ new Set();
|
|
2390
2398
|
this.stateListeners = /* @__PURE__ */ new Set();
|
|
2391
2399
|
}
|
|
@@ -2441,13 +2449,36 @@ class SonioxSttTransport {
|
|
|
2441
2449
|
this.reconnectAttempts += 1;
|
|
2442
2450
|
await this.openSocket("reconnecting");
|
|
2443
2451
|
}
|
|
2452
|
+
/**
|
|
2453
|
+
* Stop sending audio and wait for the words still provisional to be made
|
|
2454
|
+
* final: Soniox answers `finalize` with them, then `<fin>`. Dictation calls
|
|
2455
|
+
* this when the visitor taps to send, so their last words are not cut off.
|
|
2456
|
+
* Resolves at `<fin>` or after `timeoutMs`; the caller then disconnects.
|
|
2457
|
+
*/
|
|
2458
|
+
finish(timeoutMs = 2e3) {
|
|
2459
|
+
this.muted = true;
|
|
2460
|
+
const socket = this.socket;
|
|
2461
|
+
if (!socket || !this.socketReady || socket.readyState !== WebSocket.OPEN) return Promise.resolve();
|
|
2462
|
+
return new Promise((resolve) => {
|
|
2463
|
+
const done = () => {
|
|
2464
|
+
clearTimeout(timer);
|
|
2465
|
+
if (this.finishWaiter === done) this.finishWaiter = null;
|
|
2466
|
+
resolve();
|
|
2467
|
+
};
|
|
2468
|
+
const timer = setTimeout(done, timeoutMs);
|
|
2469
|
+
this.finishWaiter = done;
|
|
2470
|
+
socket.send(JSON.stringify({ type: "finalize" }));
|
|
2471
|
+
this.lastSentAt = Date.now();
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2444
2474
|
disconnect() {
|
|
2445
|
-
var _a;
|
|
2475
|
+
var _a, _b;
|
|
2446
2476
|
this.userClosed = true;
|
|
2477
|
+
(_a = this.finishWaiter) == null ? void 0 : _a.call(this);
|
|
2447
2478
|
this.setState("closing");
|
|
2448
2479
|
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
|
2449
2480
|
this.reconnectTimer = null;
|
|
2450
|
-
(
|
|
2481
|
+
(_b = this.connectionAbort) == null ? void 0 : _b.abort();
|
|
2451
2482
|
this.connectionAbort = null;
|
|
2452
2483
|
this.cleanupAll();
|
|
2453
2484
|
this.setState("closed");
|
|
@@ -2572,7 +2603,9 @@ class SonioxSttTransport {
|
|
|
2572
2603
|
audio_format: "pcm_s16le",
|
|
2573
2604
|
sample_rate: INPUT_SAMPLE_RATE,
|
|
2574
2605
|
num_channels: 1,
|
|
2575
|
-
|
|
2606
|
+
// A hint alone only biases: on a phone mic, English speech came back
|
|
2607
|
+
// as other languages. Strict holds the visitor's chosen language.
|
|
2608
|
+
...this.languageHints.length ? { language_hints: this.languageHints, language_hints_strict: true } : {},
|
|
2576
2609
|
...terms.length || this.contextText ? { context: { ...terms.length ? { terms } : {}, ...this.contextText ? { text: this.contextText } : {} } } : {},
|
|
2577
2610
|
enable_endpoint_detection: true,
|
|
2578
2611
|
endpoint_latency_adjustment_level: (_c = endpoint.latencyAdjustmentLevel) != null ? _c : 2,
|
|
@@ -2581,7 +2614,7 @@ class SonioxSttTransport {
|
|
|
2581
2614
|
};
|
|
2582
2615
|
}
|
|
2583
2616
|
handleMessage(data) {
|
|
2584
|
-
var _a, _b, _c;
|
|
2617
|
+
var _a, _b, _c, _d;
|
|
2585
2618
|
let message;
|
|
2586
2619
|
try {
|
|
2587
2620
|
message = JSON.parse(typeof data === "string" ? data : new TextDecoder().decode(data));
|
|
@@ -2599,13 +2632,17 @@ class SonioxSttTransport {
|
|
|
2599
2632
|
}
|
|
2600
2633
|
let provisional = "";
|
|
2601
2634
|
let endOfTurn = false;
|
|
2635
|
+
let finalized = false;
|
|
2602
2636
|
for (const token of (_a = message.tokens) != null ? _a : []) {
|
|
2603
2637
|
const text = (_b = token.text) != null ? _b : "";
|
|
2604
2638
|
if (text === "<end>") {
|
|
2605
2639
|
endOfTurn = true;
|
|
2606
2640
|
continue;
|
|
2607
2641
|
}
|
|
2608
|
-
if (text === "<fin>")
|
|
2642
|
+
if (text === "<fin>") {
|
|
2643
|
+
finalized = true;
|
|
2644
|
+
continue;
|
|
2645
|
+
}
|
|
2609
2646
|
if (token.is_final) this.finalText += text;
|
|
2610
2647
|
else provisional += text;
|
|
2611
2648
|
}
|
|
@@ -2632,6 +2669,7 @@ class SonioxSttTransport {
|
|
|
2632
2669
|
}
|
|
2633
2670
|
this.resetUtterance();
|
|
2634
2671
|
}
|
|
2672
|
+
if (finalized) (_d = this.finishWaiter) == null ? void 0 : _d.call(this);
|
|
2635
2673
|
}
|
|
2636
2674
|
resetUtterance() {
|
|
2637
2675
|
this.finalText = "";
|