UNPKG

@azure/communication-call-automation

Version:
117 lines (116 loc) 4.82 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var streamingData_exports = {}; __export(streamingData_exports, { StreamingData: () => StreamingData }); module.exports = __toCommonJS(streamingData_exports); var import_communication_common = require("@azure/communication-common"); class StreamingData { // Kind of the streaming data ex.AudioData, AudioMetadata, TranscriptionData, TranscriptionMetadata. static streamingKind; /** Parses a encoded json string or buffer into a StreamingData object, which can be one of the following subtypes: AudioData, AudioMetadata, TranscriptionData, or TranscriptionMetadata. */ static parse(data) { return StreamingData.parseStreamingData(data); } // Get Streaming data Kind. static getStreamingKind() { return StreamingData.streamingKind; } /** Parses a encoded json string or buffer into a StreamingData object, which can be one of the following subtypes: AudioData, AudioMetadata, TranscriptionData, or TranscriptionMetadata. */ static parseStreamingData(data) { let stringJson; if (typeof data === "string") { stringJson = data; } else { const decoder = new TextDecoder(); stringJson = decoder.decode(data); } const jsonObject = JSON.parse(stringJson); const kind = jsonObject.kind; switch (kind) { case "TranscriptionMetadata": { const transcriptionMetadata = { subscriptionId: jsonObject.transcriptionMetadata.subscriptionId, locale: jsonObject.transcriptionMetadata.locale, callConnectionId: jsonObject.transcriptionMetadata.callConnectionId, correlationId: jsonObject.transcriptionMetadata.correlationId, speechRecognitionModelEndpointId: jsonObject.transcriptionMetadata.speechRecognitionModelEndpointId }; StreamingData.streamingKind = kind; return transcriptionMetadata; } case "TranscriptionData": { const transcriptionData = { text: jsonObject.transcriptionData.text, format: jsonObject.transcriptionData.format, confidence: jsonObject.transcriptionData.confidence, offsetInTicks: jsonObject.transcriptionData.offset, durationInTicks: jsonObject.transcriptionData.duration, words: jsonObject.transcriptionData.words.map( (word) => ({ text: word.text, offsetInTicks: word.offset, durationInTicks: word.duration }) ), participant: (0, import_communication_common.createIdentifierFromRawId)(jsonObject.transcriptionData.participantRawID), resultState: jsonObject.transcriptionData.resultStatus }; StreamingData.streamingKind = kind; return transcriptionData; } case "AudioMetadata": { const audioMetadata = { subscriptionId: jsonObject.audioMetadata.subscriptionId, encoding: jsonObject.audioMetadata.encoding, sampleRate: jsonObject.audioMetadata.sampleRate, channels: jsonObject.audioMetadata.channels }; StreamingData.streamingKind = kind; return audioMetadata; } case "AudioData": { const audioData = { data: jsonObject.audioData.data, timestamp: jsonObject.audioData.timestamp, isSilent: jsonObject.audioData.silent, participant: jsonObject.audioData.participantRawID !== void 0 ? (0, import_communication_common.createIdentifierFromRawId)(jsonObject.audioData.participantRawID) : void 0 }; StreamingData.streamingKind = kind; return audioData; } case "DtmfData": { const dtmfData = { data: jsonObject.dtmfData.data }; StreamingData.streamingKind = kind; return dtmfData; } default: throw new Error("Unknown data kind: " + jsonObject.kind); } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { StreamingData }); //# sourceMappingURL=streamingData.js.map