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iceRecognizer.d.ts","sourcesContent":["import { IAudioSource } from \"../common/Exports.js\";\nimport {\n    CancellationErrorCode,\n    CancellationReason,\n    OutputFormat,\n    PropertyCollection,\n    PropertyId,\n    Recognizer,\n    ResultReason,\n    SpeechRecognitionResult\n} from \"../sdk/Exports.js\";\nimport {\n    DetailedSpeechPhrase,\n    EnumTranslation,\n    IAuthentication,\n    IConnectionFactory,\n    OutputFormatPropertyName,\n    RecognitionStatus,\n    RecognizerConfig,\n    ServiceRecognizerBase,\n    SimpleSpeechPhrase,\n    SpeechHypothesis\n} from \"./Exports.js\";\nimport { SpeechConnectionMessage } from \"./SpeechConnectionMessage.Internal.js\";\n\nexport class ConversationServiceRecognizer extends ServiceRecognizerBase {\n\n    public constructor(\n        authentication: IAuthentication,\n        connectionFactory: IConnectionFactory,\n        audioSource: IAudioSource,\n        recognizerConfig: RecognizerConfig,\n        recognizer: Recognizer) {\n        super(authentication, connectionFactory, audioSource, recognizerConfig, recognizer);\n        this.handleSpeechPhraseMessage = async (textBody: string): Promise<void> => this.handleSpeechPhrase(textBody);\n        this.handleSpeechHypothesisMessage = (textBody: string): void => this.handleSpeechHypothesis(textBody);\n    }\n\n    protected processTypeSpecificMessages(connectionMessage: SpeechConnectionMessage): Promise<boolean> {\n        void connectionMessage;\n        return;\n    }\n\n    protected handleRecognizedCallback(result: SpeechRecognitionResult, offset: number, sessionId: string): void {\n        void result;\n        void offset;\n        void sessionId;\n        return;\n    }\n\n    protected handleRecognizingCallback(result: SpeechRecognitionResult, duration: number, sessionId: string): void {\n        void result;\n        void duration;\n        void sessionId;\n        return;\n    }\n\n    protected async processSpeechMessages(connectionMessage: SpeechConnectionMessage): Promise<boolean> {\n        let processed: boolean = false;\n        switch (connectionMessage.path.toLowerCase()) {\n            case \"speech.hypothesis\":\n            case \"speech.fragment\":\n                if (!!this.handleSpeechHypothesisMessage) {\n                    this.handleSpeechHypothesisMessage(connectionMessage.textBody);\n                }\n                processed = true;\n                break;\n            case \"speech.phrase\":\n                if (!!this.handleSpeechPhraseMessage) {\n                    await this.handleSpeechPhraseMessage(connectionMessage.textBody);\n                }\n                processed = true;\n                break;\n            default:\n                break;\n        }\n        return processed;\n    }\n\n    protected cancelRecognition(\n        sessionId: string,\n        requestId: string,\n        cancellationReason: CancellationReason,\n        errorCode: CancellationErrorCode,\n        error: string): void {\n        // Implementing to allow inheritance\n        void sessionId;\n        void requestId;\n        void cancellationReason;\n        void errorCode;\n        void error;\n    }\n\n    protected async handleSpeechPhrase(textBody: string): Promise<void> {\n\n        const simple: SimpleSpeechPhrase = SimpleSpeechPhrase.fromJSON(textBody, this.privRequestSession.currentTurnAudioOffset);\n        const resultReason: ResultReason = EnumTranslation.implTranslateRecognitionResult(simple.RecognitionStatus);\n        let result: SpeechRecognitionResult;\n        const resultProps: PropertyCollection = new PropertyCollection();\n        resultProps.setProperty(PropertyId.SpeechServiceResponse_JsonResult, textBody);\n\n        this.privRequestSession.onPhraseRecognized(simple.Offset + simple.Duration);\n\n        if (ResultReason.Canceled === resultReason) {\n            const cancelReason: CancellationReason = EnumTranslation.implTranslateCancelResult(simple.RecognitionStatus);\n            const cancellationErrorCode: CancellationErrorCode = EnumTranslation.implTranslateCancelErrorCode(simple.RecognitionStatus);\n\n            await this.cancelRecognitionLocal(\n                cancelReason,\n                cancellationErrorCode,\n                EnumTranslation.implTranslateErrorDetails(cancellationErrorCode));\n\n        } else {\n            if (simple.RecognitionStatus !== RecognitionStatus.EndOfDictation) {\n                if (this.privRecognizerConfig.parameters.getProperty(OutputFormatPropertyName) === OutputFormat[OutputFormat.Simple]) {\n                    result = new SpeechRecognitionResult(\n                        this.privRequestSession.requestId,\n                        resultReason,\n                        simple.DisplayText,\n                        simple.Duration,\n                        simple.Offset,\n                        simple.Language,\n                        simple.LanguageDetectionConfidence,\n                        simple.SpeakerId,\n                        undefined,\n                        simple.asJson(),\n                        resultProps);\n                } else {\n                    const detailed: DetailedSpeechPhrase = DetailedSpeechPhrase.fromJSON(textBody, this.privRequestSession.currentTurnAudioOffset);\n\n                    result = new SpeechRecognitionResult(\n                        this.privRequestSession.requestId,\n                        resultReason,\n                        detailed.Text,\n                        detailed.Duration,\n                        detailed.Offset,\n                        detailed.Language,\n                        detailed.LanguageDetectionConfidence,\n                        detailed.SpeakerId,\n                        undefined,\n                        detailed.asJson(),\n                        resultProps);\n                }\n\n                this.handleRecognizedCallback(result, result.offset, this.privRequestSession.sessionId);\n            }\n        }\n    }\n\n    protected handleSpeechHypothesis(textBody: string): void {\n        const hypothesis: SpeechHypothesis = SpeechHypothesis.fromJSON(textBody, this.privRequestSession.currentTurnAudioOffset);\n        const resultProps: PropertyCollection = new PropertyCollection();\n        resultProps.setProperty(PropertyId.SpeechServiceResponse_JsonResult, textBody);\n\n        const result = new SpeechRecognitionResult(\n            this.privRequestSession.requestId,\n            ResultReason.RecognizingSpeech,\n            hypothesis.Text,\n            hypothesis.Duration,\n            hypothesis.Offset,\n            hypothesis.Language,\n            hypothesis.LanguageDetectionConfidence,\n            hypothesis.SpeakerId,\n            undefined,\n            hypothesis.asJson(),\n            resultProps);\n\n        this.privRequestSession.onHypothesis(hypothesis.Offset);\n\n        this.handleRecognizingCallback(result, hypothesis.Duration, this.privRequestSession.sessionId);\n    }\n}\n"]}