@jskit-ai/assistant-voice 0.1.44 → 0.2.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/examples/conversation/package.json +8 -8
- package/locales/en.json +182 -0
- package/package.json +6 -3
- package/src/client/ConversationDialog.vue +19 -9
- package/src/client/VoiceAvatar.vue +3 -1
- package/src/client/VoiceConversation.vue +26 -7
- package/src/client/VoiceConversationControls.vue +40 -18
- package/src/client/VoiceConversationHost.vue +23 -11
- package/src/client/VoiceConversationSettings.vue +4 -2
- package/src/client/VoiceSpeakingVoiceSelect.vue +5 -2
- package/src/client/i18n.js +42 -0
- package/src/client/voiceController.js +9 -7
- package/src/client/voiceConversation.js +60 -40
- package/src/client/voiceTransport.js +28 -26
- package/src/server/voiceDaemon.js +32 -16
- package/src/server/voiceProxy.js +22 -12
- package/src/shared/protocol.js +38 -17
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { mdiCog } from "@mdi/js";
|
|
3
3
|
import { useSlots } from "vue";
|
|
4
4
|
import VoiceSpeakingVoiceSelect from "./VoiceSpeakingVoiceSelect.vue";
|
|
5
|
+
import { useJskitText } from "./i18n.js";
|
|
5
6
|
|
|
6
7
|
const props = defineProps({
|
|
7
8
|
voice: { type: Object, default: null },
|
|
8
9
|
compact: Boolean
|
|
9
10
|
});
|
|
10
11
|
const emit = defineEmits(["error"]);
|
|
12
|
+
const { t } = useJskitText();
|
|
11
13
|
const slots = useSlots();
|
|
12
14
|
async function openSettings(open) {
|
|
13
15
|
if (!open || slots.default || !props.voice) return;
|
|
@@ -22,12 +24,12 @@ async function openSettings(open) {
|
|
|
22
24
|
<v-btn
|
|
23
25
|
v-bind="settingsButton" :icon="mdiCog" variant="text" :color="compact ? 'primary' : undefined"
|
|
24
26
|
:width="compact ? 40 : undefined" :min-width="compact ? 40 : 48" :min-height="compact ? 44 : 48" :disabled="!voice && !$slots.default"
|
|
25
|
-
aria-label="
|
|
27
|
+
:aria-label="t('jskit.assistant.voice.settings.title')" :title="t('jskit.assistant.voice.settings.title')"
|
|
26
28
|
>
|
|
27
29
|
<template v-if="compact" #default><span class="voice-settings__disc"><v-icon size="20" :icon="mdiCog" /></span></template>
|
|
28
30
|
</v-btn>
|
|
29
31
|
</template>
|
|
30
|
-
<v-card class="voice-settings__menu" role="region" aria-label="
|
|
32
|
+
<v-card class="voice-settings__menu" role="region" :aria-label="t('jskit.assistant.voice.settings.title')">
|
|
31
33
|
<v-card-text>
|
|
32
34
|
<slot :voice="voice">
|
|
33
35
|
<VoiceSpeakingVoiceSelect v-if="voice" :voice="voice" />
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
// The speech service's speaking-voice choice. Hosts that replace the settings
|
|
3
3
|
// menu content reuse this instead of copying the selector.
|
|
4
|
+
import { useJskitText } from "./i18n.js";
|
|
5
|
+
|
|
6
|
+
const { t } = useJskitText();
|
|
4
7
|
const props = defineProps({
|
|
5
8
|
voice: { type: Object, required: true }
|
|
6
9
|
});
|
|
@@ -15,7 +18,7 @@ function selectVoice(value) {
|
|
|
15
18
|
:model-value="voice.selectedVoice.value" @update:model-value="selectVoice"
|
|
16
19
|
:items="voice.availableVoices.value" item-title="label" item-value="id"
|
|
17
20
|
:disabled="voice.availableVoices.value.length < 2"
|
|
18
|
-
label="
|
|
19
|
-
hint="
|
|
21
|
+
:label="t('jskit.assistant.voice.settings.speakingVoice')" density="comfortable"
|
|
22
|
+
:hint="t('jskit.assistant.voice.settings.speakingVoiceHint')" persistent-hint
|
|
20
23
|
/>
|
|
21
24
|
</template>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { registerJskitMessages, useJskitText } from "@jskit-ai/kernel/client";
|
|
2
|
+
import { catalogMessage, formatMessage } from "@jskit-ai/kernel/shared/i18n";
|
|
3
|
+
import en from "../../locales/en.json" with { type: "json" };
|
|
4
|
+
|
|
5
|
+
registerJskitMessages(en);
|
|
6
|
+
|
|
7
|
+
const { errorMessage, t } = useJskitText();
|
|
8
|
+
|
|
9
|
+
// A failure made in the browser keeps its English message for callers and logs, and
|
|
10
|
+
// names its sentence so a screen can show it in the active language.
|
|
11
|
+
function voiceError(key, params = {}) {
|
|
12
|
+
return Object.assign(new Error(formatMessage(catalogMessage(en, key), params)), {
|
|
13
|
+
messageCode: key.slice("jskit.".length),
|
|
14
|
+
messageParams: params
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// An error event from the voice service, kept with its code and translation fields.
|
|
19
|
+
function voiceEventError(event, fallbackKey) {
|
|
20
|
+
if (!event?.message) return voiceError(fallbackKey);
|
|
21
|
+
const { code, params, messageCode, messageParams } = event;
|
|
22
|
+
return Object.assign(new Error(String(event.message)),
|
|
23
|
+
Object.fromEntries(Object.entries({ code, params, messageCode, messageParams }).filter(([, value]) => value !== undefined)));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// What a screen shows for a caught failure; a thrown string is shown as written.
|
|
27
|
+
function voiceErrorText(cause) {
|
|
28
|
+
return errorMessage(cause, typeof cause === "string" ? cause : "");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// What speech says in place of content it leaves on screen, in the active language.
|
|
32
|
+
function voiceSpeechWording() {
|
|
33
|
+
return {
|
|
34
|
+
code: t("jskit.assistant.voice.speech.codeOnScreen"),
|
|
35
|
+
sql: t("jskit.assistant.voice.speech.sqlOnScreen"),
|
|
36
|
+
details: t("jskit.assistant.voice.speech.detailsInChat"),
|
|
37
|
+
image: t("jskit.assistant.voice.speech.image"),
|
|
38
|
+
link: t("jskit.assistant.voice.speech.link")
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { useJskitText, voiceError, voiceErrorText, voiceEventError, voiceSpeechWording };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { effectScope, shallowReactive, watch } from "vue";
|
|
2
2
|
import { useVoiceConversation } from "./voiceConversation.js";
|
|
3
|
+
import { useJskitText, voiceError, voiceErrorText } from "./i18n.js";
|
|
3
4
|
|
|
4
5
|
/** One controller per application shell. Bindings retain their own conversation. */
|
|
5
6
|
export function createVoiceConversationController({ connectSpeech, createSession = useVoiceConversation } = {}) {
|
|
6
7
|
if (typeof connectSpeech !== "function") throw new TypeError("Voice requires an application speech connection.");
|
|
8
|
+
const { t } = useJskitText();
|
|
7
9
|
const state = shallowReactive({ binding: null, session: null, visible: false, nextTarget: null, busy: false, error: "" });
|
|
8
10
|
let scope;
|
|
9
11
|
let revision = 0;
|
|
@@ -30,7 +32,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
30
32
|
async function activate(binding, requestRevision) {
|
|
31
33
|
const socketUrl = await connectSpeech(binding);
|
|
32
34
|
if (disposed || requestRevision !== revision) return false;
|
|
33
|
-
if (!socketUrl) throw
|
|
35
|
+
if (!socketUrl) throw voiceError("jskit.assistant.voice.errors.speechNotConfigured");
|
|
34
36
|
await release();
|
|
35
37
|
if (disposed || requestRevision !== revision) return false;
|
|
36
38
|
const nextScope = effectScope(true);
|
|
@@ -44,7 +46,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
44
46
|
state.nextTarget = null;
|
|
45
47
|
nextScope.run(() => watch(() => binding.available, (available) => {
|
|
46
48
|
if (available !== false) return;
|
|
47
|
-
state.error = "
|
|
49
|
+
state.error = t("jskit.assistant.voice.errors.noLongerAvailable");
|
|
48
50
|
void end({ discard: true });
|
|
49
51
|
}, { immediate: true }));
|
|
50
52
|
return true;
|
|
@@ -59,7 +61,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
59
61
|
if (!conversation?.id || !conversation.state || typeof conversation.submitText !== "function") {
|
|
60
62
|
return Promise.reject(new TypeError("Voice requires a conversation identity, state and text submission."));
|
|
61
63
|
}
|
|
62
|
-
if (disposed) return Promise.reject(
|
|
64
|
+
if (disposed) return Promise.reject(voiceError("jskit.assistant.voice.errors.hostDisposed"));
|
|
63
65
|
const requestRevision = ++revision;
|
|
64
66
|
return serialize(async () => {
|
|
65
67
|
if (requestRevision !== revision || disposed) return false;
|
|
@@ -69,7 +71,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
69
71
|
state.nextTarget = null;
|
|
70
72
|
return true;
|
|
71
73
|
}
|
|
72
|
-
if (conversation.available === false) throw
|
|
74
|
+
if (conversation.available === false) throw voiceError("jskit.assistant.voice.errors.notAvailable");
|
|
73
75
|
if (state.session?.hasUnsentSpeech.value) {
|
|
74
76
|
state.nextTarget = conversation;
|
|
75
77
|
state.visible = true;
|
|
@@ -77,7 +79,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
77
79
|
}
|
|
78
80
|
state.busy = true;
|
|
79
81
|
try { return await activate(conversation, requestRevision); }
|
|
80
|
-
catch (error) { state.error = error
|
|
82
|
+
catch (error) { state.error = voiceErrorText(error); throw error; }
|
|
81
83
|
finally { state.busy = false; }
|
|
82
84
|
});
|
|
83
85
|
}
|
|
@@ -91,7 +93,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
91
93
|
return serialize(async () => {
|
|
92
94
|
state.busy = true;
|
|
93
95
|
try { return await activate(target, requestRevision); }
|
|
94
|
-
catch (error) { state.error = error
|
|
96
|
+
catch (error) { state.error = voiceErrorText(error); throw error; }
|
|
95
97
|
finally { state.busy = false; }
|
|
96
98
|
});
|
|
97
99
|
}
|
|
@@ -99,7 +101,7 @@ export function createVoiceConversationController({ connectSpeech, createSession
|
|
|
99
101
|
function end({ discard = false } = {}) {
|
|
100
102
|
if (!discard && state.session?.hasUnsentSpeech.value) {
|
|
101
103
|
state.visible = true;
|
|
102
|
-
state.error = "
|
|
104
|
+
state.error = t("jskit.assistant.voice.errors.finishBeforeEnding");
|
|
103
105
|
return Promise.resolve(false);
|
|
104
106
|
}
|
|
105
107
|
++revision;
|
|
@@ -2,10 +2,12 @@ import { computed, onScopeDispose, ref, watch } from "vue";
|
|
|
2
2
|
import { createVoiceTurnId, useVoiceTransport } from "./voiceTransport.js";
|
|
3
3
|
import { speechTextFromAssistant, takeStreamingSpeech, VOICE_MAX_SPEECH_TEXT_CHARACTERS } from "../shared/protocol.js";
|
|
4
4
|
import { createConversationNarrationTracker } from "./conversationNarration.js";
|
|
5
|
+
import { useJskitText, voiceErrorText, voiceSpeechWording } from "./i18n.js";
|
|
5
6
|
|
|
6
7
|
/** Created inside the controller's effect scope, independent of a mounted screen. */
|
|
7
8
|
export function useVoiceConversation(binding, { socketUrl, createTransport = useVoiceTransport } = {}) {
|
|
8
|
-
const
|
|
9
|
+
const { serverMessage, t } = useJskitText();
|
|
10
|
+
const targetLabel = computed(() => binding.label || t("jskit.assistant.voice.assistant"));
|
|
9
11
|
const readAloud = ref(binding.defaults?.readAloud === true);
|
|
10
12
|
const readAloudChangePending = computed(() => binding.readAloudChangePending === true);
|
|
11
13
|
const soundPreparing = ref(false);
|
|
@@ -43,29 +45,31 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
43
45
|
const capturing = computed(() => voice.captureState.value !== "idle");
|
|
44
46
|
const speechActive = computed(() => Boolean(voice.activeSpeechTurnId.value));
|
|
45
47
|
const callConnection = computed(() => {
|
|
46
|
-
if (voice.reconnecting.value) return "
|
|
47
|
-
if (error.value || voice.error.value) return "
|
|
48
|
-
if (starting.value) return "
|
|
49
|
-
if (live.value) return "
|
|
50
|
-
return "
|
|
48
|
+
if (voice.reconnecting.value) return t("jskit.assistant.voice.status.interrupted");
|
|
49
|
+
if (error.value || voice.error.value) return t("jskit.assistant.voice.status.needsAttention");
|
|
50
|
+
if (starting.value) return t("jskit.assistant.voice.status.starting");
|
|
51
|
+
if (live.value) return t("jskit.assistant.voice.status.active");
|
|
52
|
+
return t("jskit.assistant.voice.status.off");
|
|
51
53
|
});
|
|
52
54
|
const callStatus = computed(() => {
|
|
53
|
-
if (voice.reconnecting.value) return "
|
|
54
|
-
if (starting.value) return "
|
|
55
|
-
if (live.value && voice.captureState.value === "connecting") return "
|
|
56
|
-
if (live.value && voice.captureState.value === "opening") return "
|
|
57
|
-
if (error.value || voice.error.value) return "
|
|
55
|
+
if (voice.reconnecting.value) return t("jskit.assistant.voice.status.reconnecting");
|
|
56
|
+
if (starting.value) return t("jskit.assistant.voice.status.starting");
|
|
57
|
+
if (live.value && voice.captureState.value === "connecting") return t("jskit.assistant.voice.status.connecting");
|
|
58
|
+
if (live.value && voice.captureState.value === "opening") return t("jskit.assistant.voice.status.openingMicrophone");
|
|
59
|
+
if (error.value || voice.error.value) return t("jskit.assistant.voice.status.needsAttention");
|
|
58
60
|
if (!live.value) return "";
|
|
59
|
-
if (pushHolding.value && voice.listening.value) return "
|
|
60
|
-
if (voice.speaking.value) return
|
|
61
|
-
if (speechActive.value) return "
|
|
62
|
-
if (binding.state.status === "working") return "
|
|
63
|
-
if (sending.value) return "
|
|
64
|
-
if (pendingTranscript.value) return "
|
|
65
|
-
if (microphoneMuted.value) return "
|
|
66
|
-
if (voice.captureState.value === "transcribing") return "
|
|
67
|
-
if (voice.listening.value) return "
|
|
68
|
-
return callMode.value === "push-to-talk"
|
|
61
|
+
if (pushHolding.value && voice.listening.value) return t("jskit.assistant.voice.status.listeningToYou");
|
|
62
|
+
if (voice.speaking.value) return t("jskit.assistant.voice.status.targetSpeaking", { target: targetLabel.value });
|
|
63
|
+
if (speechActive.value) return t("jskit.assistant.voice.status.preparingSpeech");
|
|
64
|
+
if (binding.state.status === "working") return t("jskit.assistant.voice.status.thinking");
|
|
65
|
+
if (sending.value) return t("jskit.assistant.voice.status.sending");
|
|
66
|
+
if (pendingTranscript.value) return t("jskit.assistant.voice.status.review");
|
|
67
|
+
if (microphoneMuted.value) return t("jskit.assistant.voice.status.microphoneMuted");
|
|
68
|
+
if (voice.captureState.value === "transcribing") return t("jskit.assistant.voice.status.transcribing");
|
|
69
|
+
if (voice.listening.value) return t("jskit.assistant.voice.status.listeningToYou");
|
|
70
|
+
return callMode.value === "push-to-talk"
|
|
71
|
+
? t("jskit.assistant.voice.status.holdToSpeak")
|
|
72
|
+
: t("jskit.assistant.voice.status.preparingMicrophone");
|
|
69
73
|
});
|
|
70
74
|
const callModeBusy = computed(() => starting.value || changingCallMode.value || pushHolding.value || sending.value || Boolean(pendingTranscript.value)
|
|
71
75
|
|| capturing.value && Boolean(voice.partialTranscript.value.trim()) || capturing.value && !voice.listening.value);
|
|
@@ -79,8 +83,19 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
79
83
|
const callAudioLevel = computed(() => Math.max(0, Math.min(1, voice.speaking.value ? voice.mouthLevel.value
|
|
80
84
|
: voice.listening.value && !microphoneMuted.value ? voice.inputLevel.value : 0)));
|
|
81
85
|
const status = computed(() => {
|
|
82
|
-
const capture = {
|
|
83
|
-
|
|
86
|
+
const capture = {
|
|
87
|
+
connecting: "jskit.assistant.voice.status.connecting",
|
|
88
|
+
opening: "jskit.assistant.voice.status.openingMic",
|
|
89
|
+
listening: "jskit.assistant.voice.status.listening",
|
|
90
|
+
transcribing: "jskit.assistant.voice.status.transcribing"
|
|
91
|
+
}[voice.captureState.value];
|
|
92
|
+
return [
|
|
93
|
+
starting.value ? "jskit.assistant.voice.status.starting" : "",
|
|
94
|
+
voice.reconnecting.value ? "jskit.assistant.voice.status.reconnecting" : "",
|
|
95
|
+
live.value ? "jskit.assistant.voice.status.live" : "",
|
|
96
|
+
microphoneMuted.value ? "jskit.assistant.voice.status.microphoneMuted" : capture,
|
|
97
|
+
voice.speaking.value ? "jskit.assistant.voice.status.speaking" : speechActive.value ? "jskit.assistant.voice.status.preparingSpeech" : ""
|
|
98
|
+
].filter(Boolean).map(key => t(key)).join(" · ");
|
|
84
99
|
});
|
|
85
100
|
const heldTranscript = computed(() => pendingTranscript.value?.text ||
|
|
86
101
|
(["listening", "transcribing"].includes(voice.captureState.value) ? voice.partialTranscript.value : ""));
|
|
@@ -147,7 +162,9 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
147
162
|
if (!narrationEnabled() || !narration.working || !narration.thinkingSounds) return;
|
|
148
163
|
thinkingMurmurTimer = setTimeout(() => {
|
|
149
164
|
if (epoch !== narrationEpoch || !narrationEnabled() || !binding.narration?.working || !binding.narration.thinkingSounds) return;
|
|
150
|
-
if (!speechQueue.length && !draining && !speechActive.value && voice.state.value === "idle")
|
|
165
|
+
if (!speechQueue.length && !draining && !speechActive.value && voice.state.value === "idle") {
|
|
166
|
+
queueNarration("murmur", t("jskit.assistant.voice.narration.murmur"));
|
|
167
|
+
}
|
|
151
168
|
scheduleThinkingMurmur(epoch);
|
|
152
169
|
}, 20_000);
|
|
153
170
|
}
|
|
@@ -216,6 +233,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
216
233
|
async function drainSpeech() {
|
|
217
234
|
if (draining || disposed || !readAloud.value || speechSuppressed || soundPreparing.value || voice.playbackBlocked?.value) return;
|
|
218
235
|
draining = true;
|
|
236
|
+
const wording = voiceSpeechWording();
|
|
219
237
|
try {
|
|
220
238
|
while (speechQueue.length) {
|
|
221
239
|
const reply = speechQueue[0];
|
|
@@ -223,13 +241,13 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
223
241
|
if (reply.started && !speechActive.value) { speechQueue.shift(); continue; }
|
|
224
242
|
if (speechActive.value && !reply.started) return;
|
|
225
243
|
if (reply.started && !voice.canAppendSpeech.value) return;
|
|
226
|
-
const previousSpeech = reply.narrationKind ? "" : speechTextFromAssistant(reply.raw.slice(0, reply.consumed));
|
|
244
|
+
const previousSpeech = reply.narrationKind ? "" : speechTextFromAssistant(reply.raw.slice(0, reply.consumed), undefined, wording);
|
|
227
245
|
const maximumCharacters = reply.narrationKind ? (reply.started ? 140 : 64) : Math.max(1, Math.min(
|
|
228
246
|
reply.started ? 140 : 64,
|
|
229
247
|
VOICE_MAX_SPEECH_TEXT_CHARACTERS - previousSpeech.length,
|
|
230
248
|
VOICE_MAX_SPEECH_TEXT_CHARACTERS - reply.spokenCharacters
|
|
231
249
|
));
|
|
232
|
-
const chunk = reply.speechCapped ? null : takeStreamingSpeech(reply.raw.slice(reply.consumed), reply.final, maximumCharacters);
|
|
250
|
+
const chunk = reply.speechCapped ? null : takeStreamingSpeech(reply.raw.slice(reply.consumed), reply.final, maximumCharacters, wording);
|
|
233
251
|
if (!chunk) {
|
|
234
252
|
if (reply.final && reply.started) voice.endSpeech();
|
|
235
253
|
else if (reply.final) {
|
|
@@ -244,7 +262,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
244
262
|
if (!reply.narrationKind) {
|
|
245
263
|
// Keep offsets in raw Markdown. The original limit applies after its
|
|
246
264
|
// cleanup, including whitespace between separately streamed phrases.
|
|
247
|
-
const speech = speechTextFromAssistant(reply.raw.slice(0, reply.consumed));
|
|
265
|
+
const speech = speechTextFromAssistant(reply.raw.slice(0, reply.consumed), undefined, wording);
|
|
248
266
|
const boundary = speech.startsWith(previousSpeech)
|
|
249
267
|
? speech.slice(previousSpeech.length).match(/^\s*/u)[0].length : 0;
|
|
250
268
|
text = text.slice(0, Math.max(0, Math.min(
|
|
@@ -273,7 +291,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
273
291
|
} else if (!voice.appendSpeech(text)) return;
|
|
274
292
|
if (reply.speechCapped || (reply.final && reply.consumed >= reply.raw.length)) { voice.endSpeech(); return; }
|
|
275
293
|
}
|
|
276
|
-
} catch (cause) { error.value = cause
|
|
294
|
+
} catch (cause) { error.value = voiceErrorText(cause); stopSpeech(); }
|
|
277
295
|
finally { draining = false; }
|
|
278
296
|
}
|
|
279
297
|
function queueReply(message, final) {
|
|
@@ -359,9 +377,11 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
359
377
|
try {
|
|
360
378
|
inviteSpeech(pending.messageId);
|
|
361
379
|
const receipt = await binding.submitText(pending.text, { messageId: pending.messageId, context: pending.focus });
|
|
362
|
-
if (receipt === false || receipt?.ok === false)
|
|
380
|
+
if (receipt === false || receipt?.ok === false) {
|
|
381
|
+
throw new Error(serverMessage(receipt || {}, t("jskit.assistant.voice.errors.notAccepted")));
|
|
382
|
+
}
|
|
363
383
|
if (pendingTranscript.value === pending) dismissTranscript();
|
|
364
|
-
} catch (cause) { if (pendingTranscript.value === pending) error.value = cause
|
|
384
|
+
} catch (cause) { if (pendingTranscript.value === pending) error.value = voiceErrorText(cause); }
|
|
365
385
|
finally { sending.value = false; }
|
|
366
386
|
}
|
|
367
387
|
async function cancelRecording() {
|
|
@@ -401,7 +421,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
401
421
|
if (capturing.value) { await discardRecording(); return; }
|
|
402
422
|
if (pendingTranscript.value) return;
|
|
403
423
|
await startRecording(false);
|
|
404
|
-
} catch (cause) { recording = null; error.value = cause
|
|
424
|
+
} catch (cause) { recording = null; error.value = voiceErrorText(cause); }
|
|
405
425
|
}
|
|
406
426
|
async function startRecording(reviewBeforeSend, continuous = false) {
|
|
407
427
|
if (disposed || hiddenNarrationPage.value || starting.value || microphoneMuted.value || capturing.value || committing ||
|
|
@@ -416,7 +436,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
416
436
|
try {
|
|
417
437
|
const started = await voice.startListening({ continuous });
|
|
418
438
|
if (recording === next) { next.started = started; if (!started) recording = null; }
|
|
419
|
-
} catch (cause) { if (recording === next) { recording = null; error.value = cause
|
|
439
|
+
} catch (cause) { if (recording === next) { recording = null; error.value = voiceErrorText(cause); } }
|
|
420
440
|
}
|
|
421
441
|
async function toggleMicrophoneMuted({ preserveBuffered = false } = {}) {
|
|
422
442
|
// A person's explicit microphone choice supersedes an Edit-owned pause.
|
|
@@ -469,7 +489,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
469
489
|
}
|
|
470
490
|
if (voice.listening.value) await voice.stopListening();
|
|
471
491
|
else await cancelRecording();
|
|
472
|
-
} catch (cause) { await cancelRecording(); error.value = cause
|
|
492
|
+
} catch (cause) { await cancelRecording(); error.value = voiceErrorText(cause); }
|
|
473
493
|
}
|
|
474
494
|
async function cancelPushToTalk(event) {
|
|
475
495
|
if (!pushHolding.value || event?.pointerId !== undefined && event.pointerId !== pushInput) return;
|
|
@@ -542,7 +562,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
542
562
|
} catch (cause) {
|
|
543
563
|
if (startupAbort === controller && !controller.signal.aborted) {
|
|
544
564
|
live.value = false;
|
|
545
|
-
error.value = signal.aborted ? "
|
|
565
|
+
error.value = signal.aborted ? t("jskit.assistant.voice.errors.setupTimeout") : voiceErrorText(cause);
|
|
546
566
|
}
|
|
547
567
|
} finally {
|
|
548
568
|
if (startupAbort === controller) { startupAbort = null; starting.value = false; }
|
|
@@ -591,7 +611,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
591
611
|
if (live.value && candidate === voice.endpoint.value) {
|
|
592
612
|
live.value = false;
|
|
593
613
|
if (recording) recording.reviewBeforeSend = true;
|
|
594
|
-
error.value =
|
|
614
|
+
error.value = t("jskit.assistant.voice.errors.finishAndReview", { message: voiceErrorText(cause) });
|
|
595
615
|
}
|
|
596
616
|
}
|
|
597
617
|
}
|
|
@@ -631,7 +651,7 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
631
651
|
// Retire intent before the asynchronous PCM drain so a receipt/reset
|
|
632
652
|
// cannot finalize this capture twice. Its original final watcher sends B.
|
|
633
653
|
delete recording.finishAfterPending;
|
|
634
|
-
void voice.stopListening().catch(cause => { error.value = cause
|
|
654
|
+
void voice.stopListening().catch(cause => { error.value = voiceErrorText(cause); });
|
|
635
655
|
return;
|
|
636
656
|
}
|
|
637
657
|
if (live.value && callMode.value === "hands-free" && !changingCallMode.value && !microphoneMuted.value && !capturing.value && !pendingTranscript.value && !sending.value && !voice.error.value) void startRecording(false, true);
|
|
@@ -644,9 +664,9 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
644
664
|
if (voice.listening.value) await voice.stopListening();
|
|
645
665
|
else {
|
|
646
666
|
await cancelRecording();
|
|
647
|
-
error.value = "
|
|
667
|
+
error.value = t("jskit.assistant.voice.errors.microphoneNotReady");
|
|
648
668
|
}
|
|
649
|
-
} catch (cause) { await cancelRecording(); error.value = cause
|
|
669
|
+
} catch (cause) { await cancelRecording(); error.value = voiceErrorText(cause); }
|
|
650
670
|
}
|
|
651
671
|
async function discardHeldRecording() {
|
|
652
672
|
if (sending.value) return;
|
|
@@ -664,13 +684,13 @@ export function useVoiceConversation(binding, { socketUrl, createTransport = use
|
|
|
664
684
|
if (text) {
|
|
665
685
|
pendingTranscript.value = { ...finished, text, reviewBeforeSend: true };
|
|
666
686
|
holding.value = false;
|
|
667
|
-
error.value = "
|
|
687
|
+
error.value = t("jskit.assistant.voice.errors.recordingInterrupted");
|
|
668
688
|
}
|
|
669
689
|
return;
|
|
670
690
|
}
|
|
671
691
|
const text = voice.transcript.value.trim();
|
|
672
692
|
if (!text) {
|
|
673
|
-
if (!finished.continuous) error.value = "
|
|
693
|
+
if (!finished.continuous) error.value = t("jskit.assistant.voice.errors.noSpeech");
|
|
674
694
|
return;
|
|
675
695
|
}
|
|
676
696
|
if (live.value && !finished.reviewBeforeSend && explicitSilence(text)) {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
speechTextFromAssistant
|
|
9
9
|
} from "../shared/protocol.js";
|
|
10
10
|
import { createMicrophoneCapture } from "./audioCapture.js";
|
|
11
|
+
import { useJskitText, voiceError, voiceErrorText, voiceEventError, voiceSpeechWording } from "./i18n.js";
|
|
11
12
|
import {
|
|
12
13
|
normalizeSpeechSegment,
|
|
13
14
|
pcm16ArrayBufferToFloat32,
|
|
@@ -35,6 +36,7 @@ function resolveWebSocketUrl(value) {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnListen = false, autoReconnect = false, voiceId = "", onPlayback } = {}) {
|
|
39
|
+
const { serverMessage, t } = useJskitText();
|
|
38
40
|
const availableVoices = ref([]);
|
|
39
41
|
const selectedVoice = ref(voiceId);
|
|
40
42
|
const connectionState = ref("idle");
|
|
@@ -139,7 +141,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
139
141
|
activeListenTurnId.value = "";
|
|
140
142
|
void closeMicrophone().catch(() => null);
|
|
141
143
|
stopPlayback("failed", reason);
|
|
142
|
-
error.value = String(message || "
|
|
144
|
+
error.value = String(message || t("jskit.assistant.voice.errors.couldNotContinue"));
|
|
143
145
|
captureState.value = "idle";
|
|
144
146
|
connectionState.value = "idle";
|
|
145
147
|
}
|
|
@@ -157,8 +159,8 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
157
159
|
|
|
158
160
|
function connectionLost(message) {
|
|
159
161
|
message ||= activeListenTurnId.value || pendingListenTurnId
|
|
160
|
-
? "
|
|
161
|
-
: "
|
|
162
|
+
? t("jskit.assistant.voice.errors.interruptedRecording")
|
|
163
|
+
: t("jskit.assistant.voice.errors.interrupted");
|
|
162
164
|
const wasActive = Boolean(activeListenTurnId.value || pendingListenTurnId || activeSpeechTurnId.value || reconnecting.value);
|
|
163
165
|
setError(message, "disconnected");
|
|
164
166
|
disconnect({ preserveError: true });
|
|
@@ -173,7 +175,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
173
175
|
return;
|
|
174
176
|
}
|
|
175
177
|
if (activeSpeechTurnId.value && synthesisPending.value && Date.now() - lastSpeechProgressAt > synthesisTimeoutMs) {
|
|
176
|
-
connectionLost("
|
|
178
|
+
connectionLost(t("jskit.assistant.voice.errors.speechStalled"));
|
|
177
179
|
return;
|
|
178
180
|
}
|
|
179
181
|
if (socket?.readyState === WEBSOCKET_OPEN) sendControl({ type: "ping", turnId: "heartbeat" });
|
|
@@ -181,7 +183,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
181
183
|
|
|
182
184
|
function sendControl(payload) {
|
|
183
185
|
if (socket?.readyState !== WEBSOCKET_OPEN) {
|
|
184
|
-
throw
|
|
186
|
+
throw voiceError("jskit.assistant.voice.errors.notConnected");
|
|
185
187
|
}
|
|
186
188
|
socket.send(JSON.stringify(payload));
|
|
187
189
|
}
|
|
@@ -268,7 +270,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
268
270
|
const AudioContextCtor = window.AudioContext || window.webkitAudioContext;
|
|
269
271
|
if (!AudioContextCtor) {
|
|
270
272
|
playbackBlocked.value = true;
|
|
271
|
-
throw
|
|
273
|
+
throw voiceError("jskit.assistant.voice.errors.playbackUnsupported");
|
|
272
274
|
}
|
|
273
275
|
if (!playbackContext || playbackContext.state === "closed") {
|
|
274
276
|
playbackContext = new AudioContextCtor({ latencyHint: "interactive" });
|
|
@@ -286,7 +288,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
286
288
|
const resumed = context.resume();
|
|
287
289
|
if (preparation === playbackPreparation && context.state !== "running") playbackBlocked.value = true;
|
|
288
290
|
await resumed;
|
|
289
|
-
if (context.state !== "running") throw
|
|
291
|
+
if (context.state !== "running") throw voiceError("jskit.assistant.voice.errors.soundBlocked");
|
|
290
292
|
if (preparation === playbackPreparation && !unmounted) playbackBlocked.value = false;
|
|
291
293
|
} catch (cause) {
|
|
292
294
|
// A newer unlock of this same context supersedes an older resume failure.
|
|
@@ -379,7 +381,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
379
381
|
playbackQueue = playbackQueue
|
|
380
382
|
.then(() => schedulePcm(buffer, epoch, segment))
|
|
381
383
|
.catch((playbackError) => {
|
|
382
|
-
if (epoch === playbackEpoch) setError(playbackError
|
|
384
|
+
if (epoch === playbackEpoch) setError(voiceErrorText(playbackError));
|
|
383
385
|
})
|
|
384
386
|
.finally(() => {
|
|
385
387
|
if (epoch !== playbackEpoch) return;
|
|
@@ -528,9 +530,9 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
528
530
|
if (turnId && turnId !== activeListenTurnId.value && turnId !== activeSpeechTurnId.value) {
|
|
529
531
|
return;
|
|
530
532
|
}
|
|
531
|
-
setError(
|
|
532
|
-
? "
|
|
533
|
-
: "
|
|
533
|
+
setError(serverMessage(message, type === "busy"
|
|
534
|
+
? t("jskit.assistant.voice.errors.busy")
|
|
535
|
+
: t("jskit.assistant.voice.errors.serviceCouldNotContinue")));
|
|
534
536
|
}
|
|
535
537
|
}
|
|
536
538
|
|
|
@@ -547,7 +549,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
547
549
|
try {
|
|
548
550
|
message = JSON.parse(String(event.data || ""));
|
|
549
551
|
} catch {
|
|
550
|
-
setError("
|
|
552
|
+
setError(t("jskit.assistant.voice.errors.invalidResponse"));
|
|
551
553
|
return;
|
|
552
554
|
}
|
|
553
555
|
handleControlMessage(message);
|
|
@@ -572,7 +574,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
572
574
|
}
|
|
573
575
|
const path = selectedSocketPath.value;
|
|
574
576
|
if (!path) {
|
|
575
|
-
throw
|
|
577
|
+
throw voiceError("jskit.assistant.voice.errors.conversationRequired");
|
|
576
578
|
}
|
|
577
579
|
if (connectedSocketPath === path && socket?.readyState === WEBSOCKET_OPEN && ready.value) {
|
|
578
580
|
return true;
|
|
@@ -590,7 +592,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
590
592
|
nextSocket.binaryType = "arraybuffer";
|
|
591
593
|
connectPromise = new Promise((resolve, reject) => {
|
|
592
594
|
const timeout = setTimeout(() => {
|
|
593
|
-
reject(
|
|
595
|
+
reject(voiceError("jskit.assistant.voice.errors.connectTimeout"));
|
|
594
596
|
nextSocket.close();
|
|
595
597
|
}, 8_000);
|
|
596
598
|
const onReady = (event) => {
|
|
@@ -605,7 +607,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
605
607
|
clearTimeout(timeout);
|
|
606
608
|
nextSocket.removeEventListener("message", onReady);
|
|
607
609
|
if (message.type === "voice.ready") resolve(true);
|
|
608
|
-
else reject(
|
|
610
|
+
else reject(voiceEventError(message, "jskit.assistant.voice.errors.couldNotConnect"));
|
|
609
611
|
} catch {
|
|
610
612
|
// The regular message handler will surface malformed responses.
|
|
611
613
|
}
|
|
@@ -613,11 +615,11 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
613
615
|
nextSocket.addEventListener("message", onReady);
|
|
614
616
|
nextSocket.addEventListener("error", () => {
|
|
615
617
|
clearTimeout(timeout);
|
|
616
|
-
reject(
|
|
618
|
+
reject(voiceError("jskit.assistant.voice.errors.unreachable"));
|
|
617
619
|
}, { once: true });
|
|
618
620
|
nextSocket.addEventListener("close", () => {
|
|
619
621
|
clearTimeout(timeout);
|
|
620
|
-
reject(
|
|
622
|
+
reject(voiceError("jskit.assistant.voice.errors.closedWhileConnecting"));
|
|
621
623
|
}, { once: true });
|
|
622
624
|
});
|
|
623
625
|
nextSocket.addEventListener("message", (event) => {
|
|
@@ -639,7 +641,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
639
641
|
return await connectPromise;
|
|
640
642
|
} catch (connectionError) {
|
|
641
643
|
if (socket === nextSocket) {
|
|
642
|
-
if (!recovery) setError(connectionError
|
|
644
|
+
if (!recovery) setError(voiceErrorText(connectionError));
|
|
643
645
|
disconnect({ preserveError: true });
|
|
644
646
|
}
|
|
645
647
|
throw connectionError;
|
|
@@ -651,7 +653,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
651
653
|
return false;
|
|
652
654
|
}
|
|
653
655
|
if (microphoneOwner && microphoneOwner !== microphoneClaim) {
|
|
654
|
-
error.value = "
|
|
656
|
+
error.value = t("jskit.assistant.voice.errors.microphoneInUse");
|
|
655
657
|
return false;
|
|
656
658
|
}
|
|
657
659
|
microphoneClaim = Symbol("voice microphone");
|
|
@@ -677,7 +679,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
677
679
|
onPcm(frame) {
|
|
678
680
|
if ((!microphoneMuted.value || preserveBufferedMicrophone) && socket?.readyState === WEBSOCKET_OPEN && activeListenTurnId.value === turnId) {
|
|
679
681
|
if (socket.bufferedAmount > 32 * 1024) {
|
|
680
|
-
connectionLost("
|
|
682
|
+
connectionLost(t("jskit.assistant.voice.errors.microphoneBehind"));
|
|
681
683
|
return;
|
|
682
684
|
}
|
|
683
685
|
socket.send(frame);
|
|
@@ -692,8 +694,8 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
692
694
|
if (pendingListenTurnId !== turnId) return false;
|
|
693
695
|
const denied = ["NotAllowedError", "PermissionDeniedError"].includes(microphoneError?.name);
|
|
694
696
|
setError(denied
|
|
695
|
-
? "
|
|
696
|
-
: "
|
|
697
|
+
? t("jskit.assistant.voice.errors.microphoneDenied")
|
|
698
|
+
: t("jskit.assistant.voice.errors.microphoneUnavailable"));
|
|
697
699
|
return false;
|
|
698
700
|
}
|
|
699
701
|
if (pendingListenTurnId !== turnId) {
|
|
@@ -718,7 +720,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
718
720
|
return true;
|
|
719
721
|
} catch (startError) {
|
|
720
722
|
if (pendingListenTurnId !== turnId) return false;
|
|
721
|
-
setError(startError
|
|
723
|
+
setError(voiceErrorText(startError));
|
|
722
724
|
throw startError;
|
|
723
725
|
} finally {
|
|
724
726
|
if (pendingListenTurnId === turnId) pendingListenTurnId = "";
|
|
@@ -744,7 +746,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
744
746
|
}
|
|
745
747
|
|
|
746
748
|
async function speak(text, turnId = createVoiceTurnId("speak"), { stream = false } = {}) {
|
|
747
|
-
const speechText = speechTextFromAssistant(text);
|
|
749
|
+
const speechText = speechTextFromAssistant(text, undefined, voiceSpeechWording());
|
|
748
750
|
if (unmounted || !speechOutputEnabled.value || !speechText) {
|
|
749
751
|
return false;
|
|
750
752
|
}
|
|
@@ -789,7 +791,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
789
791
|
|
|
790
792
|
function appendSpeech(text) {
|
|
791
793
|
if (!canAppendSpeech.value) return false;
|
|
792
|
-
const speechText = speechTextFromAssistant(text);
|
|
794
|
+
const speechText = speechTextFromAssistant(text, undefined, voiceSpeechWording());
|
|
793
795
|
if (!speechText) return false;
|
|
794
796
|
if (!synthesisPending.value) lastSpeechProgressAt = Date.now();
|
|
795
797
|
synthesisPending.value += 1;
|
|
@@ -893,7 +895,7 @@ function useVoiceTransport({ socketUrl, speechEnabled = true, interruptSpeechOnL
|
|
|
893
895
|
}, { flush: "sync" });
|
|
894
896
|
function pauseForPageExit() {
|
|
895
897
|
if (activeListenTurnId.value || pendingListenTurnId || activeSpeechTurnId.value) {
|
|
896
|
-
setError("
|
|
898
|
+
setError(t("jskit.assistant.voice.errors.pageSuspended"));
|
|
897
899
|
}
|
|
898
900
|
recoveryWanted = false;
|
|
899
901
|
reconnecting.value = false;
|