ssml-builder-js 2.1.0 → 2.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/README.md +77 -8
- package/dist/chunk-2XJER2BG.mjs +3486 -0
- package/dist/chunk-2XJER2BG.mjs.map +1 -0
- package/dist/elements.d.mts +72 -0
- package/dist/elements.d.ts +72 -0
- package/dist/elements.js +4577 -0
- package/dist/elements.js.map +1 -0
- package/dist/elements.mjs +1234 -0
- package/dist/elements.mjs.map +1 -0
- package/dist/react.d.mts +5 -0
- package/dist/react.d.ts +5 -0
- package/dist/react.js +558 -236
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +212 -3288
- package/dist/react.mjs.map +1 -1
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
Azure Speech Service で利用できる SSML を、TypeScript のデータ構造から生成・解析し、React の GUI で編集するための npm ワークスペースモノレポです。公開成果物は `ssml-builder-js` という単一の npm パッケージです。
|
|
9
9
|
|
|
10
|
-
SSML の XML エスケープや Azure Speech 拡張要素に対応したコアライブラリ、Monaco Editor を利用した React
|
|
10
|
+
SSML の XML エスケープや Azure Speech 拡張要素に対応したコアライブラリ、Monaco Editor を利用した React コンポーネント、フレームワーク非依存の Web Component、Azure Text-to-Speech API クライアントをサブパスから提供します。
|
|
11
11
|
|
|
12
12
|
## パッケージ構成
|
|
13
13
|
|
|
@@ -16,6 +16,7 @@ SSML の XML エスケープや Azure Speech 拡張要素に対応したコア
|
|
|
16
16
|
| `ssml-builder-js` | コア機能と Azure Text-to-Speech クライアント |
|
|
17
17
|
| `ssml-builder-js/core` | SSML の型定義、ドキュメントの生成(`buildSsml`)、XML からの解析(`parseSsml`)、構文検証(`validateSsml`) |
|
|
18
18
|
| `ssml-builder-js/react` | ツールバーと本文の表示エリアを備えた `SsmlEditor` コンポーネント |
|
|
19
|
+
| `ssml-builder-js/elements` | React などに依存しない `<ssml-editor>` Web Component |
|
|
19
20
|
|
|
20
21
|
`ssml-builder-js` と `ssml-builder-js/core` は同じコア機能を提供します。React エディタは `ssml-builder-js/react` から読み込み、Azure TTS クライアントは `ssml-builder-js` から読み込みます。
|
|
21
22
|
|
|
@@ -35,6 +36,12 @@ React エディタを使用する場合は、React と Monaco Editor のアダ
|
|
|
35
36
|
npm install ssml-builder-js @monaco-editor/react react react-dom
|
|
36
37
|
```
|
|
37
38
|
|
|
39
|
+
Web Component を使用する場合は、Monaco Editor もインストールします。
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm install ssml-builder-js monaco-editor
|
|
43
|
+
```
|
|
44
|
+
|
|
38
45
|
Azure TTS クライアントも `ssml-builder-js` から利用できます。
|
|
39
46
|
|
|
40
47
|
### リポジトリを開発する場合
|
|
@@ -66,6 +73,14 @@ cp apps/playground/.env.example apps/playground/.env.local
|
|
|
66
73
|
npm run dev --workspace playground
|
|
67
74
|
```
|
|
68
75
|
|
|
76
|
+
Playground の表示言語は `ja`、`en`、`ko`、`zh-Hans`、`fr`、`pt-BR`、`it`、`de`、
|
|
77
|
+
`ru` から選択できます。音声設定では `en-US`、`ja-JP`、`ko`、`zh-Hans`、`fr`、
|
|
78
|
+
`pt-BR`、`it`、`de`、`ru` の各言語について、女性・男性の音声を選択できます。
|
|
79
|
+
Playground の表示言語が日本語以外の場合、埋め込みエディターの UI は英語になります。
|
|
80
|
+
テーマは OS の設定に追従し、ライト・ダークを手動で切り替えて保存できます。現在の
|
|
81
|
+
SSML 全体または選択部分を Azure Speech で合成してブラウザーで再生でき、音声には
|
|
82
|
+
SSML 本文のキャプションが付きます。生成された SSML は画面下部に表示されます。
|
|
83
|
+
|
|
69
84
|
## `ssml-core` の利用方法
|
|
70
85
|
|
|
71
86
|
`SsmlDocument` は `version`、`lang`、`children` を持つオブジェクトです。`children` には文字列、テキストノード、SSML 要素を入れられます。`children` を使う形式が推奨され、旧形式の `content` プロパティも `buildSsml` の入力として利用できます。
|
|
@@ -124,7 +139,7 @@ const parsed = parseSsml(ssml);
|
|
|
124
139
|
|
|
125
140
|
`SsmlEditor` は `SsmlDocument` を受け取り、ツールバーと本文の表示エリアだけを表示するシンプルなコンポーネントです。ツールバーから選択範囲の速度、音量、ピッチなどの設定、元に戻す・やり直す操作ができます。音声の選択と表示はアプリ側で行います。本文の編集には Monaco Editor を使用し、変更時に SSML の構文を検証します。構文エラーはエディター上のマーカーとエラーメッセージで表示されます。XML のタグ名やパラメータへホバーすると SSML の説明を確認できます。テキストを選択すると、選択文字数と試聴を行うフローティングアクションが表示されます。`showDecorations` が有効な場合、`break` と `prosody` のタグに間やピッチ変化を示すインラインバッジが表示され、Monaco のインライン装飾も有効になります。生成された SSML は `onSsmlChange` で受け取り、アプリ側で自由に表示できます。`SsmlEditorRef` を `ref` に渡すと、全体、選択範囲、または現在行の SSML を取得できます。画面表示は日本語(デフォルト)と英語に対応しています。
|
|
126
141
|
|
|
127
|
-
`<mstts:express-as>` の `style` 属性補完と標準の感情メニューは、カーソルまたは選択範囲を囲む最内の `<voice name="...">`
|
|
142
|
+
`<mstts:express-as>` の `style` 属性補完と標準の感情メニューは、カーソルまたは選択範囲を囲む最内の `<voice name="...">` が対応するスタイルだけを表示します。音声名が未指定の場合は全候補を表示し、登録済みでスタイル非対応の音声や未登録の音声では候補がないことを表示します。`emotionStyles` を指定した場合、感情メニューではその値と登録済み音声の対応スタイルの共通部分を使用します。
|
|
128
143
|
|
|
129
144
|
```tsx
|
|
130
145
|
import { useState } from "react";
|
|
@@ -158,7 +173,7 @@ export function App() {
|
|
|
158
173
|
- `document`: 編集対象の `SsmlDocument`
|
|
159
174
|
- `onChange`: 編集後の `SsmlDocument` を受け取るコールバック
|
|
160
175
|
- `onSsmlChange`: 編集後に生成された SSML 文字列を受け取るコールバック
|
|
161
|
-
- `ref`: `SsmlEditorRef` の `getFullSsml()` で全体の SSML、`getSelectedSsml()`
|
|
176
|
+
- `ref`: `SsmlEditorRef` の `getFullSsml()` で全体の SSML、`getSelectedSsml()` で選択範囲(未選択時は内容が空でないカーソル行)の SSML、`getCurrentLineSsml()` で現在行の SSML を取得。選択範囲やカーソル行が空の場合は `null` を返します
|
|
162
177
|
- `onSelectionChange`: 選択テキスト、文字数、選択状態を受け取るコールバック
|
|
163
178
|
- `onPreviewSelection`: フローティングアクションの試聴ボタン押下時に、選択部分の SSML を受け取るコールバック。省略時は試聴ボタンが無効になります。Azure などの音声 API はこのコールバックから呼び出してください
|
|
164
179
|
- `locale`: 画面表示の言語(`"ja"` または `"en"`)。省略時は `"ja"`。ホバーヘルプを含む UI の翻訳にも使用されます
|
|
@@ -187,6 +202,25 @@ export function App() {
|
|
|
187
202
|
|
|
188
203
|
「説明」ボタンを押すと、各コントロール、ボタン、設定の説明を表示できます。ボタンの設定はアコーディオンで表示され、デフォルトでは閉じています。アコーディオンのタイトルにはボタンの説明と生成される XML のタグ名が表示され、各設定の意味を確認できます。「全てクリア」ボタンは `voice` 要素を保持したまま、それ以外の XML 要素を削除して本文を残します。ドキュメントの `version`、`lang`、その他の属性も保持されます。
|
|
189
204
|
|
|
205
|
+
## `ssml-editor-elements` の利用方法
|
|
206
|
+
|
|
207
|
+
`ssml-builder-js/elements` は、React などに依存しない `<ssml-editor>` Web Component を登録します。`monaco-editor` を別途インストールし、`value`、`theme`、`readonly` 属性または同名プロパティを使用できます。React エディターと同じ SSML ツールバーと説明表示も利用でき、`locale`、`show-toolbar`、`show-toolbar-labels`、`show-decorations` で表示を調整できます。編集時には `{ value }` を `detail` に持つ `change` イベントが発生します。
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import "ssml-builder-js/elements";
|
|
211
|
+
import type { SsmlEditorElement } from "ssml-builder-js/elements";
|
|
212
|
+
|
|
213
|
+
const editor = document.querySelector("ssml-editor") as SsmlEditorElement | null;
|
|
214
|
+
if (editor) {
|
|
215
|
+
editor.value = '<speak version="1.0">編集する本文</speak>';
|
|
216
|
+
editor.theme = "vs-dark";
|
|
217
|
+
editor.locale = "ja";
|
|
218
|
+
editor.addEventListener("change", (event) => {
|
|
219
|
+
console.log((event as CustomEvent<{ value: string }>).detail.value);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
190
224
|
## `azure-tts-client` の利用方法
|
|
191
225
|
|
|
192
226
|
`AzureTtsClient` に Azure Speech のサブスクリプションキーとリージョンを渡し、`synthesize` に SSML を渡します。戻り値は音声データの `ArrayBuffer` です。
|
|
@@ -219,7 +253,7 @@ const audio = await synthesizeSpeech(ssml, {
|
|
|
219
253
|
内部では Microsoft Cognitive Services Speech SDK の `SpeechSynthesizer` を使用します。`AzureTtsClient` の `endpoint` を省略すると `https://{region}.tts.speech.microsoft.com/cognitiveservices/v1` が使用されます。上の Playground の例では `.env.example` に合わせて WebSocket エンドポイントを明示しています。独自エンドポイントに `{region}` を含めた場合は、設定したリージョンに置き換えられます。
|
|
220
254
|
`outputFormat` には Speech SDK がサポートする出力形式を指定できます。省略時は `audio-16khz-128kbitrate-mono-mp3` が使用されます。
|
|
221
255
|
|
|
222
|
-
Speech SDK の合成エラーでは `AzureTtsSdkError`(`AzureTtsError` のサブクラス)がスローされ、`errorDetails`
|
|
256
|
+
Speech SDK の合成エラーでは `AzureTtsSdkError`(`AzureTtsError` のサブクラス)がスローされ、`errorDetails` から SDK のエラー詳細を確認できます。SDK が HTTP ステータスやリクエスト ID を公開しないため、SDK 経由のエラーでは `status` は `0`、`statusText` は `"Speech SDK"`、`requestId` は `null` です。Playground のサーバー側ログにもこれらの情報とリージョン、SSML の文字数が出力されます。ログに出力するエラー詳細は 4,096 文字までに制限されます。サブスクリプションキーや SSML 本文自体はログに出力されません。
|
|
223
257
|
|
|
224
258
|
サブスクリプションキーはリクエストヘッダーに含まれるため、ソースコードへハードコードしたりログへ出力したりしないでください。ブラウザから直接呼び出す場合はキーが利用者へ公開されるため、通常はサーバー側で Azure TTS を呼び出す構成にします。
|
|
225
259
|
|
|
@@ -262,7 +296,7 @@ npm test
|
|
|
262
296
|
|
|
263
297
|
SSML-Builder is an npm workspace monorepo for generating and parsing SSML supported by Azure Speech Service from TypeScript data structures and editing it in a React GUI. Its published output is a single npm package, `ssml-builder-js`.
|
|
264
298
|
|
|
265
|
-
It provides a core library with XML escaping and Azure Speech extension support, a React component based on Monaco Editor, and an Azure Text-to-Speech API client through package subpaths.
|
|
299
|
+
It provides a core library with XML escaping and Azure Speech extension support, a React component based on Monaco Editor, a framework-independent Web Component, and an Azure Text-to-Speech API client through package subpaths.
|
|
266
300
|
|
|
267
301
|
## Package structure
|
|
268
302
|
|
|
@@ -271,6 +305,7 @@ It provides a core library with XML escaping and Azure Speech extension support,
|
|
|
271
305
|
| `ssml-builder-js` | Core functionality and the Azure Text-to-Speech client |
|
|
272
306
|
| `ssml-builder-js/core` | SSML type definitions, document generation (`buildSsml`), XML parsing (`parseSsml`), and syntax validation (`validateSsml`) |
|
|
273
307
|
| `ssml-builder-js/react` | The `SsmlEditor` component with a toolbar and text display area |
|
|
308
|
+
| `ssml-builder-js/elements` | The framework-independent `<ssml-editor>` Web Component |
|
|
274
309
|
|
|
275
310
|
`ssml-builder-js` and `ssml-builder-js/core` provide the same core functionality. Import the React editor from `ssml-builder-js/react`; the Azure TTS client is available from `ssml-builder-js`.
|
|
276
311
|
|
|
@@ -290,6 +325,12 @@ To use the React editor, also install React and the Monaco Editor adapter:
|
|
|
290
325
|
npm install ssml-builder-js @monaco-editor/react react react-dom
|
|
291
326
|
```
|
|
292
327
|
|
|
328
|
+
To use the Web Component, also install Monaco Editor:
|
|
329
|
+
|
|
330
|
+
```sh
|
|
331
|
+
npm install ssml-builder-js monaco-editor
|
|
332
|
+
```
|
|
333
|
+
|
|
293
334
|
The Azure TTS client is also available from `ssml-builder-js`.
|
|
294
335
|
|
|
295
336
|
### Developing this repository
|
|
@@ -320,6 +361,15 @@ cp apps/playground/.env.example apps/playground/.env.local
|
|
|
320
361
|
npm run dev --workspace playground
|
|
321
362
|
```
|
|
322
363
|
|
|
364
|
+
The playground UI can be displayed in `ja`, `en`, `ko`, `zh-Hans`, `fr`, `pt-BR`, `it`,
|
|
365
|
+
`de`, or `ru`. Speech settings provide female and male voices for `en-US`, `ja-JP`,
|
|
366
|
+
`ko`, `zh-Hans`, `fr`, `pt-BR`, `it`, `de`, and `ru`. The embedded editor supports
|
|
367
|
+
Japanese and English UI, so non-Japanese playground locales use the English editor UI.
|
|
368
|
+
The theme follows the operating system preference until a light or dark mode is selected
|
|
369
|
+
manually, and the manual choice is stored in the browser. You can synthesize the full
|
|
370
|
+
SSML document or the selected text and play it in the browser with an SSML caption track;
|
|
371
|
+
the generated SSML is shown below the editor.
|
|
372
|
+
|
|
323
373
|
## Using `ssml-core`
|
|
324
374
|
|
|
325
375
|
`SsmlDocument` is an object with `version`, `lang`, and `children` properties. `children` can contain strings, text nodes, and SSML elements. The `children` form is recommended; the legacy `content` property is also accepted as input by `buildSsml`.
|
|
@@ -378,7 +428,7 @@ Typed representations are available for elements such as `voice`, `prosody`, `br
|
|
|
378
428
|
|
|
379
429
|
`SsmlEditor` accepts an `SsmlDocument` and renders only a toolbar and text display area. The toolbar applies rate, volume, and pitch settings to the selection and provides undo and redo actions. The application is responsible for selecting and displaying the voice. Monaco Editor is used for text editing, and SSML syntax is validated whenever the text changes. Syntax errors are shown with editor markers and an error message. Hovering over XML tag names or parameters shows SSML descriptions. Selecting text displays a floating action bar with the character count and preview action. When `showDecorations` is enabled, inline badges for pause and pitch changes are rendered next to `break` and `prosody` tags, and Monaco inline decorations are enabled. Generated SSML is provided through `onSsmlChange` so the application can display it wherever it needs. Pass an `SsmlEditorRef` through `ref` to retrieve full, selected, or current-line SSML, and use `onSelectionChange` to observe selection text and state. The UI supports Japanese (the default) and English.
|
|
380
430
|
|
|
381
|
-
Completion for the `<mstts:express-as>` `style` attribute and the built-in Emotion menu only show styles supported by the innermost `<voice name="...">` around the cursor or selection.
|
|
431
|
+
Completion for the `<mstts:express-as>` `style` attribute and the built-in Emotion menu only show styles supported by the innermost `<voice name="...">` around the cursor or selection. When no voice name is available, all candidates are shown; a registered voice without supported styles or an explicitly unregistered voice displays an empty-state message. When `emotionStyles` is supplied, the Emotion menu uses its intersection with the registered voice's supported styles.
|
|
382
432
|
|
|
383
433
|
```tsx
|
|
384
434
|
import { useState } from "react";
|
|
@@ -412,7 +462,7 @@ export function App() {
|
|
|
412
462
|
- `document`: The `SsmlDocument` being edited
|
|
413
463
|
- `onChange`: A callback that receives the edited `SsmlDocument`
|
|
414
464
|
- `onSsmlChange`: A callback that receives the generated SSML string
|
|
415
|
-
- `ref`: An `SsmlEditorRef`; `getFullSsml()` returns the full SSML, `getSelectedSsml()` returns the selected text (or the cursor line when
|
|
465
|
+
- `ref`: An `SsmlEditorRef`; `getFullSsml()` returns the full SSML, `getSelectedSsml()` returns the selected text (or the cursor line when it contains content), and `getCurrentLineSsml()` returns the current cursor line. The selection and line methods return `null` when their target is empty
|
|
416
466
|
- `onSelectionChange`: A callback that receives selected text, its character count, and whether a selection exists
|
|
417
467
|
- `onPreviewSelection`: A callback that receives the selected partial SSML when the floating preview action is pressed. The preview action is disabled when this callback is omitted; call an audio API such as Azure from the callback
|
|
418
468
|
- `locale`: The UI language (`"ja"` or `"en"`); defaults to `"ja"` and also controls hover-help translations
|
|
@@ -441,6 +491,25 @@ The built-in insertion menus are `break`, `emphasis`, `rate`, `pitch`, `volume`,
|
|
|
441
491
|
|
|
442
492
|
Click the **Description** button to see descriptions of each control, button, and setting. Button settings are shown in accordions that are closed by default, with the button description and generated XML tag name as the accordion title and the meaning of each setting inside. The **Clear all** button preserves `voice` elements, removes the other XML elements, and leaves the text in place. The document's `version`, `lang`, and other attributes are also preserved.
|
|
443
493
|
|
|
494
|
+
## Using `ssml-editor-elements`
|
|
495
|
+
|
|
496
|
+
`ssml-builder-js/elements` registers a framework-independent `<ssml-editor>` Web Component without React. Install `monaco-editor` separately, then use the `value`, `theme`, and `readonly` attributes or properties. The component includes the same SSML toolbar and help display as the React editor; use `locale`, `show-toolbar`, `show-toolbar-labels`, and `show-decorations` to customize it. Editing dispatches a `change` event whose `detail` is `{ value: string }`.
|
|
497
|
+
|
|
498
|
+
```ts
|
|
499
|
+
import "ssml-builder-js/elements";
|
|
500
|
+
import type { SsmlEditorElement } from "ssml-builder-js/elements";
|
|
501
|
+
|
|
502
|
+
const editor = document.querySelector("ssml-editor") as SsmlEditorElement | null;
|
|
503
|
+
if (editor) {
|
|
504
|
+
editor.value = '<speak version="1.0">Text to edit</speak>';
|
|
505
|
+
editor.theme = "vs-dark";
|
|
506
|
+
editor.locale = "en";
|
|
507
|
+
editor.addEventListener("change", (event) => {
|
|
508
|
+
console.log((event as CustomEvent<{ value: string }>).detail.value);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
444
513
|
## Using `azure-tts-client`
|
|
445
514
|
|
|
446
515
|
Pass an Azure Speech subscription key and region to `AzureTtsClient`, then pass SSML to `synthesize`. The return value is an `ArrayBuffer` containing audio data.
|
|
@@ -473,7 +542,7 @@ const audio = await synthesizeSpeech(ssml, {
|
|
|
473
542
|
Internally, the client uses the Microsoft Cognitive Services Speech SDK's `SpeechSynthesizer`. If `endpoint` is omitted from `AzureTtsClient`, `https://{region}.tts.speech.microsoft.com/cognitiveservices/v1` is used. The Playground example explicitly uses the WebSocket endpoint from `.env.example`. If a custom endpoint contains `{region}`, it is replaced with the configured region.
|
|
474
543
|
Set `outputFormat` to a format supported by the Speech SDK. If omitted, `audio-16khz-128kbitrate-mono-mp3` is used.
|
|
475
544
|
|
|
476
|
-
Speech SDK synthesis errors throw `AzureTtsSdkError` (a subclass of `AzureTtsError`); its `errorDetails`
|
|
545
|
+
Speech SDK synthesis errors throw `AzureTtsSdkError` (a subclass of `AzureTtsError`); its `errorDetails` field contains the SDK error details. Because the SDK does not expose HTTP status or request IDs, SDK errors use `0` for `status`, `"Speech SDK"` for `statusText`, and `null` for `requestId`. The playground's server-side logs include these fields along with the region and SSML character count. Logged error details are limited to 4,096 characters. The subscription key and SSML content itself are not written to logs.
|
|
477
546
|
|
|
478
547
|
The subscription key is sent in a request header, so do not hard-code it in source code or write it to logs. Calling Azure TTS directly from a browser exposes the key to users; a server-side Azure TTS integration is normally recommended.
|
|
479
548
|
|