@voicethere/agent 0.7.5 → 0.7.6
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/package.json +1 -1
- package/templates/crash.ts +12 -2
- package/templates/echo-smoke.ts +14 -4
package/package.json
CHANGED
package/templates/crash.ts
CHANGED
|
@@ -6,11 +6,19 @@
|
|
|
6
6
|
* - `{ type: "crash_exit" }` → process.exit(1)
|
|
7
7
|
* - `{ type: "ping", id }` → `{ type: "pong", id }`
|
|
8
8
|
* - `onUserSpeechFinal` text starting with "crash" → throw
|
|
9
|
-
* - other finals → speak(`echo
|
|
9
|
+
* - other finals → speak(`echo. ${text}`)
|
|
10
10
|
* - onSessionStart → speak("ready") after 1s (voice ready waiter)
|
|
11
11
|
*/
|
|
12
12
|
import { defineAgent, sendToClient, speak } from "@voicethere/agent";
|
|
13
13
|
|
|
14
|
+
/** TTS echo prefix with a sentence boundary so Piper does not glue words. */
|
|
15
|
+
export function formatEchoSpeak(text: string): string {
|
|
16
|
+
const trimmed = text.trim();
|
|
17
|
+
if (!trimmed) return "";
|
|
18
|
+
// Never glue `echo:` onto the next word; Piper skips "echo colon" on `echo:One`.
|
|
19
|
+
return `echo. ${trimmed}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export const CRASH_AGENT_MESSAGE =
|
|
15
23
|
"e2e crash-agent: intentional handler failure";
|
|
16
24
|
|
|
@@ -44,7 +52,9 @@ defineAgent({
|
|
|
44
52
|
if (/^crash\b/i.test(trimmed)) {
|
|
45
53
|
throw new Error(CRASH_AGENT_MESSAGE);
|
|
46
54
|
}
|
|
47
|
-
|
|
55
|
+
const echoText = formatEchoSpeak(trimmed);
|
|
56
|
+
if (!echoText) return;
|
|
57
|
+
speak(sessionId, echoText);
|
|
48
58
|
},
|
|
49
59
|
|
|
50
60
|
onDataChannelMessage(ctx) {
|
package/templates/echo-smoke.ts
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { defineAgent, parseChatText, speak } from "@voicethere/agent";
|
|
7
7
|
|
|
8
|
+
/** TTS echo prefix with a sentence boundary so Piper does not glue words. */
|
|
9
|
+
export function formatEchoSpeak(text: string): string {
|
|
10
|
+
const trimmed = text.trim();
|
|
11
|
+
if (!trimmed) return "";
|
|
12
|
+
// Never glue `echo:` onto the next word; Piper skips "echo colon" on `echo:One`.
|
|
13
|
+
return `echo. ${trimmed}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
defineAgent({
|
|
9
17
|
onSessionStart({ sessionId }) {
|
|
10
18
|
setTimeout(() => {
|
|
@@ -13,15 +21,17 @@ defineAgent({
|
|
|
13
21
|
},
|
|
14
22
|
|
|
15
23
|
onUserSpeechFinal({ sessionId, text }) {
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
18
|
-
speak(sessionId,
|
|
24
|
+
const echoText = formatEchoSpeak(text);
|
|
25
|
+
if (!echoText) return;
|
|
26
|
+
speak(sessionId, echoText);
|
|
19
27
|
},
|
|
20
28
|
|
|
21
29
|
onDataChannelMessage(ctx) {
|
|
22
30
|
const text = parseChatText(ctx.message);
|
|
23
31
|
if (!text?.trim()) return;
|
|
24
32
|
if (text.trim().toLowerCase() === "ping") return;
|
|
25
|
-
|
|
33
|
+
const echoText = formatEchoSpeak(text);
|
|
34
|
+
if (!echoText) return;
|
|
35
|
+
speak(ctx.sessionId, echoText);
|
|
26
36
|
},
|
|
27
37
|
});
|