@wcstack/speech 1.20.0 → 1.21.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.ja.md +7 -0
- package/README.md +7 -0
- package/dist/index.d.ts +100 -3
- package/dist/index.esm.js +223 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -91,6 +91,7 @@ export default {
|
|
|
91
91
|
| `charIndex` | number \| null | 読み上げ中の単語の位置 |
|
|
92
92
|
| `spokenWord` | string \| null | 読み上げ中の単語 |
|
|
93
93
|
| `error` | `WcsSpeakErrorDetail` \| null | 直近の失敗 |
|
|
94
|
+
| `errorInfo` | `WcsIoErrorInfo` \| null | `error` から派生するシリアライズ可能な失敗分類(`code` / `phase` / `recoverable`)。SpeechSynthesis のコード([注意・制限](#注意制限)参照)。付加的で `error` の形状は不変 |
|
|
94
95
|
| `unsupported` | boolean | SpeechSynthesis 非対応 |
|
|
95
96
|
|
|
96
97
|
### コマンド
|
|
@@ -148,6 +149,7 @@ export default {
|
|
|
148
149
|
| `listening` | boolean | セッション中 |
|
|
149
150
|
| `permission` | `"prompt"\|"granted"\|"denied"\|"unsupported"` | マイク permission |
|
|
150
151
|
| `error` | `WcsListenErrorDetail` \| null | 直近の失敗 |
|
|
152
|
+
| `errorInfo` | `WcsIoErrorInfo` \| null | `error` から派生するシリアライズ可能な失敗分類(`code` / `phase` / `recoverable`)。SpeechRecognition のコード([注意・制限](#注意制限)参照)。付加的で `error` の形状は不変 |
|
|
151
153
|
| `unsupported` | boolean | SpeechRecognition 非対応 |
|
|
152
154
|
|
|
153
155
|
### コマンド
|
|
@@ -243,6 +245,11 @@ SpeechRecognition 自体が Chrome 系のみの対応だからです(後述の
|
|
|
243
245
|
- **ブラウザ対応。** SpeechSynthesis は広く対応。SpeechRecognition は Chrome 系のみ(`webkitSpeechRecognition`)で、それ以外では `<wcs-listen>` は `unsupported` を報告します。
|
|
244
246
|
- **SpeechSynthesis はグローバルシングルトン。** `<wcs-speak>` は切断時に `cancel()` しません(他インスタンスまで止まるため)。音声を止めるには明示的に `cancel()` を。切断された要素は追跡を止めますが、発話中の utterance は自然に完了します。
|
|
245
247
|
- **echo ループ。** `<wcs-listen>` → state → `<wcs-speak>` を繋ぐときは、認識中は発話をミュート(例: `manual` を束縛)して合成音声が再認識されないように。echo の例を参照。
|
|
248
|
+
- **`errorInfo`——付加的な失敗分類。** `error` と並んで、各要素は付加的なバインド可能出力 `errorInfo`(`WcsIoErrorInfo` = 安定した `code` / `phase` / `recoverable` / `message`)を公開します。同じ失敗から派生し(`error` の形状は不変)、成功時に `null` へクリアされます。2 つの要素は **異なる** code セット(SpeechRecognition と SpeechSynthesis の error enum)を持ち、どちらも `core/speechCapabilities.ts` に定義されています:
|
|
249
|
+
- **`<wcs-listen>`**(`WCS_LISTEN_ERROR_CODE`・イベント `wcs-listen:error-info-changed`): `capability-missing`(phase `probe`——SpeechRecognition 非対応)・`not-allowed`(`start`——`not-allowed` / `service-not-allowed`、マイク権限拒否)・`not-readable`(`start`——`audio-capture`、マイク読取不可)・`no-speech`(`execute`・recoverable——無音で検出なし)・`network-error`(`execute`・recoverable——`network`)・`aborted`(`execute`・recoverable——セッション中断)・`invalid-argument`(`start`——`language-not-supported` / `bad-grammar`)・`speech-error`(`execute`——その他コードへの防御的 fallback)。
|
|
250
|
+
- **`<wcs-speak>`**(`WCS_SPEAK_ERROR_CODE`・イベント `wcs-speak:error-info-changed`): `capability-missing`(phase `probe`——SpeechSynthesis 非対応)・`not-allowed`(`start`——合成不許可)・`aborted`(`execute`・recoverable——`canceled` / `interrupted`)・`not-readable`(`execute`——`audio-busy` は recoverable、`audio-hardware` は不可)・`network-error`(`execute`・recoverable——`network`)・`invalid-argument`(`start`——`language-unavailable` / `voice-unavailable` / `text-too-long` / `invalid-argument`)・`synthesis-failed`(`execute`——`synthesis-unavailable` / `synthesis-failed`)・`speech-error`(`execute`——防御的 fallback)。
|
|
251
|
+
|
|
252
|
+
`WcsIoErrorInfo` 型と `WCS_LISTEN_ERROR_CODE` / `WCS_SPEAK_ERROR_CODE` 定数は export されます。
|
|
246
253
|
|
|
247
254
|
## ヘッドレス利用(`SpeakCore` / `ListenCore`)
|
|
248
255
|
|
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ export default {
|
|
|
92
92
|
| `charIndex` | number \| null | offset of the word being spoken |
|
|
93
93
|
| `spokenWord` | string \| null | the word being spoken |
|
|
94
94
|
| `error` | `WcsSpeakErrorDetail` \| null | last failure |
|
|
95
|
+
| `errorInfo` | `WcsIoErrorInfo` \| null | serializable failure taxonomy (`code` / `phase` / `recoverable`) derived from `error` — SpeechSynthesis codes, see [Notes & limitations](#notes--limitations); additive, `error` shape unchanged |
|
|
95
96
|
| `unsupported` | boolean | SpeechSynthesis is unavailable |
|
|
96
97
|
|
|
97
98
|
### Commands
|
|
@@ -149,6 +150,7 @@ Like `<wcs-geo>`, it has two phases: a **one-shot** recognition (default) and a
|
|
|
149
150
|
| `listening` | boolean | a session is active |
|
|
150
151
|
| `permission` | `"prompt"\|"granted"\|"denied"\|"unsupported"` | microphone permission |
|
|
151
152
|
| `error` | `WcsListenErrorDetail` \| null | last failure |
|
|
153
|
+
| `errorInfo` | `WcsIoErrorInfo` \| null | serializable failure taxonomy (`code` / `phase` / `recoverable`) derived from `error` — SpeechRecognition codes, see [Notes & limitations](#notes--limitations); additive, `error` shape unchanged |
|
|
152
154
|
| `unsupported` | boolean | SpeechRecognition is unavailable |
|
|
153
155
|
|
|
154
156
|
### Commands
|
|
@@ -244,6 +246,11 @@ DevTools open; they are not a supported styling hook.
|
|
|
244
246
|
- **Browser support.** SpeechSynthesis is broad; SpeechRecognition is Chrome-only (vendor-prefixed `webkitSpeechRecognition`) — `<wcs-listen>` reports `unsupported` elsewhere.
|
|
245
247
|
- **SpeechSynthesis is a global singleton.** `<wcs-speak>` does **not** `cancel()` on disconnect (that would stop other instances); call `cancel()` explicitly to stop audio. A disconnected element stops tracking but any in-flight utterance finishes.
|
|
246
248
|
- **Echo loop.** When wiring `<wcs-listen>` → state → `<wcs-speak>`, mute speaking while listening (e.g. bind `manual`) so the synthesized audio is not re-recognized. See the echo example.
|
|
249
|
+
- **`errorInfo` — additive failure taxonomy.** Alongside `error`, each element exposes an **additive** bindable output `errorInfo` (`WcsIoErrorInfo` = a stable `code` / `phase` / `recoverable` / `message`), derived from the same failure — the `error` shape is unchanged — and cleared to `null` on success. The two elements have **different** code sets (SpeechRecognition vs SpeechSynthesis error enums), both defined in `core/speechCapabilities.ts`:
|
|
250
|
+
- **`<wcs-listen>`** (`WCS_LISTEN_ERROR_CODE`, event `wcs-listen:error-info-changed`): `capability-missing` (phase `probe` — SpeechRecognition absent), `not-allowed` (`start` — `not-allowed` / `service-not-allowed`, mic permission denied), `not-readable` (`start` — `audio-capture`, mic unreadable), `no-speech` (`execute`, recoverable — silence, nothing detected), `network-error` (`execute`, recoverable — `network`), `aborted` (`execute`, recoverable — session interrupted), `invalid-argument` (`start` — `language-not-supported` / `bad-grammar`), `speech-error` (`execute` — defensive fallback for any other code).
|
|
251
|
+
- **`<wcs-speak>`** (`WCS_SPEAK_ERROR_CODE`, event `wcs-speak:error-info-changed`): `capability-missing` (phase `probe` — SpeechSynthesis absent), `not-allowed` (`start` — synthesis disallowed), `aborted` (`execute`, recoverable — `canceled` / `interrupted`), `not-readable` (`execute` — `audio-busy` recoverable, `audio-hardware` not), `network-error` (`execute`, recoverable — `network`), `invalid-argument` (`start` — `language-unavailable` / `voice-unavailable` / `text-too-long` / `invalid-argument`), `synthesis-failed` (`execute` — `synthesis-unavailable` / `synthesis-failed`), `speech-error` (`execute` — defensive fallback).
|
|
252
|
+
|
|
253
|
+
The `WcsIoErrorInfo` type and the `WCS_LISTEN_ERROR_CODE` / `WCS_SPEAK_ERROR_CODE` constants are exported.
|
|
247
254
|
|
|
248
255
|
## Headless usage (`SpeakCore` / `ListenCore`)
|
|
249
256
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/** operation error の phase(taxonomy)。 */
|
|
2
|
+
type WcsIoErrorPhase = "probe" | "start" | "execute" | "decode" | "commit" | "dispose";
|
|
3
|
+
/** serializable な error info(non-cloneable な cause とは分離。DevTools / remote へは info のみ)。 */
|
|
4
|
+
interface WcsIoErrorInfo {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly phase: WcsIoErrorPhase;
|
|
7
|
+
readonly recoverable: boolean;
|
|
8
|
+
readonly capabilityId?: string;
|
|
9
|
+
readonly message: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
interface IWcBindableProperty {
|
|
2
13
|
readonly name: string;
|
|
3
14
|
readonly event: string;
|
|
@@ -13,7 +24,8 @@ interface IWcBindableCommand {
|
|
|
13
24
|
}
|
|
14
25
|
interface IWcBindable {
|
|
15
26
|
readonly protocol: "wc-bindable";
|
|
16
|
-
|
|
27
|
+
/** Integer protocol version. All versions >= 1 are core-compatible. */
|
|
28
|
+
readonly version: number;
|
|
17
29
|
readonly properties: readonly IWcBindableProperty[];
|
|
18
30
|
readonly inputs?: readonly IWcBindableInput[];
|
|
19
31
|
readonly commands?: readonly IWcBindableCommand[];
|
|
@@ -88,6 +100,8 @@ interface WcsSpeakCoreValues {
|
|
|
88
100
|
charIndex: number | null;
|
|
89
101
|
spokenWord: string | null;
|
|
90
102
|
error: WcsSpeakErrorDetail | null;
|
|
103
|
+
/** Phase 6 serializable failure taxonomy derived from `error`, or null. */
|
|
104
|
+
errorInfo: WcsIoErrorInfo | null;
|
|
91
105
|
unsupported: boolean;
|
|
92
106
|
}
|
|
93
107
|
/**
|
|
@@ -189,6 +203,8 @@ interface WcsListenCoreValues {
|
|
|
189
203
|
listening: boolean;
|
|
190
204
|
permission: ListenPermissionState;
|
|
191
205
|
error: WcsListenErrorDetail | null;
|
|
206
|
+
/** Phase 6 serializable failure taxonomy derived from `error`, or null. */
|
|
207
|
+
errorInfo: WcsIoErrorInfo | null;
|
|
192
208
|
unsupported: boolean;
|
|
193
209
|
}
|
|
194
210
|
/**
|
|
@@ -257,6 +273,7 @@ declare class SpeakCore extends EventTarget {
|
|
|
257
273
|
private _charIndex;
|
|
258
274
|
private _spokenWord;
|
|
259
275
|
private _error;
|
|
276
|
+
private _errorInfo;
|
|
260
277
|
private _unsupported;
|
|
261
278
|
private _queued;
|
|
262
279
|
private _started;
|
|
@@ -271,6 +288,13 @@ declare class SpeakCore extends EventTarget {
|
|
|
271
288
|
get charIndex(): number | null;
|
|
272
289
|
get spokenWord(): string | null;
|
|
273
290
|
get error(): WcsSpeakErrorDetail | null;
|
|
291
|
+
/**
|
|
292
|
+
* The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /
|
|
293
|
+
* `recoverable`), or null. Additive wc-bindable property (event
|
|
294
|
+
* `wcs-speak:error-info-changed`), derived from `error`; the existing `error`
|
|
295
|
+
* property/event are unchanged.
|
|
296
|
+
*/
|
|
297
|
+
get errorInfo(): WcsIoErrorInfo | null;
|
|
274
298
|
get unsupported(): boolean;
|
|
275
299
|
/** Resolves once the first probe settles (immediate — see `_ready`). */
|
|
276
300
|
get ready(): Promise<void>;
|
|
@@ -281,6 +305,7 @@ declare class SpeakCore extends EventTarget {
|
|
|
281
305
|
private _setPending;
|
|
282
306
|
private _setBoundary;
|
|
283
307
|
private _setError;
|
|
308
|
+
private _commitErrorInfo;
|
|
284
309
|
private _setUnsupported;
|
|
285
310
|
/**
|
|
286
311
|
* Queue an utterance for `text` with optional per-utterance parameters. Never
|
|
@@ -373,6 +398,7 @@ declare class WcsSpeak extends HTMLElement {
|
|
|
373
398
|
get charIndex(): number | null;
|
|
374
399
|
get spokenWord(): string | null;
|
|
375
400
|
get error(): WcsSpeakErrorDetail | null;
|
|
401
|
+
get errorInfo(): WcsIoErrorInfo | null;
|
|
376
402
|
get unsupported(): boolean;
|
|
377
403
|
speak(text: string): void;
|
|
378
404
|
cancel(): void;
|
|
@@ -417,6 +443,7 @@ declare class ListenCore extends EventTarget {
|
|
|
417
443
|
private _listening;
|
|
418
444
|
private _permission;
|
|
419
445
|
private _error;
|
|
446
|
+
private _errorInfo;
|
|
420
447
|
private _unsupported;
|
|
421
448
|
private _active;
|
|
422
449
|
private _continuous;
|
|
@@ -433,6 +460,13 @@ declare class ListenCore extends EventTarget {
|
|
|
433
460
|
get listening(): boolean;
|
|
434
461
|
get permission(): ListenPermissionState;
|
|
435
462
|
get error(): WcsListenErrorDetail | null;
|
|
463
|
+
/**
|
|
464
|
+
* The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /
|
|
465
|
+
* `recoverable`), or null. Additive wc-bindable property (event
|
|
466
|
+
* `wcs-listen:error-info-changed`), derived from `error`; the existing `error`
|
|
467
|
+
* property/event are unchanged.
|
|
468
|
+
*/
|
|
469
|
+
get errorInfo(): WcsIoErrorInfo | null;
|
|
436
470
|
get unsupported(): boolean;
|
|
437
471
|
/** Resolves once the first probe settles (immediate — see `_ready`). */
|
|
438
472
|
get ready(): Promise<void>;
|
|
@@ -442,6 +476,7 @@ declare class ListenCore extends EventTarget {
|
|
|
442
476
|
private _setListening;
|
|
443
477
|
private _setPermission;
|
|
444
478
|
private _setError;
|
|
479
|
+
private _commitErrorInfo;
|
|
445
480
|
private _setUnsupported;
|
|
446
481
|
/**
|
|
447
482
|
* Begin a recognition session. Resets the transcripts (a fresh, user-initiated
|
|
@@ -518,6 +553,7 @@ declare class WcsListen extends HTMLElement {
|
|
|
518
553
|
get listening(): boolean;
|
|
519
554
|
get permission(): ListenPermissionState;
|
|
520
555
|
get error(): WcsListenErrorDetail | null;
|
|
556
|
+
get errorInfo(): WcsIoErrorInfo | null;
|
|
521
557
|
get unsupported(): boolean;
|
|
522
558
|
get trigger(): boolean;
|
|
523
559
|
set trigger(value: boolean);
|
|
@@ -529,5 +565,66 @@ declare class WcsListen extends HTMLElement {
|
|
|
529
565
|
disconnectedCallback(): void;
|
|
530
566
|
}
|
|
531
567
|
|
|
532
|
-
|
|
533
|
-
|
|
568
|
+
/**
|
|
569
|
+
* speechCapabilities.ts
|
|
570
|
+
*
|
|
571
|
+
* speech node 固有の error code(taxonomy)と derivation。汎用の error info 型は
|
|
572
|
+
* `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から
|
|
573
|
+
* import する。speech パッケージは 2 つの Core を持つ:
|
|
574
|
+
*
|
|
575
|
+
* - ListenCore(`<wcs-listen>`, SpeechRecognition / STT) — 認識セッションの
|
|
576
|
+
* start/stop/abort。監視ではなく command 駆動だが、競合する非同期 operation の lane は
|
|
577
|
+
* 持たない(直近の start が単一セッションを置換する)ため、lane は採用せず error
|
|
578
|
+
* taxonomy(errorInfo)のみを追加する。
|
|
579
|
+
* - SpeakCore(`<wcs-speak>`, SpeechSynthesis / TTS) — 発話キュー。同上。
|
|
580
|
+
*
|
|
581
|
+
* SpeechRecognitionErrorEvent と SpeechSynthesisErrorEvent は `error` enum の値集合が
|
|
582
|
+
* 異なるため、taxonomy も Core ごとに別 derive を持つ。いずれの Core も error detail の
|
|
583
|
+
* `.error` は既に安定コード(SpeechRecognition/SpeechSynthesis の error enum、または
|
|
584
|
+
* `"unsupported"` fallback)であり Error.name ではないので、derivation は notification と
|
|
585
|
+
* 同型の「`.error` コードを taxonomy に写す純粋 map」である。想定外のコードは防御的に
|
|
586
|
+
* `speech-error` へ畳む。
|
|
587
|
+
*/
|
|
588
|
+
|
|
589
|
+
/** 安定した listen(SpeechRecognition)error code(taxonomy)。値は公開キーとして固定。 */
|
|
590
|
+
declare const WCS_LISTEN_ERROR_CODE: {
|
|
591
|
+
/** SpeechRecognition API 非対応(`SpeechRecognition` / `webkitSpeechRecognition` 不在)。 */
|
|
592
|
+
readonly CapabilityMissing: "capability-missing";
|
|
593
|
+
/** `not-allowed` / `service-not-allowed` — マイク権限拒否 / サービス不許可。 */
|
|
594
|
+
readonly NotAllowed: "not-allowed";
|
|
595
|
+
/** `audio-capture` — マイクが読めない(不在 / ハードウェア)。 */
|
|
596
|
+
readonly NotReadable: "not-readable";
|
|
597
|
+
/** `no-speech` — 無音のまま検出できず(transient — retry で成功しうる)。 */
|
|
598
|
+
readonly NoSpeech: "no-speech";
|
|
599
|
+
/** `network` — 認識バックエンドへの通信失敗(transient)。 */
|
|
600
|
+
readonly NetworkError: "network-error";
|
|
601
|
+
/** `aborted` — セッションが中断された(transient)。 */
|
|
602
|
+
readonly Aborted: "aborted";
|
|
603
|
+
/** `language-not-supported` / `bad-grammar` — 言語 / 文法が不正(前提条件違反)。 */
|
|
604
|
+
readonly InvalidArgument: "invalid-argument";
|
|
605
|
+
/** その他 / 想定外の error code に対する防御的 fallback。 */
|
|
606
|
+
readonly SpeechError: "speech-error";
|
|
607
|
+
};
|
|
608
|
+
/** 安定した speak(SpeechSynthesis)error code(taxonomy)。値は公開キーとして固定。 */
|
|
609
|
+
declare const WCS_SPEAK_ERROR_CODE: {
|
|
610
|
+
/** SpeechSynthesis API 非対応(`speechSynthesis` / `SpeechSynthesisUtterance` 不在)。 */
|
|
611
|
+
readonly CapabilityMissing: "capability-missing";
|
|
612
|
+
/** `not-allowed` — 合成が許可されていない。 */
|
|
613
|
+
readonly NotAllowed: "not-allowed";
|
|
614
|
+
/** `canceled` / `interrupted` — 発話がキャンセル / 中断された(transient)。 */
|
|
615
|
+
readonly Aborted: "aborted";
|
|
616
|
+
/** `audio-busy` / `audio-hardware` — オーディオ出力の占有 / ハードウェア障害。 */
|
|
617
|
+
readonly NotReadable: "not-readable";
|
|
618
|
+
/** `network` — 合成バックエンドへの通信失敗(transient)。 */
|
|
619
|
+
readonly NetworkError: "network-error";
|
|
620
|
+
/** `language-unavailable` / `voice-unavailable` / `text-too-long` / `invalid-argument` —
|
|
621
|
+
* 発話パラメータが不正 / 未対応(前提条件違反)。 */
|
|
622
|
+
readonly InvalidArgument: "invalid-argument";
|
|
623
|
+
/** `synthesis-unavailable` / `synthesis-failed` — 合成そのものが失敗した。 */
|
|
624
|
+
readonly SynthesisFailed: "synthesis-failed";
|
|
625
|
+
/** その他 / 想定外の error code に対する防御的 fallback。 */
|
|
626
|
+
readonly SpeechError: "speech-error";
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
export { ListenCore, SpeakCore, WCS_LISTEN_ERROR_CODE, WCS_SPEAK_ERROR_CODE, WcsListen, WcsSpeak, bootstrapSpeech, getConfig };
|
|
630
|
+
export type { IWritableConfig, IWritableTagNames, ListenOptions, ListenPermissionState, SpeakOptions, SpeechVoiceInfo, WcsIoErrorInfo, WcsIoErrorPhase, WcsListenAlternative, WcsListenCommands, WcsListenCoreCommands, WcsListenCoreValues, WcsListenErrorDetail, WcsListenInputs, WcsListenResultDetail, WcsListenValues, WcsSpeakCommands, WcsSpeakCoreCommands, WcsSpeakCoreValues, WcsSpeakErrorDetail, WcsSpeakInputs, WcsSpeakValues };
|
package/dist/index.esm.js
CHANGED
|
@@ -56,6 +56,162 @@ function setConfig(partialConfig) {
|
|
|
56
56
|
frozenConfig = null;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* speechCapabilities.ts
|
|
61
|
+
*
|
|
62
|
+
* speech node 固有の error code(taxonomy)と derivation。汎用の error info 型は
|
|
63
|
+
* `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から
|
|
64
|
+
* import する。speech パッケージは 2 つの Core を持つ:
|
|
65
|
+
*
|
|
66
|
+
* - ListenCore(`<wcs-listen>`, SpeechRecognition / STT) — 認識セッションの
|
|
67
|
+
* start/stop/abort。監視ではなく command 駆動だが、競合する非同期 operation の lane は
|
|
68
|
+
* 持たない(直近の start が単一セッションを置換する)ため、lane は採用せず error
|
|
69
|
+
* taxonomy(errorInfo)のみを追加する。
|
|
70
|
+
* - SpeakCore(`<wcs-speak>`, SpeechSynthesis / TTS) — 発話キュー。同上。
|
|
71
|
+
*
|
|
72
|
+
* SpeechRecognitionErrorEvent と SpeechSynthesisErrorEvent は `error` enum の値集合が
|
|
73
|
+
* 異なるため、taxonomy も Core ごとに別 derive を持つ。いずれの Core も error detail の
|
|
74
|
+
* `.error` は既に安定コード(SpeechRecognition/SpeechSynthesis の error enum、または
|
|
75
|
+
* `"unsupported"` fallback)であり Error.name ではないので、derivation は notification と
|
|
76
|
+
* 同型の「`.error` コードを taxonomy に写す純粋 map」である。想定外のコードは防御的に
|
|
77
|
+
* `speech-error` へ畳む。
|
|
78
|
+
*/
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// SpeechRecognition (STT) — <wcs-listen>
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
/** 安定した listen(SpeechRecognition)error code(taxonomy)。値は公開キーとして固定。 */
|
|
83
|
+
const WCS_LISTEN_ERROR_CODE = {
|
|
84
|
+
/** SpeechRecognition API 非対応(`SpeechRecognition` / `webkitSpeechRecognition` 不在)。 */
|
|
85
|
+
CapabilityMissing: "capability-missing",
|
|
86
|
+
/** `not-allowed` / `service-not-allowed` — マイク権限拒否 / サービス不許可。 */
|
|
87
|
+
NotAllowed: "not-allowed",
|
|
88
|
+
/** `audio-capture` — マイクが読めない(不在 / ハードウェア)。 */
|
|
89
|
+
NotReadable: "not-readable",
|
|
90
|
+
/** `no-speech` — 無音のまま検出できず(transient — retry で成功しうる)。 */
|
|
91
|
+
NoSpeech: "no-speech",
|
|
92
|
+
/** `network` — 認識バックエンドへの通信失敗(transient)。 */
|
|
93
|
+
NetworkError: "network-error",
|
|
94
|
+
/** `aborted` — セッションが中断された(transient)。 */
|
|
95
|
+
Aborted: "aborted",
|
|
96
|
+
/** `language-not-supported` / `bad-grammar` — 言語 / 文法が不正(前提条件違反)。 */
|
|
97
|
+
InvalidArgument: "invalid-argument",
|
|
98
|
+
/** その他 / 想定外の error code に対する防御的 fallback。 */
|
|
99
|
+
SpeechError: "speech-error",
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* listen(SpeechRecognition)の失敗を serializable な error taxonomy に写す。引数は
|
|
103
|
+
* `wcs-listen:error` の detail(`{ error, message }`)そのもの。`.error` は
|
|
104
|
+
* `SpeechRecognitionErrorEvent.error` enum(または `"unsupported"` / `"aborted"`
|
|
105
|
+
* fallback)で、Error.name ではない。
|
|
106
|
+
*
|
|
107
|
+
* - `"unsupported"` は開始前の能力欠如 → phase="probe" / capability-missing。
|
|
108
|
+
* - `"not-allowed"` / `"service-not-allowed"` はマイク権限拒否 → phase="start" /
|
|
109
|
+
* not-allowed。回復しない(recoverable=false)。ListenCore はこの 2 つを終端扱いにし
|
|
110
|
+
* 自動再開を止める。
|
|
111
|
+
* - `"audio-capture"` はマイクの読取失敗 → phase="start" / not-readable / false。
|
|
112
|
+
* - `"no-speech"` / `"network"` / `"aborted"` は transient で、continuous セッションは
|
|
113
|
+
* `maxRestarts` の範囲で自動再開しうる → phase="execute" / recoverable=true。
|
|
114
|
+
* - `"language-not-supported"` / `"bad-grammar"` は言語 / 文法の前提違反 →
|
|
115
|
+
* phase="start" / invalid-argument / false。
|
|
116
|
+
* - それ以外(未知コード)は防御的に phase="execute" / speech-error / false。
|
|
117
|
+
*/
|
|
118
|
+
function deriveListenErrorInfo(error) {
|
|
119
|
+
const { error: code, message } = error;
|
|
120
|
+
switch (code) {
|
|
121
|
+
case "unsupported":
|
|
122
|
+
return { code: WCS_LISTEN_ERROR_CODE.CapabilityMissing, phase: "probe", recoverable: false, message };
|
|
123
|
+
case "not-allowed":
|
|
124
|
+
case "service-not-allowed":
|
|
125
|
+
return { code: WCS_LISTEN_ERROR_CODE.NotAllowed, phase: "start", recoverable: false, message };
|
|
126
|
+
case "audio-capture":
|
|
127
|
+
return { code: WCS_LISTEN_ERROR_CODE.NotReadable, phase: "start", recoverable: false, message };
|
|
128
|
+
case "no-speech":
|
|
129
|
+
return { code: WCS_LISTEN_ERROR_CODE.NoSpeech, phase: "execute", recoverable: true, message };
|
|
130
|
+
case "network":
|
|
131
|
+
return { code: WCS_LISTEN_ERROR_CODE.NetworkError, phase: "execute", recoverable: true, message };
|
|
132
|
+
case "aborted":
|
|
133
|
+
return { code: WCS_LISTEN_ERROR_CODE.Aborted, phase: "execute", recoverable: true, message };
|
|
134
|
+
case "language-not-supported":
|
|
135
|
+
case "bad-grammar":
|
|
136
|
+
return { code: WCS_LISTEN_ERROR_CODE.InvalidArgument, phase: "start", recoverable: false, message };
|
|
137
|
+
default:
|
|
138
|
+
return { code: WCS_LISTEN_ERROR_CODE.SpeechError, phase: "execute", recoverable: false, message };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// SpeechSynthesis (TTS) — <wcs-speak>
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
/** 安定した speak(SpeechSynthesis)error code(taxonomy)。値は公開キーとして固定。 */
|
|
145
|
+
const WCS_SPEAK_ERROR_CODE = {
|
|
146
|
+
/** SpeechSynthesis API 非対応(`speechSynthesis` / `SpeechSynthesisUtterance` 不在)。 */
|
|
147
|
+
CapabilityMissing: "capability-missing",
|
|
148
|
+
/** `not-allowed` — 合成が許可されていない。 */
|
|
149
|
+
NotAllowed: "not-allowed",
|
|
150
|
+
/** `canceled` / `interrupted` — 発話がキャンセル / 中断された(transient)。 */
|
|
151
|
+
Aborted: "aborted",
|
|
152
|
+
/** `audio-busy` / `audio-hardware` — オーディオ出力の占有 / ハードウェア障害。 */
|
|
153
|
+
NotReadable: "not-readable",
|
|
154
|
+
/** `network` — 合成バックエンドへの通信失敗(transient)。 */
|
|
155
|
+
NetworkError: "network-error",
|
|
156
|
+
/** `language-unavailable` / `voice-unavailable` / `text-too-long` / `invalid-argument` —
|
|
157
|
+
* 発話パラメータが不正 / 未対応(前提条件違反)。 */
|
|
158
|
+
InvalidArgument: "invalid-argument",
|
|
159
|
+
/** `synthesis-unavailable` / `synthesis-failed` — 合成そのものが失敗した。 */
|
|
160
|
+
SynthesisFailed: "synthesis-failed",
|
|
161
|
+
/** その他 / 想定外の error code に対する防御的 fallback。 */
|
|
162
|
+
SpeechError: "speech-error",
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* speak(SpeechSynthesis)の失敗を serializable な error taxonomy に写す。引数は
|
|
166
|
+
* `wcs-speak:error` の detail(`{ error, message }`)そのもの。`.error` は
|
|
167
|
+
* `SpeechSynthesisErrorEvent.error` enum(または `"unsupported"` /
|
|
168
|
+
* `"synthesis-failed"` fallback)で、Error.name ではない。
|
|
169
|
+
*
|
|
170
|
+
* - `"unsupported"` は開始前の能力欠如 → phase="probe" / capability-missing。
|
|
171
|
+
* - `"not-allowed"` は合成不許可 → phase="start" / not-allowed / false。
|
|
172
|
+
* - `"canceled"` / `"interrupted"` は cancel()/後続発話による中断 → phase="execute" /
|
|
173
|
+
* aborted / recoverable=true(通常は SpeakCore の世代ガードが握りつぶすため error として
|
|
174
|
+
* 表面化しないが、防御的に写す)。
|
|
175
|
+
* - `"audio-busy"` はオーディオ占有で transient(retry で回復しうる)→ phase="execute" /
|
|
176
|
+
* not-readable / recoverable=true。`"audio-hardware"` はハードウェア障害で回復しない →
|
|
177
|
+
* 同 not-readable だが recoverable=false。
|
|
178
|
+
* - `"network"` は transient → phase="execute" / network-error / recoverable=true。
|
|
179
|
+
* - `"language-unavailable"` / `"voice-unavailable"` / `"text-too-long"` /
|
|
180
|
+
* `"invalid-argument"` は発話パラメータの前提違反 → phase="start" / invalid-argument /
|
|
181
|
+
* false。
|
|
182
|
+
* - `"synthesis-unavailable"` / `"synthesis-failed"` は合成実行の失敗 → phase="execute" /
|
|
183
|
+
* synthesis-failed / false。
|
|
184
|
+
* - それ以外(未知コード)は防御的に phase="execute" / speech-error / false。
|
|
185
|
+
*/
|
|
186
|
+
function deriveSpeakErrorInfo(error) {
|
|
187
|
+
const { error: code, message } = error;
|
|
188
|
+
switch (code) {
|
|
189
|
+
case "unsupported":
|
|
190
|
+
return { code: WCS_SPEAK_ERROR_CODE.CapabilityMissing, phase: "probe", recoverable: false, message };
|
|
191
|
+
case "not-allowed":
|
|
192
|
+
return { code: WCS_SPEAK_ERROR_CODE.NotAllowed, phase: "start", recoverable: false, message };
|
|
193
|
+
case "canceled":
|
|
194
|
+
case "interrupted":
|
|
195
|
+
return { code: WCS_SPEAK_ERROR_CODE.Aborted, phase: "execute", recoverable: true, message };
|
|
196
|
+
case "audio-busy":
|
|
197
|
+
return { code: WCS_SPEAK_ERROR_CODE.NotReadable, phase: "execute", recoverable: true, message };
|
|
198
|
+
case "audio-hardware":
|
|
199
|
+
return { code: WCS_SPEAK_ERROR_CODE.NotReadable, phase: "execute", recoverable: false, message };
|
|
200
|
+
case "network":
|
|
201
|
+
return { code: WCS_SPEAK_ERROR_CODE.NetworkError, phase: "execute", recoverable: true, message };
|
|
202
|
+
case "language-unavailable":
|
|
203
|
+
case "voice-unavailable":
|
|
204
|
+
case "text-too-long":
|
|
205
|
+
case "invalid-argument":
|
|
206
|
+
return { code: WCS_SPEAK_ERROR_CODE.InvalidArgument, phase: "start", recoverable: false, message };
|
|
207
|
+
case "synthesis-unavailable":
|
|
208
|
+
case "synthesis-failed":
|
|
209
|
+
return { code: WCS_SPEAK_ERROR_CODE.SynthesisFailed, phase: "execute", recoverable: false, message };
|
|
210
|
+
default:
|
|
211
|
+
return { code: WCS_SPEAK_ERROR_CODE.SpeechError, phase: "execute", recoverable: false, message };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
59
215
|
/**
|
|
60
216
|
* Headless text-to-speech primitive. A thin, framework-agnostic wrapper around
|
|
61
217
|
* the SpeechSynthesis API exposed through the wc-bindable protocol.
|
|
@@ -89,6 +245,13 @@ class SpeakCore extends EventTarget {
|
|
|
89
245
|
{ name: "charIndex", event: "wcs-speak:boundary", getter: (e) => e.detail?.charIndex ?? null },
|
|
90
246
|
{ name: "spokenWord", event: "wcs-speak:boundary", getter: (e) => e.detail?.word ?? null },
|
|
91
247
|
{ name: "error", event: "wcs-speak:error" },
|
|
248
|
+
// Serializable failure taxonomy (stable code / phase / recoverable), or null.
|
|
249
|
+
// Additive bindable output derived from `error.error` (the
|
|
250
|
+
// SpeechSynthesisErrorEvent.error code / "unsupported"); the existing `error`
|
|
251
|
+
// property/event are unchanged. Fires wcs-speak:error-info-changed. No lane —
|
|
252
|
+
// speak() is a momentary queue submission with no competing async operation to
|
|
253
|
+
// serialize.
|
|
254
|
+
{ name: "errorInfo", event: "wcs-speak:error-info-changed" },
|
|
92
255
|
{ name: "unsupported", event: "wcs-speak:unsupported-changed" },
|
|
93
256
|
],
|
|
94
257
|
commands: [
|
|
@@ -107,6 +270,7 @@ class SpeakCore extends EventTarget {
|
|
|
107
270
|
_charIndex = null;
|
|
108
271
|
_spokenWord = null;
|
|
109
272
|
_error = null;
|
|
273
|
+
_errorInfo = null;
|
|
110
274
|
_unsupported = false;
|
|
111
275
|
// Count of utterances submitted via speak() but not yet started, and of
|
|
112
276
|
// utterances started but not yet ended/errored. `pending`/`speaking` are
|
|
@@ -162,6 +326,15 @@ class SpeakCore extends EventTarget {
|
|
|
162
326
|
get error() {
|
|
163
327
|
return this._error;
|
|
164
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /
|
|
331
|
+
* `recoverable`), or null. Additive wc-bindable property (event
|
|
332
|
+
* `wcs-speak:error-info-changed`), derived from `error`; the existing `error`
|
|
333
|
+
* property/event are unchanged.
|
|
334
|
+
*/
|
|
335
|
+
get errorInfo() {
|
|
336
|
+
return this._errorInfo;
|
|
337
|
+
}
|
|
165
338
|
// Resolved once in the constructor (`_setUnsupported(!_hasApi())`) and never
|
|
166
339
|
// re-evaluated: the speechSynthesis API's presence is immutable for the
|
|
167
340
|
// lifetime of a document, so there's nothing to re-check.
|
|
@@ -244,11 +417,24 @@ class SpeakCore extends EventTarget {
|
|
|
244
417
|
if (this._error === error)
|
|
245
418
|
return;
|
|
246
419
|
this._error = error;
|
|
420
|
+
// Keep the additive `errorInfo` taxonomy in sync with `error`: derive from the
|
|
421
|
+
// error code (or null on clear). Fires before the `error` event so an observer
|
|
422
|
+
// binding both sees the classification first, mirroring the io-node family.
|
|
423
|
+
this._commitErrorInfo(error === null ? null : deriveSpeakErrorInfo(error));
|
|
247
424
|
this._target.dispatchEvent(new CustomEvent("wcs-speak:error", {
|
|
248
425
|
detail: error,
|
|
249
426
|
bubbles: true,
|
|
250
427
|
}));
|
|
251
428
|
}
|
|
429
|
+
// Called only from _setError (which already guards on error identity), so
|
|
430
|
+
// errorInfo transitions exactly when error does — no separate guard needed here.
|
|
431
|
+
_commitErrorInfo(info) {
|
|
432
|
+
this._errorInfo = info;
|
|
433
|
+
this._target.dispatchEvent(new CustomEvent("wcs-speak:error-info-changed", {
|
|
434
|
+
detail: info,
|
|
435
|
+
bubbles: true,
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
252
438
|
_setUnsupported(unsupported) {
|
|
253
439
|
if (this._unsupported === unsupported)
|
|
254
440
|
return;
|
|
@@ -741,6 +927,11 @@ class WcsSpeak extends HTMLElement {
|
|
|
741
927
|
get error() {
|
|
742
928
|
return this._core.error;
|
|
743
929
|
}
|
|
930
|
+
// Additive Phase 6 taxonomy output (event wcs-speak:error-info-changed),
|
|
931
|
+
// delegated from the Core; declared via the inherited SpeakCore.wcBindable.
|
|
932
|
+
get errorInfo() {
|
|
933
|
+
return this._core.errorInfo;
|
|
934
|
+
}
|
|
744
935
|
get unsupported() {
|
|
745
936
|
return this._core.unsupported;
|
|
746
937
|
}
|
|
@@ -831,6 +1022,12 @@ class ListenCore extends EventTarget {
|
|
|
831
1022
|
{ name: "listening", event: "wcs-listen:listening-changed" },
|
|
832
1023
|
{ name: "permission", event: "wcs-listen:permission-changed" },
|
|
833
1024
|
{ name: "error", event: "wcs-listen:error" },
|
|
1025
|
+
// Serializable failure taxonomy (stable code / phase / recoverable), or null.
|
|
1026
|
+
// Additive bindable output derived from `error.error` (the
|
|
1027
|
+
// SpeechRecognitionErrorEvent.error code / "unsupported"); the existing `error`
|
|
1028
|
+
// property/event are unchanged. Fires wcs-listen:error-info-changed. No lane —
|
|
1029
|
+
// recognition has no competing async operation to serialize.
|
|
1030
|
+
{ name: "errorInfo", event: "wcs-listen:error-info-changed" },
|
|
834
1031
|
{ name: "unsupported", event: "wcs-listen:unsupported-changed" },
|
|
835
1032
|
],
|
|
836
1033
|
commands: [
|
|
@@ -847,6 +1044,7 @@ class ListenCore extends EventTarget {
|
|
|
847
1044
|
_listening = false;
|
|
848
1045
|
_permission = "prompt";
|
|
849
1046
|
_error = null;
|
|
1047
|
+
_errorInfo = null;
|
|
850
1048
|
_unsupported = false;
|
|
851
1049
|
// Intent flag: true between start() and stop()/abort()/terminal-error. Gates
|
|
852
1050
|
// the auto-restart loop so a session that ended because the user stopped it
|
|
@@ -893,6 +1091,15 @@ class ListenCore extends EventTarget {
|
|
|
893
1091
|
get error() {
|
|
894
1092
|
return this._error;
|
|
895
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /
|
|
1096
|
+
* `recoverable`), or null. Additive wc-bindable property (event
|
|
1097
|
+
* `wcs-listen:error-info-changed`), derived from `error`; the existing `error`
|
|
1098
|
+
* property/event are unchanged.
|
|
1099
|
+
*/
|
|
1100
|
+
get errorInfo() {
|
|
1101
|
+
return this._errorInfo;
|
|
1102
|
+
}
|
|
896
1103
|
// Resolved once in the constructor (`_setUnsupported(!Ctor)`) and never
|
|
897
1104
|
// re-evaluated: the SpeechRecognition API's presence is immutable for the
|
|
898
1105
|
// lifetime of a document, so there's nothing to re-check.
|
|
@@ -936,8 +1143,18 @@ class ListenCore extends EventTarget {
|
|
|
936
1143
|
if (this._error === value)
|
|
937
1144
|
return;
|
|
938
1145
|
this._error = value;
|
|
1146
|
+
// Keep the additive `errorInfo` taxonomy in sync with `error`: derive from the
|
|
1147
|
+
// error code (or null on clear). Fires before the `error` event so an observer
|
|
1148
|
+
// binding both sees the classification first, mirroring the io-node family.
|
|
1149
|
+
this._commitErrorInfo(value === null ? null : deriveListenErrorInfo(value));
|
|
939
1150
|
this._target.dispatchEvent(new CustomEvent("wcs-listen:error", { detail: value, bubbles: true }));
|
|
940
1151
|
}
|
|
1152
|
+
// Called only from _setError (which already guards on error identity), so
|
|
1153
|
+
// errorInfo transitions exactly when error does — no separate guard needed here.
|
|
1154
|
+
_commitErrorInfo(info) {
|
|
1155
|
+
this._errorInfo = info;
|
|
1156
|
+
this._target.dispatchEvent(new CustomEvent("wcs-listen:error-info-changed", { detail: info, bubbles: true }));
|
|
1157
|
+
}
|
|
941
1158
|
_setUnsupported(value) {
|
|
942
1159
|
if (this._unsupported === value)
|
|
943
1160
|
return;
|
|
@@ -1410,6 +1627,11 @@ class WcsListen extends HTMLElement {
|
|
|
1410
1627
|
get error() {
|
|
1411
1628
|
return this._core.error;
|
|
1412
1629
|
}
|
|
1630
|
+
// Additive Phase 6 taxonomy output (event wcs-listen:error-info-changed),
|
|
1631
|
+
// delegated from the Core; declared via the inherited ListenCore.wcBindable.
|
|
1632
|
+
get errorInfo() {
|
|
1633
|
+
return this._core.errorInfo;
|
|
1634
|
+
}
|
|
1413
1635
|
get unsupported() {
|
|
1414
1636
|
return this._core.unsupported;
|
|
1415
1637
|
}
|
|
@@ -1489,5 +1711,5 @@ function bootstrapSpeech(userConfig) {
|
|
|
1489
1711
|
registerComponents();
|
|
1490
1712
|
}
|
|
1491
1713
|
|
|
1492
|
-
export { ListenCore, SpeakCore, WcsListen, WcsSpeak, bootstrapSpeech, getConfig };
|
|
1714
|
+
export { ListenCore, SpeakCore, WCS_LISTEN_ERROR_CODE, WCS_SPEAK_ERROR_CODE, WcsListen, WcsSpeak, bootstrapSpeech, getConfig };
|
|
1493
1715
|
//# sourceMappingURL=index.esm.js.map
|