Files
ArtPlayer/docs/compiled/artplayer-plugin-asr.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
4.1 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,n,r,o,i,u,l){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof a[r]&&a[r],f=s.i||{},c=s.cache||{},d="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function p(t,n){if(!c[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof a[r]&&a[r];if(!n&&i)return i(t,!0);if(s)return s(t,!0);if(d&&"string"==typeof t)return d(t);var u=Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}f.resolve=function(n){var r=e[t][1][n];return null!=r?r:n},f.cache={};var l=c[t]=new p.Module(t);e[t][0].call(l.exports,f,l,l.exports,a)}return c[t].exports;function f(e){var t=f.resolve(e);return!1===t?{}:p(t)}}p.isParcelRequire=!0,p.Module=function(e){this.id=e,this.bundle=p,this.require=d,this.exports={}},p.modules=e,p.cache=c,p.parent=s,p.distDir=void 0,p.publicUrl=void 0,p.devServer=void 0,p.i=f,p.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(p,"root",{get:function(){return a[r]}}),a[r]=p;for(var y=0;y<t.length;y++)p(t[y]);if(n){var w=p(n);"object"==typeof exports&&"undefined"!=typeof module?module.exports=w:"function"==typeof define&&define.amd&&define(function(){return w})}}({"1gnQM":[function(e,t,n,r){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");function i(e={}){let{interval:t=5e3,sampleRate:n=16e3,callback:r=()=>null}=e;return e=>{let o=!1,i=null,u=null,l=null,a=[],s=null,f=` class RecorderProcessor extends AudioWorkletProcessor { process(inputs) { const input = inputs[0]; if (input && input[0]) { this.port.postMessage(input[0]); } return true; } } registerProcessor('recorder-processor', RecorderProcessor); `,c=()=>{let e=new Blob([f],{type:"application/javascript"});return URL.createObjectURL(e)};async function d(){if(o)return;o=!0,"suspended"===(i=new(window.AudioContext||window.webkitAudioContext)({sampleRate:n})).state&&await i.resume(),u||(u=i.createMediaElementSource(e.video)).connect(i.destination);let f=c();await i.audioWorklet.addModule(f),URL.revokeObjectURL(f),(l=new AudioWorkletNode(i,"recorder-processor")).port.onmessage=e=>{a.push(new Float32Array(e.data))},u.connect(l).connect(i.destination),s=setInterval(async()=>{if(0===a.length)return;let e=function(e,t){let n=function(e){let t=new Float32Array(e.reduce((e,t)=>e+t.length,0)),n=0;return e.forEach(e=>{t.set(e,n),n+=e.length}),t}(e),r=2*n.length,o=new ArrayBuffer(44+r),i=new DataView(o);function u(e,t){for(let n=0;n<t.length;n++)i.setUint8(e+n,t.charCodeAt(n))}u(0,"RIFF"),i.setUint32(4,36+r,!0),u(8,"WAVE"),u(12,"fmt "),i.setUint32(16,16,!0),i.setUint16(20,1,!0),i.setUint16(22,1,!0),i.setUint32(24,t,!0),i.setUint32(28,2*t,!0),i.setUint16(32,2,!0),i.setUint16(34,16,!0),u(36,"data"),i.setUint32(40,r,!0);let l=function(e){let t=e.length,n=new ArrayBuffer(2*t),r=new DataView(n);for(let n=0;n<t;n++){let t=Math.max(-1,Math.min(1,e[n]));r.setInt16(2*n,t<0?32768*t:32767*t,!0)}return n}(n);return new Uint8Array(o).set(new Uint8Array(l),44),new Blob([i],{type:"audio/wav"})}(a,i.sampleRate),t=await e.arrayBuffer();await r(t),a=[]},t)}function p(){o&&(o=!1,s&&clearInterval(s),l&&l.disconnect(),l=null,a=[])}return e.on("play",d),e.on("pause",p),e.on("destroy",p),{name:"artplayerPluginAsr",destroy:p}}}o.defineInteropFlag(n),o.export(n,"default",()=>i),"undefined"!=typeof window&&(window.artplayerPluginAsr=i)},{"@parcel/transformer-js/src/esmodule-helpers.js":"6ykb1"}],"6ykb1":[function(e,t,n,r){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach(function(n){"default"===n||"__esModule"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}]},["1gnQM"],"1gnQM","parcelRequire4dc0",{});