@oryksa/react-native 1.1.1 → 1.1.3
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/CHANGELOG.md +37 -24
- package/README.es.md +161 -0
- package/README.fr.md +161 -0
- package/README.md +62 -24
- package/README.pt.md +161 -0
- package/package.json +69 -61
- package/src/attach.js +133 -0
- package/src/chat.js +102 -21
- package/src/client.js +267 -233
- package/src/index.d.ts +86 -0
- package/src/index.js +12 -0
- package/src/link-card.js +74 -0
- package/src/links.js +115 -0
- package/src/voice-screen.js +15 -8
- package/src/voice.js +9 -2
package/src/index.js
CHANGED
|
@@ -10,6 +10,9 @@ const voice = require("./voice");
|
|
|
10
10
|
const voiceScreen = require("./voice-screen");
|
|
11
11
|
const vad = require("./vad");
|
|
12
12
|
const profanity = require("./profanity");
|
|
13
|
+
const links = require("./links");
|
|
14
|
+
const linkCard = require("./link-card");
|
|
15
|
+
const attach = require("./attach");
|
|
13
16
|
|
|
14
17
|
module.exports = {
|
|
15
18
|
OryksaClient: client.OryksaClient,
|
|
@@ -25,4 +28,13 @@ module.exports = {
|
|
|
25
28
|
Vad: vad.Vad,
|
|
26
29
|
maskProfanity: profanity.mask,
|
|
27
30
|
loadProfanity: profanity.load,
|
|
31
|
+
OryksaLinkCard: linkCard.OryksaLinkCard,
|
|
32
|
+
linksIn: links.linksIn,
|
|
33
|
+
withoutLinks: links.withoutLinks,
|
|
34
|
+
openLink: links.openLink,
|
|
35
|
+
createDefaultPicker: attach.createDefaultPicker,
|
|
36
|
+
photoAttachment: attach.photoAttachment,
|
|
37
|
+
documentAttachment: attach.documentAttachment,
|
|
38
|
+
MAX_PHOTO_BYTES: attach.MAX_PHOTO_BYTES,
|
|
39
|
+
MAX_FILE_BYTES: attach.MAX_FILE_BYTES,
|
|
28
40
|
};
|
package/src/link-card.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @oryksa/react-native - the card under a reply for each link: the picture and title of the page
|
|
3
|
+
* and an Open button. License: MIT
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const React = require("react");
|
|
8
|
+
const RN = require("react-native");
|
|
9
|
+
const { cardTexts, openLink, linksIn } = require("./links");
|
|
10
|
+
|
|
11
|
+
const h = React.createElement;
|
|
12
|
+
const { View, Text, Image, Pressable, StyleSheet } = RN;
|
|
13
|
+
|
|
14
|
+
const COLORS = { accent: "#5B47E0", ink: "#1F2937", muted: "#6B7280", background: "#FFFFFF", line: "#E5E7EB" };
|
|
15
|
+
|
|
16
|
+
/** A link drawn with views (no icon font): two rounded rings, crossed. */
|
|
17
|
+
function LinkGlyph({ color }) {
|
|
18
|
+
const ring = (left) => h(View, { style: { position: "absolute", top: 7, left, width: 12, height: 8, borderRadius: 4, borderWidth: 2, borderColor: color } });
|
|
19
|
+
return h(View, { style: { width: 22, height: 22, transform: [{ rotate: "-45deg" }] } }, ring(1), ring(9));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The card for one link of the AI's reply. Props: url, client, openLabel ("Open", "Abrir"), onLink
|
|
24
|
+
* ((url) => boolean: true when your app opened it), onOpened (called when the card opens the link),
|
|
25
|
+
* theme ({ accent, ink, muted, background, line }), style.
|
|
26
|
+
* Only the pages of the business's own site get a title and a picture; other links show the address.
|
|
27
|
+
*/
|
|
28
|
+
function OryksaLinkCard(props) {
|
|
29
|
+
const { url, client, openLabel = "Open", onLink, onOpened, theme, style } = props;
|
|
30
|
+
const th = Object.assign({}, COLORS, theme || {});
|
|
31
|
+
const [preview, setPreview] = React.useState(null);
|
|
32
|
+
const [broken, setBroken] = React.useState(false);
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
let alive = true;
|
|
35
|
+
setPreview(null); setBroken(false);
|
|
36
|
+
if (client && client.linkPreview) client.linkPreview(url).then((p) => { if (alive && p) setPreview(p); }).catch(() => {});
|
|
37
|
+
return () => { alive = false; };
|
|
38
|
+
}, [url, client]);
|
|
39
|
+
const { title, sub } = cardTexts(url, preview);
|
|
40
|
+
const img = (preview && preview.image) || "";
|
|
41
|
+
const open = () => { if (onOpened) onOpened(); openLink(url, onLink); };
|
|
42
|
+
return h(Pressable, {
|
|
43
|
+
onPress: open, accessibilityRole: "button", accessibilityLabel: openLabel + ": " + title,
|
|
44
|
+
style: [s.card, { backgroundColor: th.background, borderColor: th.line }, style],
|
|
45
|
+
},
|
|
46
|
+
h(View, { style: [s.pic, { backgroundColor: th.line }] },
|
|
47
|
+
img && !broken
|
|
48
|
+
? h(Image, { source: { uri: img }, style: s.img, resizeMode: "cover", onError: () => setBroken(true) })
|
|
49
|
+
: h(LinkGlyph, { color: th.muted })),
|
|
50
|
+
h(View, { style: s.texts },
|
|
51
|
+
h(Text, { style: [s.title, { color: th.ink }], numberOfLines: 2 }, title),
|
|
52
|
+
sub ? h(Text, { style: [s.sub, { color: th.muted }], numberOfLines: 1 }, sub) : null),
|
|
53
|
+
h(Pressable, { onPress: open, accessibilityRole: "button", accessibilityLabel: openLabel, style: [s.open, { backgroundColor: th.accent }] },
|
|
54
|
+
h(Text, { style: s.openTxt }, openLabel)));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The cards for the links of text (at most 3), one under the other. */
|
|
58
|
+
function OryksaLinkCards(props) {
|
|
59
|
+
const { text, style } = props;
|
|
60
|
+
return linksIn(text).map((u) => h(OryksaLinkCard, Object.assign({}, props, { key: u, url: u, style })));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const s = StyleSheet.create({
|
|
64
|
+
card: { flexDirection: "row", alignItems: "center", padding: 8, borderRadius: 14, borderWidth: 1 },
|
|
65
|
+
pic: { width: 52, height: 52, borderRadius: 10, overflow: "hidden", alignItems: "center", justifyContent: "center" },
|
|
66
|
+
img: { width: 52, height: 52 },
|
|
67
|
+
texts: { flex: 1, marginLeft: 10, marginRight: 8 },
|
|
68
|
+
title: { fontSize: 13.5, lineHeight: 17.5, fontWeight: "700" },
|
|
69
|
+
sub: { fontSize: 11.5, marginTop: 1 },
|
|
70
|
+
open: { minHeight: 36, paddingHorizontal: 14, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
71
|
+
openTxt: { color: "#fff", fontSize: 13, fontWeight: "700" },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
module.exports = { OryksaLinkCard, OryksaLinkCards };
|
package/src/links.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @oryksa/react-native - the links of the AI's replies: found in the text, taken out of what she
|
|
3
|
+
* says on the voice screen, and opened by your app (onLink) or by the system. License: MIT
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const URL_RE = /https?:\/\/[^\s<>"'\)\]]+/gi;
|
|
8
|
+
const MAIL_RE = /[\w.+-]+@[\w-]+(\.[\w-]+)+/g;
|
|
9
|
+
|
|
10
|
+
/** Every match of re in s (a fresh copy of the regular expression, so no state is shared). */
|
|
11
|
+
function allMatches(re, s) {
|
|
12
|
+
const r = new RegExp(re.source, re.flags);
|
|
13
|
+
const out = [];
|
|
14
|
+
let m;
|
|
15
|
+
while ((m = r.exec(s)) !== null) {
|
|
16
|
+
out.push(m);
|
|
17
|
+
if (m[0] === "") r.lastIndex++;
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The address without the punctuation that ends the sentence (.,;:!?…). */
|
|
23
|
+
function trimEnd(u) { return u.replace(/[.,;:!?…]+$/, ""); }
|
|
24
|
+
|
|
25
|
+
/** The distinct web links of text, in order (at most max). */
|
|
26
|
+
function linksIn(text, max) {
|
|
27
|
+
const limit = max === undefined ? 3 : max;
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const m of allMatches(URL_RE, String(text || ""))) {
|
|
30
|
+
const u = trimEnd(m[0]);
|
|
31
|
+
if (!out.includes(u)) out.push(u);
|
|
32
|
+
if (out.length >= limit) break;
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** text without its web links (for the voice screen: the link is on the button). */
|
|
38
|
+
function withoutLinks(text) {
|
|
39
|
+
return String(text || "")
|
|
40
|
+
.replace(URL_RE, "")
|
|
41
|
+
.replace(/[ \t]+\n/g, "\n")
|
|
42
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
43
|
+
.replace(/[ \t]{2,}/g, " ")
|
|
44
|
+
.replace(/\s+([.,;!?])/g, "$1")
|
|
45
|
+
.replace(/:\s*$/gm, "")
|
|
46
|
+
.trim();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The parts of s that are links: web addresses and e-mails (as mailto:), in order. */
|
|
50
|
+
function linkHits(s) {
|
|
51
|
+
const hits = [];
|
|
52
|
+
for (const m of allMatches(URL_RE, s)) {
|
|
53
|
+
const u = trimEnd(m[0]);
|
|
54
|
+
hits.push({ start: m.index, end: m.index + u.length, url: u });
|
|
55
|
+
}
|
|
56
|
+
for (const m of allMatches(MAIL_RE, s)) {
|
|
57
|
+
const start = m.index;
|
|
58
|
+
const end = m.index + m[0].length;
|
|
59
|
+
if (hits.some((x) => start < x.end && end > x.start)) continue;
|
|
60
|
+
hits.push({ start, end, url: "mailto:" + m[0] });
|
|
61
|
+
}
|
|
62
|
+
return hits.sort((a, b) => a.start - b.start);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A message as parts to draw: { text, bold, url } (url only on the links, web and e-mail).
|
|
67
|
+
* **bold** parts stay bold.
|
|
68
|
+
*/
|
|
69
|
+
function richParts(text) {
|
|
70
|
+
const out = [];
|
|
71
|
+
const links = (s, bold) => {
|
|
72
|
+
let at = 0;
|
|
73
|
+
for (const x of linkHits(s)) {
|
|
74
|
+
if (x.start < at) continue;
|
|
75
|
+
if (x.start > at) out.push({ text: s.slice(at, x.start), bold, url: null });
|
|
76
|
+
out.push({ text: s.slice(x.start, x.end), bold, url: x.url });
|
|
77
|
+
at = x.end;
|
|
78
|
+
}
|
|
79
|
+
if (at < s.length) out.push({ text: s.slice(at), bold, url: null });
|
|
80
|
+
};
|
|
81
|
+
const t = String(text || "");
|
|
82
|
+
const parts = t.split("**");
|
|
83
|
+
if (parts.length < 3) { links(t, false); return out; }
|
|
84
|
+
parts.forEach((p, i) => { if (p) links(p, i % 2 === 1); });
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The host of url without www. (what the card shows when it has no title). */
|
|
89
|
+
function hostOf(url) {
|
|
90
|
+
const m = /^[a-z][a-z0-9+.-]*:\/\/([^/?#:]+)/i.exec(String(url || ""));
|
|
91
|
+
return m ? m[1].replace(/^www\./i, "") : "";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Title and sub line (price · site, or site, or host) of the card for url. */
|
|
95
|
+
function cardTexts(url, p) {
|
|
96
|
+
const host = hostOf(url);
|
|
97
|
+
const title = p && p.title ? p.title : host;
|
|
98
|
+
const sub = p && p.price ? p.price + " · " + (p.site || "") : (p && p.site ? p.site : host);
|
|
99
|
+
return { title, sub };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Opens a link: your handler first (return true when your app opened it), then the system
|
|
104
|
+
* (React Native Linking: the browser or the app that owns the address).
|
|
105
|
+
*/
|
|
106
|
+
function openLink(url, handler) {
|
|
107
|
+
if (handler && handler(url) === true) return;
|
|
108
|
+
try {
|
|
109
|
+
const { Linking } = require("react-native");
|
|
110
|
+
const p = Linking.openURL(url);
|
|
111
|
+
if (p && p.catch) p.catch(() => {});
|
|
112
|
+
} catch (_) { /* no way to open it */ }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = { linksIn, withoutLinks, linkHits, richParts, hostOf, cardTexts, openLink };
|
package/src/voice-screen.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
const React = require("react");
|
|
8
8
|
const RN = require("react-native");
|
|
9
9
|
const { OryksaVoiceController } = require("./voice");
|
|
10
|
+
const { withoutLinks } = require("./links");
|
|
11
|
+
const { OryksaLinkCards } = require("./link-card");
|
|
10
12
|
|
|
11
13
|
const h = React.createElement;
|
|
12
14
|
const { View, Text, Image, Pressable, Modal, SafeAreaView, StyleSheet, Animated, Easing } = RN;
|
|
@@ -17,35 +19,37 @@ const VX = {
|
|
|
17
19
|
micError: "Microphone unavailable", micErrorSub: "Allow microphone access, or close other apps using it.",
|
|
18
20
|
noisy: "Too much background noise", noisySub: "I cannot tell your voice from the noise. Move somewhere quieter, or type to me.",
|
|
19
21
|
notUnderstood: "I could not understand", notUnderstoodSub: "Say it again, please.",
|
|
20
|
-
tapToSend: "Tap the picture to send what you said.", mute: "Mute", unmute: "Unmute", close: "Close" },
|
|
22
|
+
tapToSend: "Tap the picture to send what you said.", mute: "Mute", unmute: "Unmute", close: "Close", open: "Open" },
|
|
21
23
|
pt: { listening: "Estou a ouvir", listeningSub: "Fala comigo. Podes interromper-me quando quiseres.", hearing: "Continua, estou a ouvir.",
|
|
22
24
|
thinking: "Um momento...", muted: "Em pausa", mutedSub: "Toca no microfone para voltar a falar.",
|
|
23
25
|
micError: "Microfone indisponível", micErrorSub: "Permite o acesso ao microfone, ou fecha outras apps que o estejam a usar.",
|
|
24
26
|
noisy: "Demasiado barulho", noisySub: "Não consigo distinguir a tua voz do barulho. Vai para um sítio mais calmo, ou escreve-me.",
|
|
25
27
|
notUnderstood: "Não percebi", notUnderstoodSub: "Diz outra vez, por favor.",
|
|
26
|
-
tapToSend: "Toca na imagem para enviar o que disseste.", mute: "Silenciar", unmute: "Ativar som", close: "Fechar" },
|
|
28
|
+
tapToSend: "Toca na imagem para enviar o que disseste.", mute: "Silenciar", unmute: "Ativar som", close: "Fechar", open: "Abrir" },
|
|
27
29
|
br: { listening: "Estou ouvindo", listeningSub: "Fale comigo. Você pode me interromper quando quiser.", hearing: "Continue, estou ouvindo.",
|
|
28
30
|
thinking: "Um momento...", muted: "Em pausa", mutedSub: "Toque no microfone para voltar a falar.",
|
|
29
31
|
micError: "Microfone indisponível", micErrorSub: "Permita o acesso ao microfone, ou feche outros apps que estejam usando.",
|
|
30
32
|
noisy: "Barulho demais", noisySub: "Não consigo separar sua voz do barulho. Vá para um lugar mais calmo, ou digite para mim.",
|
|
31
33
|
notUnderstood: "Não entendi", notUnderstoodSub: "Fale de novo, por favor.",
|
|
32
|
-
tapToSend: "Toque na imagem para enviar o que você disse.", mute: "Silenciar", unmute: "Ativar som", close: "Fechar" },
|
|
34
|
+
tapToSend: "Toque na imagem para enviar o que você disse.", mute: "Silenciar", unmute: "Ativar som", close: "Fechar", open: "Abrir" },
|
|
33
35
|
es: { listening: "Te escucho", listeningSub: "Háblame. Puedes interrumpirme cuando quieras.", hearing: "Sigue, te escucho.",
|
|
34
36
|
thinking: "Un momento...", muted: "En pausa", mutedSub: "Toca el micrófono para volver a hablar.",
|
|
35
37
|
micError: "Micrófono no disponible", micErrorSub: "Permite el acceso al micrófono, o cierra otras apps que lo estén usando.",
|
|
36
38
|
noisy: "Demasiado ruido", noisySub: "No distingo tu voz del ruido. Ve a un sitio más tranquilo, o escríbeme.",
|
|
37
39
|
notUnderstood: "No te entendí", notUnderstoodSub: "Dilo otra vez, por favor.",
|
|
38
|
-
tapToSend: "Toca la imagen para enviar lo que dijiste.", mute: "Silenciar", unmute: "Activar sonido", close: "Cerrar" },
|
|
40
|
+
tapToSend: "Toca la imagen para enviar lo que dijiste.", mute: "Silenciar", unmute: "Activar sonido", close: "Cerrar", open: "Abrir" },
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
const FALLBACK_AVATAR = "https://oryksa.com/assets/img/avatar_official_oryksa.png";
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* Full-screen voice conversation. Props: client, agent ({ name, avatar, business }), visible, onClose,
|
|
45
|
-
* lang, theme, appContext (() => ({ screen, title, items })), onUserText, onReply, audio (adapter)
|
|
47
|
+
* lang, theme, appContext (() => ({ screen, title, items })), onUserText, onReply, audio (adapter),
|
|
48
|
+
* onLink ((url) => boolean: true when your app opened the link; the links of her answer show as cards
|
|
49
|
+
* with an Open button, and tapping one closes the voice screen).
|
|
46
50
|
*/
|
|
47
51
|
function OryksaVoiceScreen(props) {
|
|
48
|
-
const { client, agent, visible, onClose, lang = "en", theme, appContext, onUserText, onReply, audio } = props;
|
|
52
|
+
const { client, agent, visible, onClose, lang = "en", theme, appContext, onUserText, onReply, audio, onLink } = props;
|
|
49
53
|
const th = Object.assign({ accent: "#5B57E0", ink: "#161B3D", soft: "#EEEBFB", background: "#FFFFFF", muted: "#6B7280" }, theme || {});
|
|
50
54
|
const t = VX[lang] || VX.en;
|
|
51
55
|
const [phase, setPhase] = React.useState("starting");
|
|
@@ -69,7 +73,8 @@ function OryksaVoiceScreen(props) {
|
|
|
69
73
|
const pick = {
|
|
70
74
|
starting: [t.listening, t.listeningSub], listening: [t.listening, t.listeningSub], hearing: [t.listening, t.hearing],
|
|
71
75
|
// never the words the person said on screen: only "listening" in the interface language; her answer shows as text
|
|
72
|
-
|
|
76
|
+
// what she says out loud, without the addresses: the links are the cards below (owner 2026-11-21)
|
|
77
|
+
thinking: [t.listening, t.thinking], speaking: [(agent && agent.name) || "ORYKSA", withoutLinks((ctl && (ctl.lastSpoken || ctl.lastReply)) || "")],
|
|
73
78
|
muted: [t.muted, t.mutedSub], micError: [t.micError, t.micErrorSub], noisy: [t.noisy, t.noisySub],
|
|
74
79
|
notUnderstood: [t.notUnderstood, t.notUnderstoodSub],
|
|
75
80
|
}[phase] || [t.listening, t.listeningSub];
|
|
@@ -94,7 +99,8 @@ function OryksaVoiceScreen(props) {
|
|
|
94
99
|
ring(236, 0.06), ring(184, 0.09), ring(136, 0.13),
|
|
95
100
|
h(Image, { source: { uri: photo }, style: st.photo })),
|
|
96
101
|
h(Text, { style: [st.title, { color: th.ink }] }, pick[0]),
|
|
97
|
-
h(Text, { style: [st.sub, { color: th.muted }] }, pick[1]),
|
|
102
|
+
h(Text, { style: [st.sub, { color: th.muted }], numberOfLines: 7 }, pick[1]),
|
|
103
|
+
h(OryksaLinkCards, { text: (ctl && ctl.lastReply) || "", client, openLabel: t.open, onLink, onOpened: close, theme: th, style: st.card }),
|
|
98
104
|
phase === "hearing" ? h(Text, { style: st.tap }, t.tapToSend) : null,
|
|
99
105
|
h(View, { style: st.row },
|
|
100
106
|
btn(h(MicIcon, { color: th.muted, crossed: phase === "muted" }), phase === "muted" ? t.unmute : t.mute, false, () => ctlRef.current && ctlRef.current.toggleMute(), th),
|
|
@@ -132,6 +138,7 @@ const st = StyleSheet.create({
|
|
|
132
138
|
photo: { width: 124, height: 124, borderRadius: 62 },
|
|
133
139
|
title: { marginTop: 14, fontSize: 22, fontWeight: "700", textAlign: "center" },
|
|
134
140
|
sub: { marginTop: 8, fontSize: 13.5, lineHeight: 20, textAlign: "center" },
|
|
141
|
+
card: { alignSelf: "stretch", marginTop: 10 },
|
|
135
142
|
tap: { marginTop: 10, fontSize: 11.5, color: "#AAB0CC" },
|
|
136
143
|
row: { flexDirection: "row", gap: 46, marginTop: 20 },
|
|
137
144
|
cbtn: { width: 58, height: 58, borderRadius: 29, borderWidth: 1.5, alignItems: "center", justifyContent: "center" },
|
package/src/voice.js
CHANGED
|
@@ -153,6 +153,8 @@ class OryksaVoiceController {
|
|
|
153
153
|
this.vad = new Vad(SR);
|
|
154
154
|
this.phase = "starting";
|
|
155
155
|
this.lastReply = "";
|
|
156
|
+
/** What she said out loud last (the short spoken version of lastReply). */
|
|
157
|
+
this.lastSpoken = "";
|
|
156
158
|
this.lastHeard = "";
|
|
157
159
|
this._pcm = [];
|
|
158
160
|
this._pcmBytes = 0;
|
|
@@ -281,14 +283,19 @@ class OryksaVoiceController {
|
|
|
281
283
|
if (this._closed || my !== this._turn) return;
|
|
282
284
|
const reply = String((r && r.reply) || "").trim();
|
|
283
285
|
if (!reply) { this._busy = false; this._set("notUnderstood"); return; }
|
|
286
|
+
const speech = String((r && r.speech) || "").trim();
|
|
284
287
|
this.lastReply = reply;
|
|
288
|
+
this.lastSpoken = speech || reply;
|
|
285
289
|
if (this.onReply) this.onReply(reply);
|
|
286
|
-
const speech = String((r && r.speech) || "").trim();
|
|
287
290
|
await this._speak(speech || reply, my);
|
|
288
291
|
}
|
|
289
292
|
|
|
290
293
|
/** Speaks text with the AI's voice (for example a greeting). If the voice fails she stays silent. */
|
|
291
|
-
say(text) {
|
|
294
|
+
say(text) {
|
|
295
|
+
this.lastReply = text;
|
|
296
|
+
this.lastSpoken = text;
|
|
297
|
+
return this._speak(text, ++this._turn);
|
|
298
|
+
}
|
|
292
299
|
|
|
293
300
|
async _speak(text, my) {
|
|
294
301
|
this._before = []; this._beforeBytes = 0;
|