augnitorecorder
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -738,3 +738,3 @@ function _regeneratorRuntime() { | ||
// worklet-thread | ||
var worklet = "class MyAudioWorkletProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n this.accumulator = [];\n this.reset();\n this.isProcessing = true;\n // message received from main-thread\n this.port.onmessage = (e) => {\n console.log(\"Worklet received event: \", e.data);\n if (this.sampleSize > 0) {\n this.accumulator.push(this.sampleVal / this.sampleSize);\n }\n if (e.data == \"PAUSE\" || e.data == \"STOP\") {\n // append silence to get last word ASR.\n const silenceSize = 16000 * 2;\n for (let i = 0; i < silenceSize; i++) {\n this.accumulator.push(0);\n }\n }\n this.send();\n if (e.data == \"STOP\") {\n // message sent to main-thread\n this.port.postMessage(\"DONE\");\n this.isProcessing = false;\n }\n };\n }\n\n static get parameterDescriptors() {\n return [\n {\n name: \"scale\",\n defaultValue: 1,\n minValue: 1,\n maxValue: 6,\n },\n {\n name: \"bufferSizeInterval\",\n defaultValue: 1,\n minValue: 1,\n maxValue: 100,\n },\n ];\n }\n\n // 128 frames\n process(inputList, outputList, params) {\n const input = inputList[0];\n if (input && input.length && input[0].length) {\n const output = outputList[0];\n const scale = params.scale[0];\n const bufferSizeInterval = params[\"bufferSizeInterval\"][0];\n // console.log(\"BufferSizeInterval\", bufferSizeInterval);\n // Jackpot\n input[0].forEach((float32Element) => {\n const int16Element = Math.min(1, Math.max(-1, float32Element)) * 0x7fff;\n this.sampleVal += int16Element;\n this.sampleSize++;\n if (this.sampleSize == scale) {\n this.accumulator.push(this.sampleVal / this.sampleSize);\n this.reset();\n }\n\n // Comment this when streaming microphone audio\n // output[0][index] = float32Element;\n });\n if (this.accumulator.length >= 125 * 128 * bufferSizeInterval) {\n this.send();\n }\n }\n return this.isProcessing;\n }\n\n send() {\n if (this.accumulator.length == 0) return;\n const audioData = new Int16Array(this.accumulator);\n // message sent to main-thread - transferrable\n this.port.postMessage(audioData.buffer, [audioData.buffer]);\n this.accumulator = [];\n this.reset();\n }\n\n reset() {\n this.sampleVal = 0;\n this.sampleSize = 0;\n }\n}\n\nregisterProcessor(\"worklet-processor\", MyAudioWorkletProcessor);"; | ||
var worklet = "class MyAudioWorkletProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n this.accumulator = [];\n this.reset();\n this.isProcessing = true;\n // message received from main-thread\n this.port.onmessage = (e) => {\n console.log(\"Worklet received event: \", e.data);\n if (this.sampleSize > 0) {\n this.accumulator.push(this.sampleVal / this.sampleSize);\n }\n if (e.data == \"PAUSE\" || e.data == \"STOP\") {\n // append silence to get last word ASR.\n const silenceSize = 16000 * 2;\n for (let i = 0; i < silenceSize; i++) {\n this.accumulator.push(0);\n }\n }\n this.send();\n this.reset();\n if (e.data == \"STOP\") {\n // message sent to main-thread\n this.port.postMessage(\"DONE\");\n this.isProcessing = false;\n }\n };\n }\n\n static get parameterDescriptors() {\n return [\n {\n name: \"sampleRate\",\n defaultValue: SAMPLE_RATE,\n minValue: SAMPLE_RATE,\n maxValue: 6 * SAMPLE_RATE,\n },\n {\n name: \"bufferSizeInterval\",\n defaultValue: 1,\n minValue: 1,\n maxValue: 100,\n },\n ];\n }\n\n // 128 frames\n process(inputList, outputList, params) {\n const input = inputList[0];\n if (input && input.length && input[0].length) {\n const output = outputList[0];\n const inputSampleRate = params.sampleRate[0];\n const sampleRatio = inputSampleRate / SAMPLE_RATE\n const bufferSizeInterval = params[\"bufferSizeInterval\"][0];\n // console.log(\"BufferSizeInterval\", bufferSizeInterval);\n // Jackpot\n input[0].forEach((float32Element, index) => {\n const int16Element = Math.min(1, Math.max(-1, float32Element)) * 0x7fff;\n this.sampleVal += int16Element;\n this.sampleSize += 1;\n if (this.sampleSize >= sampleRatio) {\n const fraction = this.sampleSize - sampleRatio \n this.sampleVal -= fraction * int16Element;\n\n this.accumulator.push(this.sampleVal / sampleRatio);\n \n this.sampleVal = fraction * int16Element;\n this.sampleSize = fraction;\n }\n\n // Comment this when streaming microphone audio\n // output[0][index] = float32Element;\n });\n if (this.accumulator.length >= 125 * 128 * bufferSizeInterval) {\n this.send();\n }\n }\n return this.isProcessing;\n }\n\n send() {\n if (this.accumulator.length == 0) return;\n const audioData = new Int16Array(this.accumulator);\n // message sent to main-thread - transferrable\n this.port.postMessage(audioData.buffer, [audioData.buffer]);\n this.accumulator = [];\n }\n\n reset() {\n this.sampleVal = 0;\n this.sampleSize = 0;\n }\n}\n\nregisterProcessor(\"worklet-processor\", MyAudioWorkletProcessor);"; | ||
@@ -921,3 +921,3 @@ // main-thread | ||
var _this = this; | ||
var scaleParam, scale, bufferSizeIntervalParam; | ||
var sampleRateParam, bufferSizeIntervalParam; | ||
return _regeneratorRuntime().wrap(function _callee5$(_context5) { | ||
@@ -931,5 +931,4 @@ while (1) switch (_context5.prev = _context5.next) { | ||
this.processorNode = new AudioWorkletNode(this.audioContext, WORKLET_PROCESSOR); | ||
scaleParam = this.processorNode.parameters.get("scale"); | ||
scale = Math.ceil(this.audioContext.sampleRate / SAMPLE_RATE); | ||
scaleParam.setValueAtTime(scale, this.audioContext.currentTime); | ||
sampleRateParam = this.processorNode.parameters.get("sampleRate"); | ||
sampleRateParam.setValueAtTime(this.audioContext.sampleRate, this.audioContext.currentTime); | ||
bufferSizeIntervalParam = this.processorNode.parameters.get("bufferSizeInterval"); | ||
@@ -963,13 +962,13 @@ bufferSizeIntervalParam.setValueAtTime(this.bufferSizeInterval, this.audioContext.currentTime); | ||
}; | ||
_context5.next = 15; | ||
_context5.next = 14; | ||
break; | ||
case 12: | ||
_context5.prev = 12; | ||
case 11: | ||
_context5.prev = 11; | ||
_context5.t0 = _context5["catch"](0); | ||
console.error("Error: Unable to create worklet node: ", _context5.t0); | ||
case 15: | ||
case 14: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
}, _callee5, this, [[0, 12]]); | ||
}, _callee5, this, [[0, 11]]); | ||
})); | ||
@@ -976,0 +975,0 @@ function createProcessorNode() { |
{ | ||
"name": "augnitorecorder", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"description": "Audio recorder and streamer compatible with any browser", | ||
@@ -5,0 +5,0 @@ "main": "dist/augnitoRecorder.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129625
4
1323