@loonylabs/tts-middleware 0.1.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.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -0
  3. package/dist/index.d.ts +22 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +39 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/middleware/services/tts/index.d.ts +30 -0
  8. package/dist/middleware/services/tts/index.d.ts.map +1 -0
  9. package/dist/middleware/services/tts/index.js +69 -0
  10. package/dist/middleware/services/tts/index.js.map +1 -0
  11. package/dist/middleware/services/tts/providers/azure-provider.d.ts +131 -0
  12. package/dist/middleware/services/tts/providers/azure-provider.d.ts.map +1 -0
  13. package/dist/middleware/services/tts/providers/azure-provider.js +375 -0
  14. package/dist/middleware/services/tts/providers/azure-provider.js.map +1 -0
  15. package/dist/middleware/services/tts/providers/base-tts-provider.d.ts +204 -0
  16. package/dist/middleware/services/tts/providers/base-tts-provider.d.ts.map +1 -0
  17. package/dist/middleware/services/tts/providers/base-tts-provider.js +267 -0
  18. package/dist/middleware/services/tts/providers/base-tts-provider.js.map +1 -0
  19. package/dist/middleware/services/tts/providers/edenai-provider.d.ts +112 -0
  20. package/dist/middleware/services/tts/providers/edenai-provider.d.ts.map +1 -0
  21. package/dist/middleware/services/tts/providers/edenai-provider.js +289 -0
  22. package/dist/middleware/services/tts/providers/edenai-provider.js.map +1 -0
  23. package/dist/middleware/services/tts/providers/index.d.ts +9 -0
  24. package/dist/middleware/services/tts/providers/index.d.ts.map +1 -0
  25. package/dist/middleware/services/tts/providers/index.js +29 -0
  26. package/dist/middleware/services/tts/providers/index.js.map +1 -0
  27. package/dist/middleware/services/tts/tts.service.d.ts +175 -0
  28. package/dist/middleware/services/tts/tts.service.d.ts.map +1 -0
  29. package/dist/middleware/services/tts/tts.service.js +287 -0
  30. package/dist/middleware/services/tts/tts.service.js.map +1 -0
  31. package/dist/middleware/services/tts/types/common.types.d.ts +303 -0
  32. package/dist/middleware/services/tts/types/common.types.d.ts.map +1 -0
  33. package/dist/middleware/services/tts/types/common.types.js +42 -0
  34. package/dist/middleware/services/tts/types/common.types.js.map +1 -0
  35. package/dist/middleware/services/tts/types/index.d.ts +22 -0
  36. package/dist/middleware/services/tts/types/index.d.ts.map +1 -0
  37. package/dist/middleware/services/tts/types/index.js +46 -0
  38. package/dist/middleware/services/tts/types/index.js.map +1 -0
  39. package/dist/middleware/services/tts/types/provider-options.types.d.ts +414 -0
  40. package/dist/middleware/services/tts/types/provider-options.types.d.ts.map +1 -0
  41. package/dist/middleware/services/tts/types/provider-options.types.js +71 -0
  42. package/dist/middleware/services/tts/types/provider-options.types.js.map +1 -0
  43. package/dist/middleware/services/tts/utils/character-counter.utils.d.ts +160 -0
  44. package/dist/middleware/services/tts/utils/character-counter.utils.d.ts.map +1 -0
  45. package/dist/middleware/services/tts/utils/character-counter.utils.js +205 -0
  46. package/dist/middleware/services/tts/utils/character-counter.utils.js.map +1 -0
  47. package/dist/middleware/services/tts/utils/index.d.ts +9 -0
  48. package/dist/middleware/services/tts/utils/index.d.ts.map +1 -0
  49. package/dist/middleware/services/tts/utils/index.js +25 -0
  50. package/dist/middleware/services/tts/utils/index.js.map +1 -0
  51. package/dist/middleware/services/tts/utils/logger.utils.d.ts +116 -0
  52. package/dist/middleware/services/tts/utils/logger.utils.d.ts.map +1 -0
  53. package/dist/middleware/services/tts/utils/logger.utils.js +186 -0
  54. package/dist/middleware/services/tts/utils/logger.utils.js.map +1 -0
  55. package/dist/middleware/shared/config/tts.config.d.ts +147 -0
  56. package/dist/middleware/shared/config/tts.config.d.ts.map +1 -0
  57. package/dist/middleware/shared/config/tts.config.js +162 -0
  58. package/dist/middleware/shared/config/tts.config.js.map +1 -0
  59. package/package.json +94 -0
@@ -0,0 +1,414 @@
1
+ /**
2
+ * Provider-specific option types for TTS synthesis
3
+ *
4
+ * These types define all possible provider-specific parameters.
5
+ * All providers are typed NOW (MVP + Future) to prevent breaking API changes.
6
+ *
7
+ * @MVP ✅ Azure options are implemented
8
+ * @Future 🔮 Other providers typed but not implemented yet
9
+ */
10
+ /**
11
+ * Azure Speech Services provider options
12
+ *
13
+ * @MVP ✅ Implemented
14
+ * @provider Azure Speech Services
15
+ *
16
+ * @see https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice
17
+ */
18
+ export interface AzureProviderOptions {
19
+ /**
20
+ * Emotional tone of the speech
21
+ * @MVP ✅ Implemented
22
+ *
23
+ * @description Maps to SSML style attribute. Only supported by
24
+ * specific Azure neural voices (e.g., Jenny, Guy, Aria).
25
+ *
26
+ * @options 'sad', 'angry', 'cheerful', 'friendly', 'terrified',
27
+ * 'shouting', 'whispering', 'hopeful', 'gentle', 'excited',
28
+ * 'empathetic', 'calm', 'fearful', 'disgruntled', 'serious',
29
+ * 'depressed', 'embarrassed'
30
+ *
31
+ * @example 'cheerful'
32
+ */
33
+ emotion?: 'sad' | 'angry' | 'cheerful' | 'friendly' | 'terrified' | 'shouting' | 'whispering' | 'hopeful' | 'gentle' | 'excited' | 'empathetic' | 'calm' | 'fearful' | 'disgruntled' | 'serious' | 'depressed' | 'embarrassed';
34
+ /**
35
+ * Speaking style for the voice
36
+ * @MVP ✅ Implemented
37
+ *
38
+ * @description Maps to SSML style attribute. Voice-dependent feature.
39
+ *
40
+ * @options 'chat', 'customerservice', 'newscast', 'assistant',
41
+ * 'newscast-casual', 'newscast-formal', 'chat-casual',
42
+ * 'lyrical', 'advertisement-upbeat', 'narration-professional',
43
+ * 'narration-relaxed', 'sports-commentary',
44
+ * 'sports-commentary-excited'
45
+ *
46
+ * @example 'chat'
47
+ */
48
+ style?: 'chat' | 'customerservice' | 'newscast' | 'assistant' | 'newscast-casual' | 'newscast-formal' | 'chat-casual' | 'lyrical' | 'advertisement-upbeat' | 'narration-professional' | 'narration-relaxed' | 'sports-commentary' | 'sports-commentary-excited';
49
+ /**
50
+ * Style intensity/degree (0.01 to 2.0)
51
+ * @Future 🔮 Not implemented in MVP
52
+ *
53
+ * @range 0.01 - 2.0
54
+ * @default 1.0
55
+ */
56
+ styleDegree?: number;
57
+ /**
58
+ * Role play scenario
59
+ * @Future 🔮 Not implemented in MVP
60
+ *
61
+ * @options 'YoungAdultFemale', 'YoungAdultMale', 'OlderAdultFemale', 'OlderAdultMale', 'Girl', 'Boy'
62
+ */
63
+ role?: string;
64
+ }
65
+ /**
66
+ * OpenAI TTS provider options
67
+ *
68
+ * @Future 🔮 Not implemented in MVP
69
+ * @provider OpenAI TTS API
70
+ *
71
+ * @see https://platform.openai.com/docs/guides/text-to-speech
72
+ */
73
+ export interface OpenAIProviderOptions {
74
+ /**
75
+ * TTS model to use
76
+ * @Future 🔮 Not implemented in MVP
77
+ *
78
+ * @options
79
+ * - 'tts-1': Standard quality, lower latency
80
+ * - 'tts-1-hd': High quality, higher latency
81
+ * - 'gpt-4o-mini-tts': Token-based model
82
+ *
83
+ * @default 'tts-1'
84
+ */
85
+ model?: 'tts-1' | 'tts-1-hd' | 'gpt-4o-mini-tts';
86
+ /**
87
+ * Response format override
88
+ * @Future 🔮 Not implemented in MVP
89
+ *
90
+ * @description If not specified, uses the format from audio.format
91
+ *
92
+ * @options 'mp3', 'opus', 'aac', 'flac'
93
+ * @default 'mp3'
94
+ */
95
+ responseFormat?: 'mp3' | 'opus' | 'aac' | 'flac';
96
+ }
97
+ /**
98
+ * ElevenLabs TTS provider options
99
+ *
100
+ * @Future 🔮 Not implemented in MVP
101
+ * @provider ElevenLabs TTS API
102
+ *
103
+ * @see https://elevenlabs.io/docs/api-reference/text-to-speech
104
+ */
105
+ export interface ElevenLabsProviderOptions {
106
+ /**
107
+ * Voice model ID
108
+ * @Future 🔮 Not implemented in MVP
109
+ *
110
+ * @options
111
+ * - 'eleven_monolingual_v1': English only, lower latency
112
+ * - 'eleven_multilingual_v1': Multiple languages
113
+ * - 'eleven_multilingual_v2': Latest multilingual model
114
+ * - 'eleven_turbo_v2': Fastest, lower quality
115
+ *
116
+ * @default 'eleven_multilingual_v2'
117
+ */
118
+ model_id?: string;
119
+ /**
120
+ * Voice stability (0.0 - 1.0)
121
+ * @Future 🔮 Not implemented in MVP
122
+ *
123
+ * @description Higher values = more stable/consistent, less expressive
124
+ * Lower values = more variable/expressive
125
+ *
126
+ * @range 0.0 - 1.0
127
+ * @default 0.5
128
+ */
129
+ stability?: number;
130
+ /**
131
+ * Similarity boost (0.0 - 1.0)
132
+ * @Future 🔮 Not implemented in MVP
133
+ *
134
+ * @description Higher values = more similar to original voice sample
135
+ *
136
+ * @range 0.0 - 1.0
137
+ * @default 0.75
138
+ */
139
+ similarity_boost?: number;
140
+ /**
141
+ * Enable speaker boost
142
+ * @Future 🔮 Not implemented in MVP
143
+ *
144
+ * @description Enhances voice clarity and reduces artifacts
145
+ *
146
+ * @default true
147
+ */
148
+ speaker_boost?: boolean;
149
+ /**
150
+ * Style exaggeration (0.0 - 1.0)
151
+ * @Future 🔮 Not implemented in MVP
152
+ *
153
+ * @description Higher values = more exaggerated style (different from Azure style!)
154
+ *
155
+ * @range 0.0 - 1.0
156
+ * @default 0.0
157
+ */
158
+ style?: number;
159
+ /**
160
+ * Use speaker boost (legacy parameter)
161
+ * @Future 🔮 Not implemented in MVP
162
+ * @deprecated Use speaker_boost instead
163
+ */
164
+ use_speaker_boost?: boolean;
165
+ }
166
+ /**
167
+ * Google Cloud Text-to-Speech provider options
168
+ *
169
+ * @Future 🔮 Not implemented in MVP
170
+ * @provider Google Cloud TTS
171
+ *
172
+ * @see https://cloud.google.com/text-to-speech/docs/reference/rest/v1/text/synthesize
173
+ */
174
+ export interface GoogleCloudProviderOptions {
175
+ /**
176
+ * Audio effects profile IDs
177
+ * @Future 🔮 Not implemented in MVP
178
+ *
179
+ * @description Array of audio effect profile IDs to apply
180
+ *
181
+ * @options
182
+ * - 'wearable-class-device'
183
+ * - 'handset-class-device'
184
+ * - 'headphone-class-device'
185
+ * - 'small-bluetooth-speaker-class-device'
186
+ * - 'medium-bluetooth-speaker-class-device'
187
+ * - 'large-home-entertainment-class-device'
188
+ * - 'large-automotive-class-device'
189
+ * - 'telephony-class-application'
190
+ *
191
+ * @example ['headphone-class-device']
192
+ */
193
+ effectsProfileId?: string[];
194
+ /**
195
+ * Pitch adjustment in semitones
196
+ * @Future 🔮 Not implemented in MVP
197
+ *
198
+ * @description Overrides the pitch parameter in AudioOptions if both are specified
199
+ *
200
+ * @range -20.0 to 20.0
201
+ * @default 0.0
202
+ */
203
+ pitchSemitones?: number;
204
+ /**
205
+ * Speaking rate multiplier
206
+ * @Future 🔮 Not implemented in MVP
207
+ *
208
+ * @description Alternative to speed in AudioOptions
209
+ *
210
+ * @range 0.25 - 4.0
211
+ * @default 1.0
212
+ */
213
+ speakingRate?: number;
214
+ /**
215
+ * Volume gain in dB
216
+ * @Future 🔮 Not implemented in MVP
217
+ *
218
+ * @description Alternative to volumeGainDb in AudioOptions
219
+ *
220
+ * @range -96.0 to 16.0
221
+ * @default 0.0
222
+ */
223
+ volumeGainDb?: number;
224
+ }
225
+ /**
226
+ * Deepgram TTS provider options
227
+ *
228
+ * @Future 🔮 Not implemented in MVP
229
+ * @provider Deepgram TTS API
230
+ *
231
+ * @see https://developers.deepgram.com/docs/tts-rest
232
+ */
233
+ export interface DeepgramProviderOptions {
234
+ /**
235
+ * TTS model to use
236
+ * @Future 🔮 Not implemented in MVP
237
+ *
238
+ * @options
239
+ * - 'aura-asteria-en': Female, US English
240
+ * - 'aura-luna-en': Female, US English
241
+ * - 'aura-stella-en': Female, US English
242
+ * - 'aura-athena-en': Female, UK English
243
+ * - 'aura-hera-en': Female, US English
244
+ * - 'aura-orion-en': Male, US English
245
+ * - 'aura-arcas-en': Male, US English
246
+ * - 'aura-perseus-en': Male, US English
247
+ * - 'aura-angus-en': Male, Irish English
248
+ * - 'aura-orpheus-en': Male, US English
249
+ * - 'aura-helios-en': Male, UK English
250
+ * - 'aura-zeus-en': Male, US English
251
+ *
252
+ * @default 'aura-asteria-en'
253
+ */
254
+ model?: string;
255
+ /**
256
+ * Audio encoding format
257
+ * @Future 🔮 Not implemented in MVP
258
+ *
259
+ * @description Alternative to format in AudioOptions
260
+ *
261
+ * @options 'linear16', 'mulaw', 'alaw', 'opus', 'aac', 'mp3'
262
+ * @default 'linear16'
263
+ */
264
+ encoding?: 'linear16' | 'mulaw' | 'alaw' | 'opus' | 'aac' | 'mp3';
265
+ /**
266
+ * Audio container format
267
+ * @Future 🔮 Not implemented in MVP
268
+ *
269
+ * @options 'wav', 'mp3', 'opus', 'flac'
270
+ * @default 'wav'
271
+ */
272
+ container?: 'wav' | 'mp3' | 'opus' | 'flac';
273
+ /**
274
+ * Bitrate for encoded audio
275
+ * @Future 🔮 Not implemented in MVP
276
+ *
277
+ * @example '128000' (128 kbps)
278
+ */
279
+ bitrate?: string;
280
+ /**
281
+ * Sample rate in Hz
282
+ * @Future 🔮 Not implemented in MVP
283
+ *
284
+ * @description Alternative to sampleRate in AudioOptions
285
+ *
286
+ * @options 8000, 16000, 24000, 48000
287
+ * @default 24000
288
+ */
289
+ sampleRate?: number;
290
+ }
291
+ /**
292
+ * EdenAI TTS provider options
293
+ *
294
+ * @description EdenAI is a multi-provider aggregator that provides access
295
+ * to multiple TTS providers through a single API.
296
+ *
297
+ * @provider EdenAI (multi-provider aggregator)
298
+ *
299
+ * @see https://docs.edenai.co/reference/text_to_speech_create
300
+ */
301
+ export interface EdenAIProviderOptions {
302
+ /**
303
+ * Underlying provider to use via EdenAI
304
+ *
305
+ * @description EdenAI acts as an aggregator, routing requests to the selected provider.
306
+ *
307
+ * @options
308
+ * - 'amazon': Amazon Polly
309
+ * - 'google': Google Cloud TTS
310
+ * - 'ibm': IBM Watson TTS
311
+ * - 'microsoft': Microsoft Azure Speech
312
+ * - 'openai': OpenAI TTS
313
+ * - 'elevenlabs': ElevenLabs TTS
314
+ *
315
+ * @default Auto-selected by EdenAI based on language/voice
316
+ */
317
+ provider?: 'amazon' | 'google' | 'ibm' | 'microsoft' | 'openai' | 'elevenlabs';
318
+ /**
319
+ * Speaking rate multiplier
320
+ *
321
+ * @description Controls the speed of speech synthesis
322
+ *
323
+ * @range 0.25 - 4.0
324
+ * @default 1.0
325
+ */
326
+ speaking_rate?: number;
327
+ /**
328
+ * Pitch adjustment in semitones
329
+ *
330
+ * @description Adjusts the pitch of the synthesized voice
331
+ *
332
+ * @range -20.0 to 20.0
333
+ * @default 0.0
334
+ */
335
+ speaking_pitch?: number;
336
+ /**
337
+ * Volume adjustment in decibels
338
+ *
339
+ * @description Adjusts the volume of the synthesized speech
340
+ *
341
+ * @range -96.0 to 16.0
342
+ * @default 0.0
343
+ */
344
+ speaking_volume?: number;
345
+ /**
346
+ * Audio format override
347
+ *
348
+ * @description If not specified, uses the format from audio.format
349
+ *
350
+ * @options 'mp3', 'wav', 'ogg', 'flac'
351
+ * @default 'mp3'
352
+ */
353
+ audio_format?: 'mp3' | 'wav' | 'ogg' | 'flac';
354
+ /**
355
+ * Sample rate in Hz
356
+ *
357
+ * @description If not specified, uses the sampleRate from audio options
358
+ *
359
+ * @options 8000, 16000, 22050, 24000, 44100, 48000
360
+ * @default 24000
361
+ */
362
+ sampling_rate?: number;
363
+ /**
364
+ * Fallback providers
365
+ *
366
+ * @description List of provider names to use as fallbacks if the primary provider fails
367
+ *
368
+ * @example ['google', 'amazon', 'microsoft']
369
+ */
370
+ fallback_providers?: string[];
371
+ /**
372
+ * Webhook URL for async notifications
373
+ *
374
+ * @description URL to receive notifications when synthesis completes (for async requests)
375
+ */
376
+ webhook_url?: string;
377
+ /**
378
+ * Webhook receiver identifier
379
+ *
380
+ * @description Identifier for the webhook receiver
381
+ */
382
+ webhook_receiver?: string;
383
+ }
384
+ /**
385
+ * Union type of all provider options
386
+ *
387
+ * @description Use this type when you need to accept any provider options
388
+ */
389
+ export type ProviderOptions = AzureProviderOptions | OpenAIProviderOptions | ElevenLabsProviderOptions | GoogleCloudProviderOptions | DeepgramProviderOptions | EdenAIProviderOptions;
390
+ /**
391
+ * Type guard to check if options are for Azure
392
+ */
393
+ export declare function isAzureOptions(options: unknown): options is AzureProviderOptions;
394
+ /**
395
+ * Type guard to check if options are for OpenAI
396
+ */
397
+ export declare function isOpenAIOptions(options: unknown): options is OpenAIProviderOptions;
398
+ /**
399
+ * Type guard to check if options are for ElevenLabs
400
+ */
401
+ export declare function isElevenLabsOptions(options: unknown): options is ElevenLabsProviderOptions;
402
+ /**
403
+ * Type guard to check if options are for Google Cloud
404
+ */
405
+ export declare function isGoogleCloudOptions(options: unknown): options is GoogleCloudProviderOptions;
406
+ /**
407
+ * Type guard to check if options are for Deepgram
408
+ */
409
+ export declare function isDeepgramOptions(options: unknown): options is DeepgramProviderOptions;
410
+ /**
411
+ * Type guard to check if options are for EdenAI
412
+ */
413
+ export declare function isEdenAIOptions(options: unknown): options is EdenAIProviderOptions;
414
+ //# sourceMappingURL=provider-options.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-options.types.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/tts/types/provider-options.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,EACJ,KAAK,GACL,OAAO,GACP,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,YAAY,GACZ,SAAS,GACT,QAAQ,GACR,SAAS,GACT,YAAY,GACZ,MAAM,GACN,SAAS,GACT,aAAa,GACb,SAAS,GACT,WAAW,GACX,aAAa,CAAC;IAElB;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,EACF,MAAM,GACN,iBAAiB,GACjB,UAAU,GACV,WAAW,GACX,iBAAiB,GACjB,iBAAiB,GACjB,aAAa,GACb,SAAS,GACT,sBAAsB,GACtB,wBAAwB,GACxB,mBAAmB,GACnB,mBAAmB,GACnB,2BAA2B,CAAC;IAEhC;;;;;;OAMG;IACH,WAAW,CAAC,EA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tC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,0BAA0B,CAMvC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,uBAAuB,CAMpC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,qBAAqB,CAUlC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /**
3
+ * Provider-specific option types for TTS synthesis
4
+ *
5
+ * These types define all possible provider-specific parameters.
6
+ * All providers are typed NOW (MVP + Future) to prevent breaking API changes.
7
+ *
8
+ * @MVP ✅ Azure options are implemented
9
+ * @Future 🔮 Other providers typed but not implemented yet
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isAzureOptions = isAzureOptions;
13
+ exports.isOpenAIOptions = isOpenAIOptions;
14
+ exports.isElevenLabsOptions = isElevenLabsOptions;
15
+ exports.isGoogleCloudOptions = isGoogleCloudOptions;
16
+ exports.isDeepgramOptions = isDeepgramOptions;
17
+ exports.isEdenAIOptions = isEdenAIOptions;
18
+ /**
19
+ * Type guard to check if options are for Azure
20
+ */
21
+ function isAzureOptions(options) {
22
+ return (typeof options === 'object' &&
23
+ options !== null &&
24
+ ('emotion' in options || 'style' in options));
25
+ }
26
+ /**
27
+ * Type guard to check if options are for OpenAI
28
+ */
29
+ function isOpenAIOptions(options) {
30
+ return (typeof options === 'object' &&
31
+ options !== null &&
32
+ 'model' in options &&
33
+ typeof options.model === 'string');
34
+ }
35
+ /**
36
+ * Type guard to check if options are for ElevenLabs
37
+ */
38
+ function isElevenLabsOptions(options) {
39
+ return (typeof options === 'object' &&
40
+ options !== null &&
41
+ ('stability' in options || 'similarity_boost' in options));
42
+ }
43
+ /**
44
+ * Type guard to check if options are for Google Cloud
45
+ */
46
+ function isGoogleCloudOptions(options) {
47
+ return (typeof options === 'object' &&
48
+ options !== null &&
49
+ ('effectsProfileId' in options || 'pitchSemitones' in options));
50
+ }
51
+ /**
52
+ * Type guard to check if options are for Deepgram
53
+ */
54
+ function isDeepgramOptions(options) {
55
+ return (typeof options === 'object' &&
56
+ options !== null &&
57
+ ('encoding' in options || 'container' in options));
58
+ }
59
+ /**
60
+ * Type guard to check if options are for EdenAI
61
+ */
62
+ function isEdenAIOptions(options) {
63
+ return (typeof options === 'object' &&
64
+ options !== null &&
65
+ ('speaking_rate' in options ||
66
+ 'speaking_pitch' in options ||
67
+ 'speaking_volume' in options ||
68
+ 'fallback_providers' in options ||
69
+ 'webhook_url' in options));
70
+ }
71
+ //# sourceMappingURL=provider-options.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-options.types.js","sourceRoot":"","sources":["../../../../../src/middleware/services/tts/types/provider-options.types.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA0cH,wCAQC;AAKD,0CASC;AAKD,kDAQC;AAKD,oDAQC;AAKD,8CAQC;AAKD,0CAYC;AAjFD;;GAEG;AACH,SAAgB,cAAc,CAC5B,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,CAAC,SAAS,IAAI,OAAO,IAAI,OAAO,IAAI,OAAO,CAAC,CAC7C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC7B,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,OAAO,IAAI,OAAO;QAClB,OAAQ,OAA8B,CAAC,KAAK,KAAK,QAAQ,CAC1D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CACjC,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,CAAC,WAAW,IAAI,OAAO,IAAI,kBAAkB,IAAI,OAAO,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,CAAC,kBAAkB,IAAI,OAAO,IAAI,gBAAgB,IAAI,OAAO,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,CAAC,UAAU,IAAI,OAAO,IAAI,WAAW,IAAI,OAAO,CAAC,CAClD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAC7B,OAAgB;IAEhB,OAAO,CACL,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,CAAC,eAAe,IAAI,OAAO;YACzB,gBAAgB,IAAI,OAAO;YAC3B,iBAAiB,IAAI,OAAO;YAC5B,oBAAoB,IAAI,OAAO;YAC/B,aAAa,IAAI,OAAO,CAAC,CAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Character Counting Utilities
3
+ *
4
+ * @description Accurate character counting for billing purposes.
5
+ * This is billing-critical code - all functions must be 100% accurate
6
+ * and match provider billing methodologies.
7
+ *
8
+ * @critical This code directly impacts customer billing. Any bugs here
9
+ * could result in incorrect charges. Test coverage MUST be 100%.
10
+ */
11
+ /**
12
+ * Count all characters in text for billing purposes
13
+ *
14
+ * @param text - The input text to count
15
+ * @returns The total number of characters including spaces, punctuation, and newlines
16
+ *
17
+ * @description
18
+ * This function counts ALL characters in the input text:
19
+ * - Letters (a-z, A-Z)
20
+ * - Numbers (0-9)
21
+ * - Spaces and tabs
22
+ * - Newlines (\n, \r\n)
23
+ * - Punctuation and special characters
24
+ * - Unicode characters (counted as 1 character each)
25
+ * - Emoji (counted as 1 character each, regardless of byte length)
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * countCharacters("Hello World!") // returns 12
30
+ * countCharacters("Guten Morgen") // returns 12
31
+ * countCharacters("Hello 👋") // returns 8
32
+ * countCharacters("") // returns 0
33
+ * ```
34
+ *
35
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
36
+ *
37
+ * @critical Billing-critical function. Must be 100% accurate.
38
+ */
39
+ export declare function countCharacters(text: string): number;
40
+ /**
41
+ * Count characters in text after removing SSML markup
42
+ *
43
+ * @param text - The input text (may contain SSML tags)
44
+ * @returns The number of characters excluding SSML tags
45
+ *
46
+ * @description
47
+ * This function removes all SSML (Speech Synthesis Markup Language) tags
48
+ * before counting characters. This is used when the middleware generates
49
+ * SSML internally but billing is based on the plain text content.
50
+ *
51
+ * SSML tags removed include:
52
+ * - `<speak>`, `</speak>` - Root element
53
+ * - `<voice>`, `</voice>` - Voice selection
54
+ * - `<prosody>`, `</prosody>` - Prosody (rate, pitch, volume)
55
+ * - `<emphasis>`, `</emphasis>` - Emphasis
56
+ * - `<break>` - Pauses
57
+ * - `<say-as>`, `</say-as>` - Interpret-as hints
58
+ * - `<phoneme>`, `</phoneme>` - Phonetic pronunciation
59
+ * - `<sub>`, `</sub>` - Substitution
60
+ * - `<lang>`, `</lang>` - Language switching
61
+ * - And all other SSML tags
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * countCharactersWithoutSSML("<speak>Hello</speak>")
66
+ * // returns 5 (only "Hello" is counted)
67
+ *
68
+ * countCharactersWithoutSSML('<voice name="en-US-Jenny">Text</voice>')
69
+ * // returns 4 (only "Text" is counted)
70
+ *
71
+ * countCharactersWithoutSSML('<prosody rate="slow">Hello World</prosody>')
72
+ * // returns 11 (only "Hello World" is counted)
73
+ * ```
74
+ *
75
+ * @critical Billing-critical function. Must match Azure's character counting.
76
+ */
77
+ export declare function countCharactersWithoutSSML(text: string): number;
78
+ /**
79
+ * Validate that character count matches expected range
80
+ *
81
+ * @param text - The input text
82
+ * @param minChars - Minimum expected characters (default: 0)
83
+ * @param maxChars - Maximum expected characters (default: Infinity)
84
+ * @returns True if count is within range
85
+ * @throws {RangeError} If character count is outside expected range
86
+ *
87
+ * @description
88
+ * This is a utility function to validate text length before synthesis.
89
+ * Providers often have limits on input text length (e.g., Azure: 3000 chars per request).
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * validateCharacterCount("Hello", 1, 100) // returns true
94
+ * validateCharacterCount("", 1, 100) // throws RangeError
95
+ * ```
96
+ */
97
+ export declare function validateCharacterCount(text: string, minChars?: number, maxChars?: number): boolean;
98
+ /**
99
+ * Count billable characters (alias for countCharacters)
100
+ *
101
+ * @param text - The input text
102
+ * @returns The number of billable characters
103
+ *
104
+ * @description
105
+ * Semantic alias for countCharacters to make billing calculations clearer.
106
+ * This is the function consumers should use when calculating costs.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const text = "Hello World!";
111
+ * const chars = countBillableCharacters(text); // 12
112
+ * const costUSD = (chars / 1_000_000) * 16; // $16 per 1M chars
113
+ * ```
114
+ */
115
+ export declare function countBillableCharacters(text: string): number;
116
+ /**
117
+ * Estimate audio duration based on character count
118
+ *
119
+ * @param text - The input text
120
+ * @param speedMultiplier - Speech speed (0.5 to 2.0, default: 1.0)
121
+ * @param charsPerSecond - Average characters spoken per second (default: 15)
122
+ * @returns Estimated duration in milliseconds
123
+ *
124
+ * @description
125
+ * Provides a rough estimate of audio duration based on character count.
126
+ * This is NOT exact and varies by:
127
+ * - Language (some languages are more verbose)
128
+ * - Voice (different voices have different pacing)
129
+ * - Content (technical terms take longer)
130
+ * - Speed setting
131
+ *
132
+ * Default assumption: ~15 characters per second at normal speed
133
+ * (roughly 150-180 words per minute, assuming 5-6 chars per word)
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * estimateAudioDuration("Hello World!", 1.0) // ~800ms
138
+ * estimateAudioDuration("Hello World!", 0.5) // ~1600ms (slower)
139
+ * ```
140
+ */
141
+ export declare function estimateAudioDuration(text: string, speedMultiplier?: number, charsPerSecond?: number): number;
142
+ /**
143
+ * Format character count for display
144
+ *
145
+ * @param count - The character count
146
+ * @returns Formatted string (e.g., "1.2K chars", "1.5M chars")
147
+ *
148
+ * @description
149
+ * Formats large character counts in human-readable format.
150
+ * Useful for displaying usage statistics.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * formatCharacterCount(500) // "500 chars"
155
+ * formatCharacterCount(1234) // "1.2K chars"
156
+ * formatCharacterCount(1500000) // "1.5M chars"
157
+ * ```
158
+ */
159
+ export declare function formatCharacterCount(count: number): string;
160
+ //# sourceMappingURL=character-counter.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"character-counter.utils.d.ts","sourceRoot":"","sources":["../../../../../src/middleware/services/tts/utils/character-counter.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO/D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAU,EACpB,QAAQ,GAAE,MAAiB,GAC1B,OAAO,CAgBT;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,eAAe,GAAE,MAAY,EAC7B,cAAc,GAAE,MAAW,GAC1B,MAAM,CAWR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAU1D"}