@hahnpro/ms-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
1 lines • 3.78 kB
Source Map (JSON)
{"version":3,"sources":["src/common.speech/SynthesisContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAc,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;GAGG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,qBAAqB,CAAwB;IAErD;;;;OAIG;IACI,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIpE;;;OAGG;IACH,IAAW,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,EAEzD;IAEM,MAAM,IAAI,MAAM;IAIhB,mBAAmB,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI;IAKtE,OAAO,CAAC,qBAAqB;CAqBhC","file":"SynthesisContext.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport { AudioOutputFormatImpl } from \"../sdk/Audio/AudioOutputFormat.js\";\nimport { PropertyId, SpeechSynthesizer } from \"../sdk/Exports.js\";\n\n/**\n * Represents the JSON used in the synthesis.context message sent to the speech service.\n * The dynamic grammar is always refreshed from the encapsulated dynamic grammar object.\n */\nexport class SynthesisContext {\n private privContext: { [section: string]: any } = {};\n private privAudioOutputFormat: AudioOutputFormatImpl;\n\n /**\n * Adds a section to the synthesis.context object.\n * @param sectionName Name of the section to add.\n * @param value JSON serializable object that represents the value.\n */\n public setSection(sectionName: string, value: string | object): void {\n this.privContext[sectionName] = value;\n }\n\n /**\n * Sets the audio output format for synthesis context generation.\n * @param format {AudioOutputFormatImpl} the output format\n */\n public set audioOutputFormat(format: AudioOutputFormatImpl) {\n this.privAudioOutputFormat = format;\n }\n\n public toJSON(): string {\n return JSON.stringify(this.privContext);\n }\n\n public setSynthesisSection(speechSynthesizer: SpeechSynthesizer): void {\n const synthesisSection: ISynthesisSection = this.buildSynthesisContext(speechSynthesizer);\n this.setSection(\"synthesis\", synthesisSection);\n }\n\n private buildSynthesisContext(speechSynthesizer: SpeechSynthesizer): ISynthesisSection {\n return {\n audio: {\n metadataOptions: {\n bookmarkEnabled: (!!speechSynthesizer?.bookmarkReached),\n punctuationBoundaryEnabled: speechSynthesizer?.properties.getProperty(\n PropertyId.SpeechServiceResponse_RequestPunctuationBoundary, (!!speechSynthesizer?.wordBoundary)),\n sentenceBoundaryEnabled: speechSynthesizer?.properties.getProperty(\n PropertyId.SpeechServiceResponse_RequestSentenceBoundary, false),\n sessionEndEnabled: true,\n visemeEnabled: (!!speechSynthesizer?.visemeReceived),\n wordBoundaryEnabled: speechSynthesizer?.properties.getProperty(\n PropertyId.SpeechServiceResponse_RequestWordBoundary, (!!speechSynthesizer?.wordBoundary)),\n },\n outputFormat: this.privAudioOutputFormat.requestAudioFormatString,\n },\n language: {\n autoDetection: speechSynthesizer?.autoDetectSourceLanguage\n }\n } as ISynthesisSection;\n }\n}\n\ninterface ISynthesisSection {\n audio: {\n outputFormat: string;\n metadataOptions: {\n bookmarkEnabled: boolean;\n wordBoundaryEnabled: string;\n punctuationBoundaryEnabled: string;\n visemeEnabled: boolean;\n sentenceBoundaryEnabled: string;\n sessionEndEnabled: boolean;\n };\n };\n language: {\n autoDetection: boolean;\n };\n}\n"]}