Files
ArtPlayer/docs/compiled/artplayer-plugin-asr.legacy.js
T
Harvey Zack 5d7710979d fix: rename cleanupTimeout to hideTimeout for consistency in ASR plugin
Refactor artplayerPluginAsr: Enhance audio capture and processing

- Introduced gainNode for audio output management.
- Added mediaStream and mediaStreamSource for fallback audio capture.
- Refactored startCapture and stopCapture functions for better clarity and error handling.
- Improved audio source setup with a dedicated function for capturing audio from video.
- Ensured proper disconnection of audio nodes and cleanup of resources on destroy.

feat: enhance ASR plugin with improved subtitle handling and styling

fix: rename autoClearTimer to hideTimer for consistency in ASR plugin

Update asr.js

feat: refactor ASR plugin to improve audio chunk handling and WebSocket management

Update asr.js

fix: rename autoClearTimeout to cleanupTimeout for consistency

Update asr.js

feat: refactor ASR handling and improve WebSocket management

Update index.js

feat: add append and clear functions to enhance audio chunk handling

Update asr.js

Update asr.js

feat: release version 2.0.0 of artplayer-plugin-asr

- Implemented core functionality for audio recording using AudioWorklet.
- Added support for configurable audio capture interval and sample rate.
- Introduced WAV encoding for recorded audio chunks.
- Created a new plugin structure with proper TypeScript definitions.
- Added legacy support for older environments.
- Updated package.json with necessary metadata and export configurations.
- Included comprehensive inline documentation for better maintainability.
2025-05-23 00:09:13 +08:00

8 lines
17 KiB
JavaScript

/*!
* artplayer-plugin-asr.js v2.0.0
* Github: https://github.com/zhw2590582/ArtPlayer
* (c) 2017-2025 Harvey Zack
* Released under the MIT License.
*/
!function(e,t,r,n,o,i,u,a){var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof c[n]&&c[n],f=s.i||{},l=s.cache||{},p="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,r){if(!l[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof c[n]&&c[n];if(!r&&i)return i(t,!0);if(s)return s(t,!0);if(p&&"string"==typeof t)return p(t);var u=Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}f.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},f.cache={};var a=l[t]=new d.Module(t);e[t][0].call(a.exports,f,a,a.exports,c)}return l[t].exports;function f(e){var t=f.resolve(e);return!1===t?{}:d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.require=p,this.exports={}},d.modules=e,d.cache=l,d.parent=s,d.distDir=void 0,d.publicUrl=void 0,d.devServer=void 0,d.i=f,d.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(d,"root",{get:function(){return c[n]}}),c[n]=d;for(var y=0;y<t.length;y++)d(t[y]);if(r){var _=d(r);"object"==typeof exports&&"undefined"!=typeof module?module.exports=_:"function"==typeof define&&define.amd&&define(function(){return _})}}({"98QZN":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"default",function(){return a});var i=e("@swc/helpers/cjs/_async_to_generator.cjs"),u=e("@swc/helpers/cjs/_ts_generator.cjs");function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.interval,r=void 0===t?5e3:t,n=e.sampleRate,o=void 0===n?16e3:n,a=e.callback,c=void 0===a?function(){return null}:a;return function(e){var t=!1,n=null,a=null,s=null,f=[],l=null,p=function(){var e=new Blob(["\n class RecorderProcessor extends AudioWorkletProcessor {\n process(inputs) {\n const input = inputs[0];\n if (input && input[0]) {\n this.port.postMessage(input[0]);\n }\n return true;\n }\n }\n registerProcessor('recorder-processor', RecorderProcessor);\n "],{type:"application/javascript"});return URL.createObjectURL(e)};function d(){return(d=(0,i._)(function(){var d;return(0,u._)(this,function(y){switch(y.label){case 0:if(t)return[2];if(t=!0,"suspended"!==(n=new(window.AudioContext||window.webkitAudioContext)({sampleRate:o})).state)return[3,2];return[4,n.resume()];case 1:y.sent(),y.label=2;case 2:return a||(a=n.createMediaElementSource(e.video)).connect(n.destination),d=p(),[4,n.audioWorklet.addModule(d)];case 3:return y.sent(),URL.revokeObjectURL(d),(s=new AudioWorkletNode(n,"recorder-processor")).port.onmessage=function(e){f.push(new Float32Array(e.data))},a.connect(s).connect(n.destination),l=setInterval((0,i._)(function(){return(0,u._)(this,function(e){switch(e.label){case 0:if(0===f.length)return[2];return[4,(function(e,t){var r,n,o=(r=new Float32Array(e.reduce(function(e,t){return e+t.length},0)),n=0,e.forEach(function(e){r.set(e,n),n+=e.length}),r),i=2*o.length,u=new ArrayBuffer(44+i),a=new DataView(u);function c(e,t){for(var r=0;r<t.length;r++)a.setUint8(e+r,t.charCodeAt(r))}c(0,"RIFF"),a.setUint32(4,36+i,!0),c(8,"WAVE"),c(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,t,!0),a.setUint32(28,2*t,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),c(36,"data"),a.setUint32(40,i,!0);var s=function(e){for(var t=e.length,r=new ArrayBuffer(2*t),n=new DataView(r),o=0;o<t;o++){var i=Math.max(-1,Math.min(1,e[o]));n.setInt16(2*o,i<0?32768*i:32767*i,!0)}return r}(o);return new Uint8Array(u).set(new Uint8Array(s),44),new Blob([a],{type:"audio/wav"})})(f,n.sampleRate).arrayBuffer()];case 1:return[4,c(e.sent())];case 2:return e.sent(),f=[],[2]}})}),r),[2]}})})).apply(this,arguments)}function y(){t&&(t=!1,l&&clearInterval(l),s&&s.disconnect(),s=null,f=[])}return e.on("play",function(){return d.apply(this,arguments)}),e.on("pause",y),e.on("destroy",y),{name:"artplayerPluginAsr",destroy:y}}}"undefined"!=typeof window&&(window.artplayerPluginAsr=a)},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],cZn0e:[function(e,t,r,n){"use strict";function o(e,t,r,n,o,i,u){try{var a=e[i](u),c=a.value}catch(e){r(e);return}a.done?t(c):Promise.resolve(c).then(n,o)}r._=function(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var u=e.apply(t,r);function a(e){o(u,n,i,a,c,"next",e)}function c(e){o(u,n,i,a,c,"throw",e)}a(void 0)})}}},{}],eltGh:[function(e,t,r,n){"use strict";r._=e("eb260df52bffddd").__generator},{eb260df52bffddd:"6yrAu"}],"6yrAu":[function(e,t,r,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(r),o.export(r,"__extends",function(){return a}),o.export(r,"__assign",function(){return c}),o.export(r,"__rest",function(){return s}),o.export(r,"__decorate",function(){return f}),o.export(r,"__param",function(){return l}),o.export(r,"__esDecorate",function(){return p}),o.export(r,"__runInitializers",function(){return d}),o.export(r,"__propKey",function(){return y}),o.export(r,"__setFunctionName",function(){return _}),o.export(r,"__metadata",function(){return h}),o.export(r,"__awaiter",function(){return v}),o.export(r,"__generator",function(){return b}),o.export(r,"__createBinding",function(){return w}),o.export(r,"__exportStar",function(){return m}),o.export(r,"__values",function(){return g}),o.export(r,"__read",function(){return j}),o.export(r,"__spread",function(){return x}),o.export(r,"__spreadArrays",function(){return O}),o.export(r,"__spreadArray",function(){return P}),o.export(r,"__await",function(){return S}),o.export(r,"__asyncGenerator",function(){return E}),o.export(r,"__asyncDelegator",function(){return A}),o.export(r,"__asyncValues",function(){return R}),o.export(r,"__makeTemplateObject",function(){return I}),o.export(r,"__importStar",function(){return M}),o.export(r,"__importDefault",function(){return U}),o.export(r,"__classPrivateFieldGet",function(){return k}),o.export(r,"__classPrivateFieldSet",function(){return F}),o.export(r,"__classPrivateFieldIn",function(){return C}),o.export(r,"__addDisposableResource",function(){return N}),o.export(r,"__disposeResources",function(){return B}),o.export(r,"__rewriteRelativeImportExtension",function(){return G});var i=e("@swc/helpers/cjs/_type_of.cjs"),u=function(e,t){return(u=Object.setPrototypeOf||({__proto__:[]})instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function a(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var c=function(){return(c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function s(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&0>t.indexOf(n)&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,n=Object.getOwnPropertySymbols(e);o<n.length;o++)0>t.indexOf(n[o])&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]]);return r}function f(e,t,r,n){var o,u=arguments.length,a=u<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if(("undefined"==typeof Reflect?"undefined":(0,i._)(Reflect))==="object"&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(u<3?o(a):u>3?o(t,r,a):o(t,r))||a);return u>3&&a&&Object.defineProperty(t,r,a),a}function l(e,t){return function(r,n){t(r,n,e)}}function p(e,t,r,n,o,u){function a(e){if(void 0!==e&&"function"!=typeof e)throw TypeError("Function expected");return e}for(var c,s=n.kind,f="getter"===s?"get":"setter"===s?"set":"value",l=!t&&e?n.static?e:e.prototype:null,p=t||(l?Object.getOwnPropertyDescriptor(l,n.name):{}),d=!1,y=r.length-1;y>=0;y--){var _={};for(var h in n)_[h]="access"===h?{}:n[h];for(var h in n.access)_.access[h]=n.access[h];_.addInitializer=function(e){if(d)throw TypeError("Cannot add initializers after decoration has completed");u.push(a(e||null))};var v=(0,r[y])("accessor"===s?{get:p.get,set:p.set}:p[f],_);if("accessor"===s){if(void 0===v)continue;if(null===v||(void 0===v?"undefined":(0,i._)(v))!=="object")throw TypeError("Object expected");(c=a(v.get))&&(p.get=c),(c=a(v.set))&&(p.set=c),(c=a(v.init))&&o.unshift(c)}else(c=a(v))&&("field"===s?o.unshift(c):p[f]=c)}l&&Object.defineProperty(l,n.name,p),d=!0}function d(e,t,r){for(var n=arguments.length>2,o=0;o<t.length;o++)r=n?t[o].call(e,r):t[o].call(e);return n?r:void 0}function y(e){return(void 0===e?"undefined":(0,i._)(e))==="symbol"?e:"".concat(e)}function _(e,t,r){return(void 0===t?"undefined":(0,i._)(t))==="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:r?"".concat(r," ",t):t})}function h(e,t){if(("undefined"==typeof Reflect?"undefined":(0,i._)(Reflect))==="object"&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function v(e,t,r,n){return new(r||(r=Promise))(function(o,i){function u(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(u,a)}c((n=n.apply(e,t||[])).next())})}function b(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return u.next=a(0),u.throw=a(1),u.return=a(2),"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(a){return function(c){var s=[a,c];if(r)throw TypeError("Generator is already executing.");for(;u&&(u=0,s[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}}var w=Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]};function m(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||w(t,e,r)}function g(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function j(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u}function x(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(j(arguments[t]));return e}function O(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var n=Array(e),o=0,t=0;t<r;t++)for(var i=arguments[t],u=0,a=i.length;u<a;u++,o++)n[o]=i[u];return n}function P(e,t,r){if(r||2==arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}function S(e){return this instanceof S?(this.v=e,this):new S(e)}function E(e,t,r){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(e,t||[]),i=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),u("next"),u("throw"),u("return",function(e){return function(t){return Promise.resolve(t).then(e,s)}}),n[Symbol.asyncIterator]=function(){return this},n;function u(e,t){o[e]&&(n[e]=function(t){return new Promise(function(r,n){i.push([e,t,r,n])>1||a(e,t)})},t&&(n[e]=t(n[e])))}function a(e,t){try{var r;(r=o[e](t)).value instanceof S?Promise.resolve(r.value.v).then(c,s):f(i[0][2],r)}catch(e){f(i[0][3],e)}}function c(e){a("next",e)}function s(e){a("throw",e)}function f(e,t){e(t),i.shift(),i.length&&a(i[0][0],i[0][1])}}function A(e){var t,r;return t={},n("next"),n("throw",function(e){throw e}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(n,o){t[n]=e[n]?function(t){return(r=!r)?{value:S(e[n](t)),done:!1}:o?o(t):t}:o}}function R(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=g(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise(function(n,o){var i,u,a;i=n,u=o,a=(t=e[r](t)).done,Promise.resolve(t.value).then(function(e){i({value:e,done:a})},u)})}}}function I(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var T=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t},D=function(e){return(D=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)};function M(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=D(e),n=0;n<r.length;n++)"default"!==r[n]&&w(t,e,r[n]);return T(t,e),t}function U(e){return e&&e.__esModule?e:{default:e}}function k(e,t,r,n){if("a"===r&&!n)throw TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)}function F(e,t,r,n,o){if("m"===n)throw TypeError("Private method is not writable");if("a"===n&&!o)throw TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,r):o?o.value=r:t.set(e,r),r}function C(e,t){if(null===t||(void 0===t?"undefined":(0,i._)(t))!=="object"&&"function"!=typeof t)throw TypeError("Cannot use 'in' operator on non-object");return"function"==typeof e?t===e:e.has(t)}function N(e,t,r){if(null!=t){var n,o;if((void 0===t?"undefined":(0,i._)(t))!=="object"&&"function"!=typeof t)throw TypeError("Object expected.");if(r){if(!Symbol.asyncDispose)throw TypeError("Symbol.asyncDispose is not defined.");n=t[Symbol.asyncDispose]}if(void 0===n){if(!Symbol.dispose)throw TypeError("Symbol.dispose is not defined.");n=t[Symbol.dispose],r&&(o=n)}if("function"!=typeof n)throw TypeError("Object not disposable.");o&&(n=function(){try{o.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:t,dispose:n,async:r})}else r&&e.stack.push({async:!0});return t}var q="function"==typeof SuppressedError?SuppressedError:function(e,t,r){var n=Error(r);return n.name="SuppressedError",n.error=e,n.suppressed=t,n};function B(e){function t(t){e.error=e.hasError?new q(t,e.error,"An error was suppressed during disposal."):t,e.hasError=!0}var r,n=0;return function o(){for(;r=e.stack.pop();)try{if(!r.async&&1===n)return n=0,e.stack.push(r),Promise.resolve().then(o);if(r.dispose){var i=r.dispose.call(r.value);if(r.async)return n|=2,Promise.resolve(i).then(o,function(e){return t(e),o()})}else n|=1}catch(e){t(e)}if(1===n)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}()}function G(e,t){return"string"==typeof e&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(e,r,n,o,i){return r?t?".jsx":".js":!n||o&&i?n+o+"."+i.toLowerCase()+"js":e}):e}r.default={__extends:a,__assign:c,__rest:s,__decorate:f,__param:l,__esDecorate:p,__runInitializers:d,__propKey:y,__setFunctionName:_,__metadata:h,__awaiter:v,__generator:b,__createBinding:w,__exportStar:m,__values:g,__read:j,__spread:x,__spreadArrays:O,__spreadArray:P,__await:S,__asyncGenerator:E,__asyncDelegator:A,__asyncValues:R,__makeTemplateObject:I,__importStar:M,__importDefault:U,__classPrivateFieldGet:k,__classPrivateFieldSet:F,__classPrivateFieldIn:C,__addDisposableResource:N,__disposeResources:B,__rewriteRelativeImportExtension:G}},{"@swc/helpers/cjs/_type_of.cjs":"iXhRw","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],iXhRw:[function(e,t,r,n){"use strict";r._=function(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}},{}],qpMMf:[function(e,t,r,n){r.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},r.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.exportAll=function(e,t){return Object.keys(e).forEach(function(r){"default"===r||"__esModule"===r||Object.prototype.hasOwnProperty.call(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[r]}})}),t},r.export=function(e,t,r){Object.defineProperty(e,t,{enumerable:!0,get:r})}},{}]},["98QZN"],"98QZN","parcelRequire4dc0",{});