@wcstack/speech 1.13.1
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 +186 -0
- package/README.md +187 -0
- package/dist/auto.js +3 -0
- package/dist/auto.min.js +1 -0
- package/dist/index.d.ts +493 -0
- package/dist/index.esm.js +1313 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/package.json +74 -0
package/README.ja.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# @wcstack/speech
|
|
2
|
+
|
|
3
|
+
`@wcstack/speech` は wcstack エコシステム向けの、ヘッドレスな Web Speech コンポーネント2点セットです。
|
|
4
|
+
|
|
5
|
+
これらは視覚的な UI ウィジェットではありません。`@wcstack/fetch` がネットワークリクエストを、`@wcstack/geolocation` が現在地をリアクティブな状態に変えるのと同じように、ブラウザの Web Speech API を**リアクティブな状態に変える非同期プリミティブノード**です。
|
|
6
|
+
|
|
7
|
+
同一プロトコルの両半身となる2つのタグを提供します:
|
|
8
|
+
|
|
9
|
+
| タグ | API | 向き | プロトコル上の役割 |
|
|
10
|
+
|---|---|---|---|
|
|
11
|
+
| **`<wcs-speak>`** | SpeechSynthesis(TTS) | state → 音声 | command-token(state が発話を駆動) |
|
|
12
|
+
| **`<wcs-listen>`** | SpeechRecognition(STT) | 音声 → state | event-token(認識結果が state へ流れる) |
|
|
13
|
+
|
|
14
|
+
両者が1つのパッケージに同居していること自体が要点です。`<wcs-speak>` は **command 駆動の出力**、`<wcs-listen>` は **event 駆動の入力**のショーケース。両者を繋げば speak ⇄ listen のループになります。
|
|
15
|
+
|
|
16
|
+
いずれも [CSBC](https://github.com/csbc-dev/arch/blob/main/README.md)(Core / Shell / Binding Contract)アーキテクチャに従います:
|
|
17
|
+
|
|
18
|
+
- **Core**(`SpeakCore` / `ListenCore`)はネイティブ API のラップ・データ正規化・ライフサイクル/permission 管理を担い、決して throw しません(失敗は `error` で表面化)。
|
|
19
|
+
- **Shell**(`<wcs-speak>` / `<wcs-listen>`)はそれを DOM 属性・ライフサイクル・宣言的コマンドに接続します。
|
|
20
|
+
- **Binding Contract**(`static wcBindable`)が観測可能な `properties`・書き込み可能な `inputs`・呼び出し可能な `commands` を宣言します。
|
|
21
|
+
|
|
22
|
+
## インストール
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @wcstack/speech
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
ビルドレス(CDN・両タグ登録):
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script type="module" src="https://esm.run/@wcstack/speech/auto"></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## `<wcs-speak>` — 音声合成
|
|
37
|
+
|
|
38
|
+
### 発話の2つの方法
|
|
39
|
+
|
|
40
|
+
`<wcs-speak>` は同じ「発話」という動作を、**いつ発火するか**が異なる2つのサーフェスで提供します:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<!-- 1. reactive: status が変わるたびに発話(同値は再発話しない) -->
|
|
44
|
+
<wcs-speak data-wcs="say: status"></wcs-speak>
|
|
45
|
+
|
|
46
|
+
<!-- 2. imperative: command token 経由で、同じ文でも都度発話 -->
|
|
47
|
+
<wcs-speak data-wcs="command.speak: $command.announce"></wcs-speak>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
export default {
|
|
52
|
+
$commandTokens: ["announce"],
|
|
53
|
+
status: "準備完了。",
|
|
54
|
+
onClick() {
|
|
55
|
+
this.$command.announce.emit("もう一度クリックされました。"); // imperative — 同値でも発話
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
| サーフェス | 発火条件 | 同値で再発話 | 用途 |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `say`(reactive input) | 束縛値が**変化**したとき | しない(ガード) | ステータス・a11y アナウンス |
|
|
63
|
+
| `speak`(imperative command) | command が**起動**されたとき | する | 「クリックで読む」「もう一度読む」 |
|
|
64
|
+
|
|
65
|
+
> **ヒント:** `<input>` の value など高頻度ソースに束縛するときは `\|debounce` を挟まないと1キーストロークごとに発話します。`manual` 属性で `say` を完全にミュートできます(認識中の発話ミュート=echo 回避のフックにもなります)。
|
|
66
|
+
|
|
67
|
+
### 単語境界ハイライト
|
|
68
|
+
|
|
69
|
+
`charIndex` / `spokenWord` は読み上げ中の単語に応じて更新されます。束縛すれば「いま読んでいる単語」をハイライトできます(カラオケ風)。
|
|
70
|
+
|
|
71
|
+
### 属性 / Inputs
|
|
72
|
+
|
|
73
|
+
| 属性 | Input | 型 | 既定 | 意味 |
|
|
74
|
+
|---|---|---|---|---|
|
|
75
|
+
| — | `say` | string | — | reactive: 新しい値を書くと発話 |
|
|
76
|
+
| `rate` | `rate` | number | `1` | 速度(0.1–10) |
|
|
77
|
+
| `pitch` | `pitch` | number | `1` | ピッチ(0–2) |
|
|
78
|
+
| `volume` | `volume` | number | `1` | 音量(0–1) |
|
|
79
|
+
| `voice` | `voice` | string | — | `name` で voice 選択 |
|
|
80
|
+
| `lang` | `lang` | string | — | BCP-47 言語タグ |
|
|
81
|
+
| `manual` | `manual` | boolean | `false` | `say` パスをミュート |
|
|
82
|
+
|
|
83
|
+
### 観測プロパティ(出力)
|
|
84
|
+
|
|
85
|
+
| プロパティ | 型 | 意味 |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| `voices` | `SpeechVoiceInfo[]` | 利用可能な voice(非同期で確定) |
|
|
88
|
+
| `speaking` | boolean | 発話中 |
|
|
89
|
+
| `paused` | boolean | 一時停止中 |
|
|
90
|
+
| `pending` | boolean | キューに発話あり |
|
|
91
|
+
| `charIndex` | number \| null | 読み上げ中の単語の位置 |
|
|
92
|
+
| `spokenWord` | string \| null | 読み上げ中の単語 |
|
|
93
|
+
| `error` | `WcsSpeakErrorDetail` \| null | 直近の失敗 |
|
|
94
|
+
| `unsupported` | boolean | SpeechSynthesis 非対応 |
|
|
95
|
+
|
|
96
|
+
### コマンド
|
|
97
|
+
|
|
98
|
+
| コマンド | 意味 |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `speak(text)` | 発話をキュー(現在の `rate`/`pitch`/… 属性を使用) |
|
|
101
|
+
| `cancel()` | キューをクリアして停止 |
|
|
102
|
+
| `pause()` / `resume()` | 一時停止 / 再開 |
|
|
103
|
+
|
|
104
|
+
### DOM トリガ(任意)
|
|
105
|
+
|
|
106
|
+
`autoTrigger` 有効時(既定)、`data-speaktarget="<id>"` を持つ要素のクリックで、その `data-speaktext`(無ければ textContent)を `<wcs-speak id="<id>">` で発話します。
|
|
107
|
+
|
|
108
|
+
```html
|
|
109
|
+
<wcs-speak id="tts"></wcs-speak>
|
|
110
|
+
<button data-speaktarget="tts" data-speaktext="こんにちは!">読み上げ</button>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## `<wcs-listen>` — 音声認識
|
|
116
|
+
|
|
117
|
+
```html
|
|
118
|
+
<!-- 接続時に自動開始し、transcript を state に束縛 -->
|
|
119
|
+
<wcs-listen lang="ja-JP" interim data-wcs="finalTranscript: transcript; interimTranscript: draft"></wcs-listen>
|
|
120
|
+
|
|
121
|
+
<!-- manual・continuous・command 駆動 -->
|
|
122
|
+
<wcs-listen manual continuous max-restarts="5"
|
|
123
|
+
data-wcs="command.start: $command.listen; finalTranscript: transcript; listening: isListening"></wcs-listen>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`<wcs-geo>` と同様に二相を持ちます: **一発**認識(既定)と、**連続**セッション(`continuous` 属性)。ブラウザは無音でセッションを終了しますが、自動再開は **`max-restarts` でのオプトイン**です — `continuous` **単独**(既定 `max-restarts="0"`)では無音で再開**しません**。`max-restarts="5"` で最大5回の無音をまたぎます。この上限は意図的です(無制限再開は無限ループ/クォータ枯渇のリスク)。
|
|
127
|
+
|
|
128
|
+
> **マイクの自動起動。** `manual` を付けないと `<wcs-listen>` は接続時に `start()` を呼びます — タグを DOM に置くだけで認識が始まります(permission プロンプト→継続キャプチャ)。**明示的な `start()` / DOM トリガ / `trigger` 書き込みを要求したい場合は `manual` を付けてください。** `<wcs-geo>` の `manual` 慣習に倣っていますが、マイクキャプチャはよりプライバシー感度が高い点に注意。
|
|
129
|
+
|
|
130
|
+
### 属性 / Inputs
|
|
131
|
+
|
|
132
|
+
| 属性 | Input | 型 | 既定 | 意味 |
|
|
133
|
+
|---|---|---|---|---|
|
|
134
|
+
| `lang` | `lang` | string | — | BCP-47 言語タグ |
|
|
135
|
+
| `continuous` | `continuous` | boolean | `false` | セッション継続+end で自動再開 |
|
|
136
|
+
| `interim` | `interim` | boolean | `false` | 途中経過の interim を出す |
|
|
137
|
+
| `max-restarts` | `maxRestarts` | number | `0` | 自動再開の上限(continuous) |
|
|
138
|
+
| `manual` | `manual` | boolean | `false` | 接続時に自動開始しない |
|
|
139
|
+
| — | `trigger` | boolean | — | モーメンタリ: `false`→`true` で開始 |
|
|
140
|
+
|
|
141
|
+
### 観測プロパティ(出力)
|
|
142
|
+
|
|
143
|
+
| プロパティ | 型 | 意味 |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `interimTranscript` | string | 未確定の途中テキスト |
|
|
146
|
+
| `finalTranscript` | string | 蓄積された確定テキスト |
|
|
147
|
+
| `result` | `WcsListenResultDetail` \| null | 直近結果(transcript / confidence / alternatives / isFinal) |
|
|
148
|
+
| `listening` | boolean | セッション中 |
|
|
149
|
+
| `permission` | `"prompt"\|"granted"\|"denied"\|"unsupported"` | マイク permission |
|
|
150
|
+
| `error` | `WcsListenErrorDetail` \| null | 直近の失敗 |
|
|
151
|
+
| `unsupported` | boolean | SpeechRecognition 非対応 |
|
|
152
|
+
|
|
153
|
+
### コマンド
|
|
154
|
+
|
|
155
|
+
| コマンド | 意味 |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `start()` | セッション開始(transcript をリセット) |
|
|
158
|
+
| `stop()` | 穏やかに停止(自動再開しない) |
|
|
159
|
+
| `abort()` | 即時停止 |
|
|
160
|
+
|
|
161
|
+
### DOM トリガ(任意)
|
|
162
|
+
|
|
163
|
+
`data-listentarget="<id>"` を持つ要素のクリックで、対象 `<wcs-listen>` の `start()` / `stop()` をトグルします。
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## 注意・制限
|
|
168
|
+
|
|
169
|
+
- **セキュアコンテキスト必須。** 両 API とも HTTPS か `localhost` が必要。`<wcs-listen>` はさらにマイク permission が必要です。
|
|
170
|
+
- **ブラウザ対応。** SpeechSynthesis は広く対応。SpeechRecognition は Chrome 系のみ(`webkitSpeechRecognition`)で、それ以外では `<wcs-listen>` は `unsupported` を報告します。
|
|
171
|
+
- **SpeechSynthesis はグローバルシングルトン。** `<wcs-speak>` は切断時に `cancel()` しません(他インスタンスまで止まるため)。音声を止めるには明示的に `cancel()` を。切断された要素は追跡を止めますが、発話中の utterance は自然に完了します。
|
|
172
|
+
- **echo ループ。** `<wcs-listen>` → state → `<wcs-speak>` を繋ぐときは、認識中は発話をミュート(例: `manual` を束縛)して合成音声が再認識されないように。echo の例を参照。
|
|
173
|
+
|
|
174
|
+
## ヘッドレス利用(`SpeakCore` / `ListenCore`)
|
|
175
|
+
|
|
176
|
+
どちらの Core もフレームワーク非依存で、カスタム要素なしに `@wc-bindable/core` の `bind()` 経由で利用できます:
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
import { SpeakCore } from "@wcstack/speech";
|
|
180
|
+
const core = new SpeakCore();
|
|
181
|
+
core.speak("こんにちは。");
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## ライセンス
|
|
185
|
+
|
|
186
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# @wcstack/speech
|
|
2
|
+
|
|
3
|
+
`@wcstack/speech` is a headless Web Speech component pair for the wcstack ecosystem.
|
|
4
|
+
|
|
5
|
+
These are not visual UI widgets. They are **async primitive nodes** that turn the browser's Web Speech APIs into reactive state — the same way `@wcstack/fetch` turns a network request into reactive state and `@wcstack/geolocation` turns the device's location into reactive state.
|
|
6
|
+
|
|
7
|
+
The package ships two complementary tags, the two halves of the same protocol:
|
|
8
|
+
|
|
9
|
+
| Tag | API | Direction | Protocol role |
|
|
10
|
+
|---|---|---|---|
|
|
11
|
+
| **`<wcs-speak>`** | SpeechSynthesis (TTS) | state → speech | command-token (state drives speech) |
|
|
12
|
+
| **`<wcs-listen>`** | SpeechRecognition (STT) | speech → state | event-token (recognition flows to state) |
|
|
13
|
+
|
|
14
|
+
Their coexistence in one package is the point: `<wcs-speak>` is a perfect showcase of **command-driven output**, `<wcs-listen>` of **event-driven input**. Wire them together for a speak ⇄ listen loop.
|
|
15
|
+
|
|
16
|
+
Both follow the [CSBC](https://github.com/csbc-dev/arch/blob/main/README.md) (Core / Shell / Binding Contract) architecture:
|
|
17
|
+
|
|
18
|
+
- **Core** (`SpeakCore` / `ListenCore`) wraps the native API, normalizes data, manages lifecycle/permission, and never throws (failures surface through `error`).
|
|
19
|
+
- **Shell** (`<wcs-speak>` / `<wcs-listen>`) connects that state to DOM attributes, lifecycle, and declarative commands.
|
|
20
|
+
- **Binding Contract** (`static wcBindable`) declares observable `properties`, writable `inputs`, and callable `commands`.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @wcstack/speech
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or buildless via CDN (registers both tags):
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script type="module" src="https://esm.run/@wcstack/speech/auto"></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## `<wcs-speak>` — text to speech
|
|
37
|
+
|
|
38
|
+
### Two ways to speak
|
|
39
|
+
|
|
40
|
+
`<wcs-speak>` exposes the same action through two surfaces that differ in **when they fire**:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<!-- 1. Reactive: speaks whenever `status` changes (same value is NOT re-spoken). -->
|
|
44
|
+
<wcs-speak data-wcs="say: status"></wcs-speak>
|
|
45
|
+
|
|
46
|
+
<!-- 2. Imperative: speaks on demand, even the same text again, via the command token. -->
|
|
47
|
+
<wcs-speak data-wcs="command.speak: $command.announce"></wcs-speak>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
// state
|
|
52
|
+
export default {
|
|
53
|
+
$commandTokens: ["announce"],
|
|
54
|
+
status: "Ready.",
|
|
55
|
+
onClick() {
|
|
56
|
+
this.$command.announce.emit("Button clicked again."); // imperative — re-speaks same text
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
| Surface | Fires when | Same value re-speaks? | Use for |
|
|
62
|
+
|---|---|---|---|
|
|
63
|
+
| `say` (reactive input) | the bound value **changes** | no (guarded) | status / a11y announcements |
|
|
64
|
+
| `speak` (imperative command) | the command is **invoked** | yes | "speak this on click", "say it again" |
|
|
65
|
+
|
|
66
|
+
> **Tip:** wire `say` through a `\|debounce` filter when binding to a rapidly-changing source (e.g. an `<input>` value), or it will speak on every keystroke. Set the `manual` attribute to mute the `say` path entirely (also the hook for muting speech while listening — see the echo example).
|
|
67
|
+
|
|
68
|
+
### Word-boundary highlighting
|
|
69
|
+
|
|
70
|
+
`charIndex` / `spokenWord` update as each word is spoken — bind them to highlight the currently-spoken word (karaoke-style).
|
|
71
|
+
|
|
72
|
+
### Attributes / Inputs
|
|
73
|
+
|
|
74
|
+
| Attribute | Input | Type | Default | Meaning |
|
|
75
|
+
|---|---|---|---|---|
|
|
76
|
+
| — | `say` | string | — | reactive: writing a new value speaks it |
|
|
77
|
+
| `rate` | `rate` | number | `1` | speech rate (0.1–10) |
|
|
78
|
+
| `pitch` | `pitch` | number | `1` | pitch (0–2) |
|
|
79
|
+
| `volume` | `volume` | number | `1` | volume (0–1) |
|
|
80
|
+
| `voice` | `voice` | string | — | voice selected by `name` |
|
|
81
|
+
| `lang` | `lang` | string | — | BCP-47 language tag |
|
|
82
|
+
| `manual` | `manual` | boolean | `false` | mute the `say` path |
|
|
83
|
+
|
|
84
|
+
### Observable Properties (outputs)
|
|
85
|
+
|
|
86
|
+
| Property | Type | Meaning |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `voices` | `SpeechVoiceInfo[]` | available voices (populated asynchronously) |
|
|
89
|
+
| `speaking` | boolean | an utterance is being spoken |
|
|
90
|
+
| `paused` | boolean | speech is paused |
|
|
91
|
+
| `pending` | boolean | utterances are queued |
|
|
92
|
+
| `charIndex` | number \| null | offset of the word being spoken |
|
|
93
|
+
| `spokenWord` | string \| null | the word being spoken |
|
|
94
|
+
| `error` | `WcsSpeakErrorDetail` \| null | last failure |
|
|
95
|
+
| `unsupported` | boolean | SpeechSynthesis is unavailable |
|
|
96
|
+
|
|
97
|
+
### Commands
|
|
98
|
+
|
|
99
|
+
| Command | Meaning |
|
|
100
|
+
|---|---|
|
|
101
|
+
| `speak(text)` | queue an utterance (uses current `rate`/`pitch`/… attributes) |
|
|
102
|
+
| `cancel()` | clear the queue and stop |
|
|
103
|
+
| `pause()` / `resume()` | suspend / resume |
|
|
104
|
+
|
|
105
|
+
### Optional DOM triggering
|
|
106
|
+
|
|
107
|
+
With `autoTrigger` on (default), clicking an element carrying `data-speaktarget="<id>"` speaks its `data-speaktext` (or its text content) through the `<wcs-speak id="<id>">`.
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<wcs-speak id="tts"></wcs-speak>
|
|
111
|
+
<button data-speaktarget="tts" data-speaktext="Hello!">Speak</button>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## `<wcs-listen>` — speech to text
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
<!-- Auto-start on connect; bind the transcript to state -->
|
|
120
|
+
<wcs-listen lang="en-US" interim data-wcs="finalTranscript: transcript; interimTranscript: draft"></wcs-listen>
|
|
121
|
+
|
|
122
|
+
<!-- Manual, continuous, command-driven -->
|
|
123
|
+
<wcs-listen manual continuous max-restarts="5"
|
|
124
|
+
data-wcs="command.start: $command.listen; finalTranscript: transcript; listening: isListening"></wcs-listen>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Like `<wcs-geo>`, it has two phases: a **one-shot** recognition (default) and a **continuous** session (`continuous` attribute). The browser still ends a session on silence; auto-restart bridges that, but is **opt-in via `max-restarts`** — `continuous` *alone* (with the default `max-restarts="0"`) does **not** restart on silence. Set `max-restarts="5"` to bridge up to 5 silences. This bound is deliberate: unbounded restart is an infinite-loop / quota-exhaustion risk.
|
|
128
|
+
|
|
129
|
+
> **Microphone auto-start.** Without `manual`, `<wcs-listen>` calls `start()` on connect — placing the tag in the DOM begins recognition (a permission prompt, then continuous capture). **Add `manual` to require an explicit `start()` / DOM-trigger / `trigger` write instead.** Mirrors `<wcs-geo>`'s `manual` convention, but mind that microphone capture is more privacy-sensitive.
|
|
130
|
+
|
|
131
|
+
### Attributes / Inputs
|
|
132
|
+
|
|
133
|
+
| Attribute | Input | Type | Default | Meaning |
|
|
134
|
+
|---|---|---|---|---|
|
|
135
|
+
| `lang` | `lang` | string | — | BCP-47 language tag |
|
|
136
|
+
| `continuous` | `continuous` | boolean | `false` | keep the session open & auto-restart on end |
|
|
137
|
+
| `interim` | `interim` | boolean | `false` | emit live interim transcripts |
|
|
138
|
+
| `max-restarts` | `maxRestarts` | number | `0` | cap on automatic restarts (continuous) |
|
|
139
|
+
| `manual` | `manual` | boolean | `false` | do not auto-start on connect |
|
|
140
|
+
| — | `trigger` | boolean | — | momentary: `false`→`true` starts a session |
|
|
141
|
+
|
|
142
|
+
### Observable Properties (outputs)
|
|
143
|
+
|
|
144
|
+
| Property | Type | Meaning |
|
|
145
|
+
|---|---|---|
|
|
146
|
+
| `interimTranscript` | string | live, not-yet-final text |
|
|
147
|
+
| `finalTranscript` | string | accumulated final text |
|
|
148
|
+
| `result` | `WcsListenResultDetail` \| null | latest result (transcript / confidence / alternatives / isFinal) |
|
|
149
|
+
| `listening` | boolean | a session is active |
|
|
150
|
+
| `permission` | `"prompt"\|"granted"\|"denied"\|"unsupported"` | microphone permission |
|
|
151
|
+
| `error` | `WcsListenErrorDetail` \| null | last failure |
|
|
152
|
+
| `unsupported` | boolean | SpeechRecognition is unavailable |
|
|
153
|
+
|
|
154
|
+
### Commands
|
|
155
|
+
|
|
156
|
+
| Command | Meaning |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `start()` | begin a session (resets transcripts) |
|
|
159
|
+
| `stop()` | stop gracefully (no auto-restart) |
|
|
160
|
+
| `abort()` | stop immediately |
|
|
161
|
+
|
|
162
|
+
### Optional DOM triggering
|
|
163
|
+
|
|
164
|
+
Clicking an element with `data-listentarget="<id>"` toggles `start()` / `stop()` on the target `<wcs-listen>`.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Notes & limitations
|
|
169
|
+
|
|
170
|
+
- **Secure context required.** Both APIs need HTTPS or `localhost`; `<wcs-listen>` additionally needs microphone permission.
|
|
171
|
+
- **Browser support.** SpeechSynthesis is broad; SpeechRecognition is Chrome-only (vendor-prefixed `webkitSpeechRecognition`) — `<wcs-listen>` reports `unsupported` elsewhere.
|
|
172
|
+
- **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.
|
|
173
|
+
- **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.
|
|
174
|
+
|
|
175
|
+
## Headless usage (`SpeakCore` / `ListenCore`)
|
|
176
|
+
|
|
177
|
+
Both Cores are framework-agnostic and usable without the custom elements, via `bind()` from `@wc-bindable/core`:
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
import { SpeakCore } from "@wcstack/speech";
|
|
181
|
+
const core = new SpeakCore();
|
|
182
|
+
core.speak("Hello, world.");
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT
|
package/dist/auto.js
ADDED
package/dist/auto.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{bootstrapSpeech}from"./index.esm.min.js";bootstrapSpeech();
|