UNPKG

microsoft-cognitiveservices-speech-sdk

Version:
1 lines 4.85 kB
{"version":3,"sources":["src/common.speech/EnumTranslation.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,qBAAa,eAAe;WACV,8BAA8B,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,GAAE,OAAe,GAAG,YAAY;WA0BzH,yBAAyB,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,kBAAkB;WAoBnF,4BAA4B,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,qBAAqB;WAwBzF,yBAAyB,CAAC,qBAAqB,EAAE,qBAAqB,GAAG,MAAM;CAkBhG","file":"EnumTranslation.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n CancellationErrorCode,\r\n CancellationReason,\r\n ResultReason\r\n} from \"../sdk/Exports.js\";\r\nimport { RecognitionStatus } from \"./Exports.js\";\r\n\r\nexport class EnumTranslation {\r\n public static implTranslateRecognitionResult(recognitionStatus: RecognitionStatus, expectEndOfDictation: boolean = false): ResultReason {\r\n let reason = ResultReason.Canceled;\r\n switch (recognitionStatus) {\r\n case RecognitionStatus.Success:\r\n reason = ResultReason.RecognizedSpeech;\r\n break;\r\n case RecognitionStatus.EndOfDictation:\r\n // If we need the result in EndOfDictation (typically some session level result),\r\n // translate into RecognizedSpeech, otherwise NoMatch\r\n reason = expectEndOfDictation ? ResultReason.RecognizedSpeech : ResultReason.NoMatch;\r\n break;\r\n case RecognitionStatus.NoMatch:\r\n case RecognitionStatus.InitialSilenceTimeout:\r\n case RecognitionStatus.BabbleTimeout:\r\n reason = ResultReason.NoMatch;\r\n break;\r\n case RecognitionStatus.Error:\r\n case RecognitionStatus.BadRequest:\r\n case RecognitionStatus.Forbidden:\r\n default:\r\n reason = ResultReason.Canceled;\r\n break;\r\n }\r\n return reason;\r\n }\r\n\r\n public static implTranslateCancelResult(recognitionStatus: RecognitionStatus): CancellationReason {\r\n let reason = CancellationReason.EndOfStream;\r\n switch (recognitionStatus) {\r\n case RecognitionStatus.Success:\r\n case RecognitionStatus.EndOfDictation:\r\n case RecognitionStatus.NoMatch:\r\n reason = CancellationReason.EndOfStream;\r\n break;\r\n case RecognitionStatus.InitialSilenceTimeout:\r\n case RecognitionStatus.BabbleTimeout:\r\n case RecognitionStatus.Error:\r\n case RecognitionStatus.BadRequest:\r\n case RecognitionStatus.Forbidden:\r\n default:\r\n reason = CancellationReason.Error;\r\n break;\r\n }\r\n return reason;\r\n }\r\n\r\n public static implTranslateCancelErrorCode(recognitionStatus: RecognitionStatus): CancellationErrorCode {\r\n let reason: CancellationErrorCode = CancellationErrorCode.NoError;\r\n switch (recognitionStatus) {\r\n case RecognitionStatus.Error:\r\n reason = CancellationErrorCode.ServiceError;\r\n break;\r\n case RecognitionStatus.TooManyRequests:\r\n reason = CancellationErrorCode.TooManyRequests;\r\n break;\r\n case RecognitionStatus.BadRequest:\r\n reason = CancellationErrorCode.BadRequestParameters;\r\n break;\r\n case RecognitionStatus.Forbidden:\r\n reason = CancellationErrorCode.Forbidden;\r\n break;\r\n default:\r\n reason = CancellationErrorCode.NoError;\r\n break;\r\n }\r\n\r\n return reason;\r\n\r\n }\r\n\r\n public static implTranslateErrorDetails(cancellationErrorCode: CancellationErrorCode): string {\r\n let errorDetails: string = \"The speech service encountered an internal error and could not continue.\";\r\n switch (cancellationErrorCode) {\r\n case CancellationErrorCode.Forbidden:\r\n errorDetails = \"The recognizer is using a free subscription that ran out of quota.\";\r\n break;\r\n case CancellationErrorCode.BadRequestParameters:\r\n errorDetails = \"Invalid parameter or unsupported audio format in the request.\";\r\n break;\r\n case CancellationErrorCode.TooManyRequests:\r\n errorDetails = \"The number of parallel requests exceeded the number of allowed concurrent transcriptions.\";\r\n break;\r\n default:\r\n break;\r\n }\r\n return errorDetails;\r\n }\r\n\r\n}\r\n"]}