microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 6.18 kB
Source Map (JSON)
{"version":3,"sources":["src/common.speech/SpeechSynthesisAdapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAEH,gCAAgC,EAEhC,qBAAqB,EACrB,8BAA8B,EAC9B,oCAAoC,EACpC,iBAAiB,EAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,eAAe,EACf,2BAA2B,EAC3B,oBAAoB,EACpB,iBAAiB,EACpB,MAAM,cAAc,CAAC;AAEtB,qBAAa,sBAAuB,SAAQ,oBAAoB;IAC5D,OAAO,CAAC,qBAAqB,CAAoB;gBAE7C,cAAc,EAAE,eAAe,EAC/B,iBAAiB,EAAE,2BAA2B,EAC9C,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,gBAAgB,EAAE,iBAAiB;IAMvC,SAAS,CAAC,mCAAmC,IAAI,IAAI;IAIrD,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAarD,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAiBlD,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI;IAUnE,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI;IAcnE,SAAS,CAAC,cAAc,CAAC,qBAAqB,EAAE,oCAAoC,GAAG,IAAI;IAW3F,SAAS,CAAC,gBAAgB,CAAC,eAAe,EAAE,8BAA8B,GAAG,IAAI;IAWjF,SAAS,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,gCAAgC,GAAG,IAAI;CAUzF","file":"SpeechSynthesisAdapter.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport { IAudioDestination } from \"../common/Exports.js\";\r\nimport {\r\n ResultReason,\r\n SpeechSynthesisBookmarkEventArgs,\r\n SpeechSynthesisEventArgs,\r\n SpeechSynthesisResult,\r\n SpeechSynthesisVisemeEventArgs,\r\n SpeechSynthesisWordBoundaryEventArgs,\r\n SpeechSynthesizer,\r\n Synthesizer,\r\n} from \"../sdk/Exports.js\";\r\nimport {\r\n IAuthentication,\r\n ISynthesisConnectionFactory,\r\n SynthesisAdapterBase,\r\n SynthesizerConfig\r\n} from \"./Exports.js\";\r\n\r\nexport class SpeechSynthesisAdapter extends SynthesisAdapterBase {\r\n private privSpeechSynthesizer: SpeechSynthesizer;\r\n public constructor(\r\n authentication: IAuthentication,\r\n connectionFactory: ISynthesisConnectionFactory,\r\n synthesizerConfig: SynthesizerConfig,\r\n speechSynthesizer: SpeechSynthesizer,\r\n audioDestination: IAudioDestination) {\r\n super(authentication, connectionFactory, synthesizerConfig, audioDestination);\r\n this.privSpeechSynthesizer = speechSynthesizer;\r\n this.privSynthesizer = speechSynthesizer as Synthesizer;\r\n }\r\n\r\n protected setSynthesisContextSynthesisSection(): void {\r\n this.privSynthesisContext.setSynthesisSection(this.privSpeechSynthesizer);\r\n }\r\n\r\n protected onSynthesisStarted(requestId: string): void {\r\n const synthesisStartEventArgs: SpeechSynthesisEventArgs = new SpeechSynthesisEventArgs(\r\n new SpeechSynthesisResult(\r\n requestId,\r\n ResultReason.SynthesizingAudioStarted,\r\n )\r\n );\r\n\r\n if (!!this.privSpeechSynthesizer.synthesisStarted) {\r\n this.privSpeechSynthesizer.synthesisStarted(this.privSpeechSynthesizer, synthesisStartEventArgs);\r\n }\r\n }\r\n\r\n protected onSynthesizing(audio: ArrayBuffer): void {\r\n if (!!this.privSpeechSynthesizer.synthesizing) {\r\n try {\r\n const audioWithHeader = this.privSynthesisTurn.audioOutputFormat.addHeader(audio);\r\n const ev: SpeechSynthesisEventArgs = new SpeechSynthesisEventArgs(\r\n new SpeechSynthesisResult(\r\n this.privSynthesisTurn.requestId,\r\n ResultReason.SynthesizingAudio,\r\n audioWithHeader));\r\n this.privSpeechSynthesizer.synthesizing(this.privSpeechSynthesizer, ev);\r\n } catch (error) {\r\n // Not going to let errors in the event handler\r\n // trip things up.\r\n }\r\n }\r\n }\r\n\r\n protected onSynthesisCancelled(result: SpeechSynthesisResult): void {\r\n if (!!this.privSpeechSynthesizer.SynthesisCanceled) {\r\n const cancelEvent: SpeechSynthesisEventArgs = new SpeechSynthesisEventArgs(result);\r\n try {\r\n this.privSpeechSynthesizer.SynthesisCanceled(this.privSpeechSynthesizer, cancelEvent);\r\n /* eslint-disable no-empty */\r\n } catch { }\r\n }\r\n }\r\n\r\n protected onSynthesisCompleted(result: SpeechSynthesisResult): void {\r\n if (this.privSpeechSynthesizer.synthesisCompleted) {\r\n try {\r\n this.privSpeechSynthesizer.synthesisCompleted(\r\n this.privSpeechSynthesizer,\r\n new SpeechSynthesisEventArgs(result)\r\n );\r\n } catch (e) {\r\n // Not going to let errors in the event handler\r\n // trip things up.\r\n }\r\n }\r\n }\r\n\r\n protected onWordBoundary(wordBoundaryEventArgs: SpeechSynthesisWordBoundaryEventArgs): void {\r\n if (!!this.privSpeechSynthesizer.wordBoundary) {\r\n try {\r\n this.privSpeechSynthesizer.wordBoundary(this.privSpeechSynthesizer, wordBoundaryEventArgs);\r\n } catch (error) {\r\n // Not going to let errors in the event handler\r\n // trip things up.\r\n }\r\n }\r\n }\r\n\r\n protected onVisemeReceived(visemeEventArgs: SpeechSynthesisVisemeEventArgs): void {\r\n if (!!this.privSpeechSynthesizer.visemeReceived) {\r\n try {\r\n this.privSpeechSynthesizer.visemeReceived(this.privSpeechSynthesizer, visemeEventArgs);\r\n } catch (error) {\r\n // Not going to let errors in the event handler\r\n // trip things up.\r\n }\r\n }\r\n }\r\n\r\n protected onBookmarkReached(bookmarkEventArgs: SpeechSynthesisBookmarkEventArgs): void {\r\n if (!!this.privSpeechSynthesizer.bookmarkReached) {\r\n try {\r\n this.privSpeechSynthesizer.bookmarkReached(this.privSpeechSynthesizer, bookmarkEventArgs);\r\n } catch (error) {\r\n // Not going to let errors in the event handler\r\n // trip things up.\r\n }\r\n }\r\n }\r\n}\r\n"]}