{"ast":null,"code":"\"use strict\";\n\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.RiffPcmEncoder = void 0;\nclass RiffPcmEncoder {\n constructor(actualSampleRate, desiredSampleRate) {\n this.privActualSampleRate = actualSampleRate;\n this.privDesiredSampleRate = desiredSampleRate;\n }\n encode(actualAudioFrame) {\n const audioFrame = this.downSampleAudioFrame(actualAudioFrame, this.privActualSampleRate, this.privDesiredSampleRate);\n if (!audioFrame) {\n return null;\n }\n const audioLength = audioFrame.length * 2;\n const buffer = new ArrayBuffer(audioLength);\n const view = new DataView(buffer);\n this.floatTo16BitPCM(view, 0, audioFrame);\n return buffer;\n }\n setString(view, offset, str) {\n for (let i = 0; i < str.length; i++) {\n view.setUint8(offset + i, str.charCodeAt(i));\n }\n }\n floatTo16BitPCM(view, offset, input) {\n for (let i = 0; i < input.length; i++, offset += 2) {\n const s = Math.max(-1, Math.min(1, input[i]));\n view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);\n }\n }\n downSampleAudioFrame(srcFrame, srcRate, dstRate) {\n if (!srcFrame) {\n return null;\n }\n if (dstRate === srcRate || dstRate > srcRate) {\n return srcFrame;\n }\n const ratio = srcRate / dstRate;\n const dstLength = Math.round(srcFrame.length / ratio);\n const dstFrame = new Float32Array(dstLength);\n let srcOffset = 0;\n let dstOffset = 0;\n while (dstOffset < dstLength) {\n const nextSrcOffset = Math.round((dstOffset + 1) * ratio);\n let accum = 0;\n let count = 0;\n while (srcOffset < nextSrcOffset && srcOffset < srcFrame.length) {\n accum += srcFrame[srcOffset++];\n count++;\n }\n dstFrame[dstOffset++] = accum / count;\n }\n return dstFrame;\n }\n}\nexports.RiffPcmEncoder = RiffPcmEncoder;","map":{"version":3,"names":["Object","defineProperty","exports","value","RiffPcmEncoder","constructor","actualSampleRate","desiredSampleRate","privActualSampleRate","privDesiredSampleRate","encode","actualAudioFrame","audioFrame","downSampleAudioFrame","audioLength","length","buffer","ArrayBuffer","view","DataView","floatTo16BitPCM","setString","offset","str","i","setUint8","charCodeAt","input","s","Math","max","min","setInt16","srcFrame","srcRate","dstRate","ratio","dstLength","round","dstFrame","Float32Array","srcOffset","dstOffset","nextSrcOffset","accum","count"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common/RiffPcmEncoder.js"],"sourcesContent":["\"use strict\";\n// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.RiffPcmEncoder = void 0;\nclass RiffPcmEncoder {\n constructor(actualSampleRate, desiredSampleRate) {\n this.privActualSampleRate = actualSampleRate;\n this.privDesiredSampleRate = desiredSampleRate;\n }\n encode(actualAudioFrame) {\n const audioFrame = this.downSampleAudioFrame(actualAudioFrame, this.privActualSampleRate, this.privDesiredSampleRate);\n if (!audioFrame) {\n return null;\n }\n const audioLength = audioFrame.length * 2;\n const buffer = new ArrayBuffer(audioLength);\n const view = new DataView(buffer);\n this.floatTo16BitPCM(view, 0, audioFrame);\n return buffer;\n }\n setString(view, offset, str) {\n for (let i = 0; i < str.length; i++) {\n view.setUint8(offset + i, str.charCodeAt(i));\n }\n }\n floatTo16BitPCM(view, offset, input) {\n for (let i = 0; i < input.length; i++, offset += 2) {\n const s = Math.max(-1, Math.min(1, input[i]));\n view.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);\n }\n }\n downSampleAudioFrame(srcFrame, srcRate, dstRate) {\n if (!srcFrame) {\n return null;\n }\n if (dstRate === srcRate || dstRate > srcRate) {\n return srcFrame;\n }\n const ratio = srcRate / dstRate;\n const dstLength = Math.round(srcFrame.length / ratio);\n const dstFrame = new Float32Array(dstLength);\n let srcOffset = 0;\n let dstOffset = 0;\n while (dstOffset < dstLength) {\n const nextSrcOffset = Math.round((dstOffset + 1) * ratio);\n let accum = 0;\n let count = 0;\n while (srcOffset < nextSrcOffset && srcOffset < srcFrame.length) {\n accum += srcFrame[srcOffset++];\n count++;\n }\n dstFrame[dstOffset++] = accum / count;\n }\n return dstFrame;\n }\n}\nexports.RiffPcmEncoder = RiffPcmEncoder;\n\n"],"mappings":"AAAA,YAAY;;AACZ;AACA;AACAA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,cAAc,GAAG,KAAK,CAAC;AAC/B,MAAMA,cAAc,CAAC;EACjBC,WAAWA,CAACC,gBAAgB,EAAEC,iBAAiB,EAAE;IAC7C,IAAI,CAACC,oBAAoB,GAAGF,gBAAgB;IAC5C,IAAI,CAACG,qBAAqB,GAAGF,iBAAiB;EAClD;EACAG,MAAMA,CAACC,gBAAgB,EAAE;IACrB,MAAMC,UAAU,GAAG,IAAI,CAACC,oBAAoB,CAACF,gBAAgB,EAAE,IAAI,CAACH,oBAAoB,EAAE,IAAI,CAACC,qBAAqB,CAAC;IACrH,IAAI,CAACG,UAAU,EAAE;MACb,OAAO,IAAI;IACf;IACA,MAAME,WAAW,GAAGF,UAAU,CAACG,MAAM,GAAG,CAAC;IACzC,MAAMC,MAAM,GAAG,IAAIC,WAAW,CAACH,WAAW,CAAC;IAC3C,MAAMI,IAAI,GAAG,IAAIC,QAAQ,CAACH,MAAM,CAAC;IACjC,IAAI,CAACI,eAAe,CAACF,IAAI,EAAE,CAAC,EAAEN,UAAU,CAAC;IACzC,OAAOI,MAAM;EACjB;EACAK,SAASA,CAACH,IAAI,EAAEI,MAAM,EAAEC,GAAG,EAAE;IACzB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,GAAG,CAACR,MAAM,EAAES,CAAC,EAAE,EAAE;MACjCN,IAAI,CAACO,QAAQ,CAACH,MAAM,GAAGE,CAAC,EAAED,GAAG,CAACG,UAAU,CAACF,CAAC,CAAC,CAAC;IAChD;EACJ;EACAJ,e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