ssml-builder-js 2.11.0 → 2.13.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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { AudioElement, AzureDiagnosticCode, AzureLanguageNormalizationOptions, AzureSsmlValidationOptions, AzureValidationOptions, AzureVoiceCatalogMetadata, AzureVoiceDefinition, AzureVoiceMetadata, BookmarkElement, BreakElement, BuildPartialSsmlOptions, CustomElement, EmphasisElement, ExpressAsElement, ExtractSsmlTranslatableTextOptions, FromPlainTextToSsmlOptions, LangElement, LexiconElement, MapSsmlTextNodesOptions, MarkElement, MsttsAudioDurationElement, MsttsEmbeddingElement, MsttsSilenceElement, MsttsTtsEmbeddingElement, MsttsVisemeElement, MsttsVoiceConversionElement, NamedElement, ParagraphElement, PhonemeElement, ProsodyElement, SayAsElement, SentenceElement, SsmlAttributeValue, SsmlAttributes, SsmlBackgroundAudioNode, SsmlBreakElement, SsmlDiagnostic, SsmlDiagnosticSeverity, SsmlDiagnosticSource, SsmlDialogNode, SsmlDocument, SsmlElement, SsmlElementBase, SsmlEmbeddingNode, SsmlExpressAsElement, SsmlNode, SsmlPartialContext, SsmlPartialProsody, SsmlPartialVoice, SsmlPhonemeElement, SsmlProsodyElement, SsmlSayAsElement, SsmlStructureIntegrityResult, SsmlStructureMismatch, SsmlText, SsmlTextNodeContext, SsmlTtsEmbeddingNode, SsmlTurnNode, SsmlValidationError, SsmlVoiceConversionNode, SsmlVoiceElement, SubElement, VoiceElement, WordElement, areAzureLanguagesEquivalent, buildPartialSsml, buildSsml, extractSsmlText, extractSsmlTranslatableText, fromPlainTextToSsml, getAzureVoiceCatalogMetadata, getBuiltInVoiceCatalogMetadata, isValidAzureAudioDuration, mapSsmlTextNodes, normalizeAzureLanguage, parseSsml, validateAzureSsml, validateSsml, validateSsmlStructureIntegrity } from './core.js';
1
+ export { AudioElement, AzureDiagnosticCode, AzureLanguageNormalizationOptions, AzureSsmlValidationOptions, AzureUrlValidationResult, AzureUrlValidator, AzureValidationOptions, AzureVoiceCatalogMetadata, AzureVoiceDefinition, AzureVoiceMetadata, BookmarkElement, BreakElement, BuildPartialSsmlOptions, CustomElement, EmphasisElement, ExpressAsElement, ExtractSsmlTranslatableTextOptions, FromPlainTextToSsmlOptions, LangElement, LexiconElement, MapSsmlTextNodesOptions, MarkElement, MsttsAudioDurationElement, MsttsEmbeddingElement, MsttsSilenceElement, MsttsTtsEmbeddingElement, MsttsVisemeElement, MsttsVoiceConversionElement, NamedElement, ParagraphElement, PhonemeElement, ProsodyElement, SayAsElement, SentenceElement, SplitSsmlOptions, SsmlAttributeValue, SsmlAttributes, SsmlBackgroundAudioNode, SsmlBreakElement, SsmlChunk, SsmlChunkContext, SsmlDiagnostic, SsmlDiagnosticSeverity, SsmlDiagnosticSource, SsmlDialogNode, SsmlDocument, SsmlElement, SsmlElementBase, SsmlEmbeddingNode, SsmlExpressAsElement, SsmlNode, SsmlPartialContext, SsmlPartialProsody, SsmlPartialVoice, SsmlPhonemeElement, SsmlProsodyElement, SsmlSayAsElement, SsmlStructureIntegrityResult, SsmlStructureMismatch, SsmlText, SsmlTextNodeContext, SsmlTextRange, SsmlTtsEmbeddingNode, SsmlTurnNode, SsmlValidationError, SsmlVoiceConversionNode, SsmlVoiceElement, SubElement, VoiceElement, WordElement, areAzureLanguagesEquivalent, buildPartialSsml, buildSsml, extractSsmlText, extractSsmlTranslatableText, fromPlainTextToSsml, getAzureVoiceCatalogMetadata, getBuiltInVoiceCatalogMetadata, isValidAzureAudioDuration, mapSsmlTextNodes, normalizeAzureLanguage, parseSsml, splitSsmlDocument, validateAzureSsml, validateSsml, validateSsmlStructureIntegrity } from './core.js';
2
+ import { S as SsmlDiagnostic, A as AzureValidationOptions } from './index.d-Xbr6ZWnK.js';
2
3
 
3
4
  interface TtsConfig {
4
5
  signal?: AbortSignal;
@@ -7,6 +8,79 @@ interface TtsConfig {
7
8
  subscriptionKey: string;
8
9
  region: string;
9
10
  outputFormat?: string;
11
+ /** Original plain-text range represented by this synthesis request. */
12
+ sourceTextRange?: {
13
+ start: number;
14
+ end: number;
15
+ };
16
+ /** Reports completion of a chunk when using synthesizeSsmlChunks. */
17
+ onProgress?: (event: {
18
+ currentChunk: number;
19
+ totalChunks: number;
20
+ percent: number;
21
+ }) => void;
22
+ }
23
+ interface SsmlSynthesisBoundary {
24
+ text: string;
25
+ audioOffsetMs: number;
26
+ durationMs: number;
27
+ textRange?: {
28
+ start: number;
29
+ end: number;
30
+ };
31
+ requestId?: string;
32
+ }
33
+ interface SsmlSynthesisViseme {
34
+ visemeId: number;
35
+ audioOffsetMs: number;
36
+ textRange?: {
37
+ start: number;
38
+ end: number;
39
+ };
40
+ requestId?: string;
41
+ }
42
+ interface SsmlSynthesisBookmark {
43
+ name: string;
44
+ audioOffsetMs: number;
45
+ textRange?: {
46
+ start: number;
47
+ end: number;
48
+ };
49
+ requestId?: string;
50
+ }
51
+ /** Audio and Azure Speech synchronization events emitted for one SSML request. */
52
+ interface SsmlSynthesisResult {
53
+ audioData: ArrayBuffer;
54
+ durationMs: number;
55
+ boundaries?: SsmlSynthesisBoundary[];
56
+ /** Alias matching the Azure Speech event name. */
57
+ wordBoundary?: SsmlSynthesisBoundary[];
58
+ /** Alias for consumers that use Azure's word-boundary terminology. */
59
+ wordBoundaries?: SsmlSynthesisBoundary[];
60
+ visemes?: SsmlSynthesisViseme[];
61
+ bookmarks?: SsmlSynthesisBookmark[];
62
+ /** Request identifier returned by Azure Speech, when available. */
63
+ requestId?: string;
64
+ /** Original plain-text range represented by the result. */
65
+ textRange?: {
66
+ start: number;
67
+ end: number;
68
+ };
69
+ }
70
+ interface SsmlSynthesisChunk {
71
+ ssml: string;
72
+ originalTextRange?: {
73
+ start: number;
74
+ end: number;
75
+ };
76
+ }
77
+ interface SynthesizeChunksOptions {
78
+ onProgress?: (event: SynthesisProgressEvent) => void;
79
+ }
80
+ interface SynthesisProgressEvent {
81
+ currentChunk: number;
82
+ totalChunks: number;
83
+ percent: number;
10
84
  }
11
85
  interface AzureTtsLogger {
12
86
  debug?: (...args: unknown[]) => void;
@@ -22,6 +96,7 @@ interface AzureTtsClientOptions {
22
96
  endpoint?: string;
23
97
  outputFormat?: string;
24
98
  logger?: AzureTtsLogger;
99
+ onProgress?: (event: SynthesisProgressEvent) => void;
25
100
  }
26
101
 
27
102
  declare class AzureTtsError extends Error {
@@ -36,12 +111,58 @@ declare class AzureTtsSdkError extends AzureTtsError {
36
111
  constructor(errorDetails: string);
37
112
  }
38
113
 
114
+ interface SsmlValidationError {
115
+ readonly kind: "validation";
116
+ readonly message: string;
117
+ readonly diagnostics: readonly SsmlDiagnostic[];
118
+ }
119
+ type Result<T, E> = {
120
+ readonly ok: true;
121
+ readonly success: true;
122
+ readonly status: "success";
123
+ readonly value: T;
124
+ } | {
125
+ readonly ok: false;
126
+ readonly success: false;
127
+ readonly status: "validation-error" | "azure-api-error";
128
+ readonly error: E;
129
+ };
130
+ type SynthesisResult<T, E> = Result<T, E>;
131
+ type Success<T> = Extract<Result<T, never>, {
132
+ readonly ok: true;
133
+ }>;
134
+ type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
135
+ readonly status: "validation-error";
136
+ }>;
137
+ type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
138
+ readonly status: "azure-api-error";
139
+ }>;
140
+ type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, AzureTtsError>;
141
+ interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
142
+ /** Optional nested form for callers that want to keep validation settings grouped. */
143
+ validation?: AzureValidationOptions;
144
+ }
145
+ interface SynthesisClient {
146
+ synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
147
+ }
148
+ /** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
149
+ declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
150
+
39
151
  declare class AzureTtsClient {
40
152
  #private;
41
153
  constructor(options: AzureTtsClientOptions);
42
154
  synthesize(ssml: string): Promise<ArrayBuffer>;
155
+ synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
156
+ synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
157
+ synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
43
158
  }
44
159
 
160
+ declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
161
+ /** Synthesizes chunks sequentially, annotates synchronization events, and merges the results. */
162
+ declare function synthesizeSsmlChunks(chunks: readonly (SsmlSynthesisChunk | string)[], config: TtsConfig): Promise<SsmlSynthesisResult>;
163
+ /** Concatenates audio buffers and shifts all synchronization events by prior chunk durations. */
164
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[]): SsmlSynthesisResult;
165
+ /** Backward-compatible audio-only synthesis helper. */
45
166
  declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
46
167
 
47
168
  interface FetchAzureVoiceCatalogOptions {
@@ -69,4 +190,4 @@ interface AzureVoiceCatalog {
69
190
  /** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
70
191
  declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
71
192
 
72
- export { AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, AzureTtsSdkError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type TtsConfig, fetchAzureVoiceCatalog, synthesizeSpeech };
193
+ export { type AzureApiErrorResult, type SsmlValidationError as AzureSsmlValidationError, AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, AzureTtsSdkError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type Result, type SsmlSynthesisBookmark, type SsmlSynthesisBoundary, type SsmlSynthesisChunk, type SsmlSynthesisResult, type SsmlSynthesisSafeResult, type SsmlSynthesisViseme, type Success, type SynthesisProgressEvent, type SynthesisResult, type SynthesizeChunksOptions, type SynthesizeSsmlSafeOptions, type TtsConfig, type ValidationErrorResult, fetchAzureVoiceCatalog, mergeSynthesisResults, synthesizeSpeech, synthesizeSsml, synthesizeSsmlChunks, synthesizeSsmlSafe };