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uB,EAAO,GAC1B,OAAQ,GACJ,KAAK,gBAAgB,MACjB,KAAK,KAAK,SACV,MACJ,KAAK,gBAAgB,QACjB,KAAK,KAAK,WACV,MACJ,KAAK,gBAAgB,MACjB,KAAK,KAAK,QAAS,GACnB,MACJ,QACI,MAAM,EAAU,KAAK,OAAO,OAAO,GACnC,KAAK,KAAK,UAAW,EAAO,EAAS,GAGjD,EAEJ,QAAQ,cAAgB,cACxB,QAAQ,SAAW,cACnB,QAAQ,OAAS","file":"/npm/@ttvtien/snowboy@1.3.3/lib/node/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@ttvtien/snowboy@1.3.3/lib/node/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst stream = require(\"stream\");\nconst path = require(\"path\");\nconst fs = require(\"fs\");\nconst binary = require(\"node-pre-gyp\");\nconst bindingPath = binary.find(path.resolve(path.join(__dirname, '../../package.json')));\nconst SnowboyDetectNative = require(bindingPath).SnowboyDetect;\nvar DetectionResult;\n(function (DetectionResult) {\n    DetectionResult[DetectionResult[\"SILENCE\"] = -2] = \"SILENCE\";\n    DetectionResult[DetectionResult[\"ERROR\"] = -1] = \"ERROR\";\n    DetectionResult[DetectionResult[\"SOUND\"] = 0] = \"SOUND\";\n})(DetectionResult || (DetectionResult = {}));\nvar ModelType;\n(function (ModelType) {\n    ModelType[ModelType[\"PMDL\"] = 0] = \"PMDL\";\n    ModelType[ModelType[\"UMDL\"] = 1] = \"UMDL\";\n})(ModelType || (ModelType = {}));\nclass HotwordModels {\n    constructor() {\n        this.models = [];\n    }\n    add(model) {\n        model.hotwords = [].concat(model.hotwords);\n        model.sensitivity = model.sensitivity || \"0.5\";\n        if (fs.existsSync(model.file) === false) {\n            throw new Error(`Model ${model.file} does not exists.`);\n        }\n        const type = path.extname(model.file).toUpperCase();\n        if (ModelType[type] === ModelType.PMDL && model.hotwords.length > 1) {\n            throw new Error('Personal models can define only one hotword.');\n        }\n        this.models.push(model);\n        this.lookupTable = this.generateHotwordsLookupTable();\n    }\n    get modelString() {\n        return this.models.map((model) => model.file).join();\n    }\n    get sensitivityString() {\n        return this.models.map((model) => model.sensitivity).join();\n    }\n    lookup(index) {\n        const lookupIndex = index - 1;\n        if (lookupIndex < 0 || lookupIndex >= this.lookupTable.length) {\n            throw new Error('Index out of bounds.');\n        }\n        return this.lookupTable[lookupIndex];\n    }\n    numHotwords() {\n        return this.lookupTable.length;\n    }\n    generateHotwordsLookupTable() {\n        return this.models.reduce((hotwords, model) => {\n            return hotwords.concat(model.hotwords);\n        }, new Array());\n    }\n}\nexports.HotwordModels = HotwordModels;\nclass SnowboyDetect extends stream.Writable {\n    constructor(options) {\n        super();\n        this.models = options.models;\n        this.nativeInstance = new SnowboyDetectNative(options.resource, options.models.modelString);\n        if (this.nativeInstance.NumHotwords() !== options.models.numHotwords()) {\n            throw new Error('Loaded hotwords count does not match number of hotwords defined.');\n        }\n        this.nativeInstance.SetSensitivity(options.models.sensitivityString);\n        if (options.audioGain) {\n            this.nativeInstance.SetAudioGain(options.audioGain);\n        }\n        if (options.applyFrontend) {\n            this.nativeInstance.ApplyFrontend(options.applyFrontend);\n        }\n        if (options.highSensitivity) {\n            this.nativeInstance.SetHighSensitivity(options.highSensitivity);\n        }\n    }\n    reset() {\n        return this.nativeInstance.Reset();\n    }\n    runDetection(buffer) {\n        const index = this.nativeInstance.RunDetection(buffer);\n        this.processDetectionResult(index, buffer);\n        return index;\n    }\n    setSensitivity(sensitivity) {\n        this.nativeInstance.SetSensitivity(sensitivity);\n    }\n    setHighSensitivity(highSensitivity) {\n        this.nativeInstance.SetHighSensitivity(highSensitivity);\n    }\n    getSensitivity() {\n        return this.nativeInstance.GetSensitivity();\n    }\n    setAudioGain(gain) {\n        this.nativeInstance.SetAudioGain(gain);\n    }\n    updateModel() {\n        this.nativeInstance.UpdateModel();\n    }\n    numHotwords() {\n        return this.nativeInstance.NumHotwords();\n    }\n    sampleRate() {\n        return this.nativeInstance.SampleRate();\n    }\n    numChannels() {\n        return this.nativeInstance.NumChannels();\n    }\n    bitsPerSample() {\n        return this.nativeInstance.BitsPerSample();\n    }\n    _write(chunk, encoding, callback) {\n        const index = this.nativeInstance.RunDetection(chunk);\n        this.processDetectionResult(index, chunk);\n        return callback();\n    }\n    processDetectionResult(index, buffer) {\n        switch (index) {\n            case DetectionResult.ERROR:\n                this.emit('error');\n                break;\n            case DetectionResult.SILENCE:\n                this.emit('silence');\n                break;\n            case DetectionResult.SOUND:\n                this.emit('sound', buffer);\n                break;\n            default:\n                const hotword = this.models.lookup(index);\n                this.emit('hotword', index, hotword, buffer);\n                break;\n        }\n    }\n}\nexports.SnowboyDetect = SnowboyDetect;\nexports.Detector = SnowboyDetect;\nexports.Models = HotwordModels;\n"]}