microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 6.94 kB
Source Map (JSON)
{"version":3,"sources":["src/sdk/SpeechSynthesisRequest.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAc,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F;;;;GAIG;AACH,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,aAAa,CAAkC;IACvD,OAAO,CAAC,eAAe,CAAoC;IAC3D,OAAO,CAAC,cAAc,CAAqB;IAC3C,OAAO,CAAC,qBAAqB,CAAyB;IACtD,OAAO,CAAC,uBAAuB,CAAa;IAC5C,OAAO,CAAC,sBAAsB,CAAgB;IAC9C,OAAO,CAAC,2BAA2B,CAAkB;IAErD;;;OAGG;gBACgB,SAAS,EAAE,+BAA+B;IAS7D;;OAEG;IACH,IAAW,SAAS,IAAI,+BAA+B,CAEtD;IAED;;OAEG;IACH,IAAW,WAAW,IAAI,iCAAiC,CAE1D;IAED;;OAEG;IACH,IAAW,UAAU,IAAI,kBAAkB,CAE1C;IAED;;OAEG;IACH,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAE7B;IAED;;OAEG;IACH,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAE5B;IAED;;OAEG;IACH,IAAW,MAAM,CAAC,KAAK,EAAE,MAAM,EAE9B;IAED;;OAEG;IACH,IAAW,KAAK,CAAC,KAAK,EAAE,MAAM,EAE7B;IAED;;OAEG;IACH,IAAW,WAAW,CAAC,KAAK,EAAE,MAAM,EAEnC;IAED;;OAEG;IACH,IAAW,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAExC;IAED;;OAEG;IACH,IAAW,aAAa,CAAC,KAAK,EAAE,MAAM,EAErC;IAED;;;;OAIG;IACI,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ9C;;;;OAIG;IACI,mBAAmB,IAAI,IAAI;IAQlC;;;;OAIG;IACH,IAAW,WAAW,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAOtD;IAED;;;;OAIG;IACH,IAAW,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI,EAOtC;CACJ","file":"SpeechSynthesisRequest.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { PropertyCollection, PropertyId } from \"./Exports.js\";\r\nimport { SpeechSynthesisRequestInputType } from \"./SpeechSynthesisRequestInputType.js\";\r\nimport { SpeechSynthesisRequestInputStream } from \"./SpeechSynthesisRequestInputStream.js\";\r\n\r\nexport { SpeechSynthesisRequestInputStream } from \"./SpeechSynthesisRequestInputStream.js\";\r\n\r\n/**\r\n * Represents a speech synthesis request with support for text streaming.\r\n * Note: This class is in preview and may be subject to change in future versions.\r\n * @class SpeechSynthesisRequest\r\n */\r\nexport class SpeechSynthesisRequest {\r\n private privInputType: SpeechSynthesisRequestInputType;\r\n private privInputStream: SpeechSynthesisRequestInputStream;\r\n private privProperties: PropertyCollection;\r\n private privTextPieceCallback: (text: string) => void;\r\n private privStreamCloseCallback: () => void;\r\n private privBufferedTextPieces: string[] = [];\r\n private privStreamClosedBeforeReady: boolean = false;\r\n\r\n /**\r\n * Creates a speech synthesis request.\r\n * @param inputType The input type for the speech synthesis request.\r\n */\r\n public constructor(inputType: SpeechSynthesisRequestInputType) {\r\n if (inputType !== SpeechSynthesisRequestInputType.TextStream) {\r\n throw new Error(\"Only TextStream input type is supported in this version.\");\r\n }\r\n this.privInputType = inputType;\r\n this.privInputStream = new SpeechSynthesisRequestInputStream(this);\r\n this.privProperties = new PropertyCollection();\r\n }\r\n\r\n /**\r\n * Gets the input type of this request.\r\n */\r\n public get inputType(): SpeechSynthesisRequestInputType {\r\n return this.privInputType;\r\n }\r\n\r\n /**\r\n * Gets the input stream for writing text pieces.\r\n */\r\n public get inputStream(): SpeechSynthesisRequestInputStream {\r\n return this.privInputStream;\r\n }\r\n\r\n /**\r\n * Gets the properties collection for this request.\r\n */\r\n public get properties(): PropertyCollection {\r\n return this.privProperties;\r\n }\r\n\r\n /**\r\n * Sets the pitch of the voice.\r\n */\r\n public set pitch(value: string) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_Pitch, value);\r\n }\r\n\r\n /**\r\n * Sets the speaking rate of the voice.\r\n */\r\n public set rate(value: string) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_Rate, value);\r\n }\r\n\r\n /**\r\n * Sets the volume of the voice.\r\n */\r\n public set volume(value: string) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_Volume, value);\r\n }\r\n\r\n /**\r\n * Sets the style of the voice.\r\n */\r\n public set style(value: string) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_Style, value);\r\n }\r\n\r\n /**\r\n * Sets the temperature of the voice synthesis.\r\n */\r\n public set temperature(value: number) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_Temperature, value.toString());\r\n }\r\n\r\n /**\r\n * Sets the custom lexicon URL.\r\n */\r\n public set customLexiconUrl(value: string) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_CustomLexiconUrl, value);\r\n }\r\n\r\n /**\r\n * Sets the preferred locales for the voice.\r\n */\r\n public set preferLocales(value: string) {\r\n this.privProperties.setProperty(PropertyId.SpeechSynthesisRequest_PreferLocales, value);\r\n }\r\n\r\n /**\r\n * @internal\r\n * Called by InputStream when a text piece is written.\r\n * Buffers text if no callback is registered yet.\r\n */\r\n public onTextPieceReceived(text: string): void {\r\n if (this.privTextPieceCallback) {\r\n this.privTextPieceCallback(text);\r\n } else {\r\n this.privBufferedTextPieces.push(text);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Called by InputStream when it is closed.\r\n * Buffers close event if no callback is registered yet.\r\n */\r\n public onInputStreamClosed(): void {\r\n if (this.privStreamCloseCallback) {\r\n this.privStreamCloseCallback();\r\n } else {\r\n this.privStreamClosedBeforeReady = true;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * Sets the callback for receiving text pieces.\r\n * Flushes any buffered text pieces immediately.\r\n */\r\n public set onTextPiece(callback: (text: string) => void) {\r\n this.privTextPieceCallback = callback;\r\n // Flush buffered text pieces\r\n for (const text of this.privBufferedTextPieces) {\r\n callback(text);\r\n }\r\n this.privBufferedTextPieces = [];\r\n }\r\n\r\n /**\r\n * @internal\r\n * Sets the callback for stream close events.\r\n * Fires immediately if stream was already closed.\r\n */\r\n public set onClose(callback: () => void) {\r\n this.privStreamCloseCallback = callback;\r\n // Fire if stream was already closed before callback was set\r\n if (this.privStreamClosedBeforeReady) {\r\n this.privStreamClosedBeforeReady = false;\r\n callback();\r\n }\r\n }\r\n}\r\n"]}