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.
This commit is contained in:
Harvey Zack committed 2025-05-23 00:09:13 +08:00
1 parent 6c4e9f7e78
commit 5d7710979d
22 files changed
+893 -1

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
autoSize: true,
fullscreen: true,
fullscreenWeb: true,
plugins: [
artplayerPluginAsr({
length: 3,
interval: 40,
sampleRate: 16000,
hideTimeout: 10000,
// Use your AI tool to convert buffer into subtitles
onAudioChunk: (buffer) => tencentASR(buffer),
}),
]
});
var ws = null;
var loading = false;
async function tencentASR(buffer) {
if (loading) return;
if (!ws) {
loading = true;
const api = 'https://api.aimu.app/asr/tencent?engine_model_type=16k_ja';
const { url } = await (await fetch(api)).json();
ws = new WebSocket(url);
ws.binaryType = 'arraybuffer';
ws.onmessage = (event) => {
const { code, result } = JSON.parse(event.data);
if (code === 0) {
const subtitle = result?.voice_text_str;
art.plugins.artplayerPluginAsr.append(subtitle);
} else {
ws.close();
ws = null;
}
};
loading = false;
}
if (ws.readyState === WebSocket.OPEN) {
ws.send(buffer);
} else {
console.warn('WebSocket is not open');
}
}
art.on('destroy', () => {
try {
ws.send(JSON.stringify({ type: 'end' }));
ws.close();
} catch {}
ws = null;
});
+1
View File
@@ -48,6 +48,7 @@
var libUris = [
'./assets/ts/artplayer-plugin-ads.d.ts',
'./assets/ts/artplayer-plugin-asr.d.ts',
'./assets/ts/artplayer-plugin-ambilight.d.ts',
'./assets/ts/artplayer-plugin-auto-thumbnail.d.ts',
'./assets/ts/artplayer-plugin-chapter.d.ts',
+20
View File
@@ -0,0 +1,20 @@
import type Artplayer from 'artplayer';
export = artplayerPluginAsr;
export as namespace artplayerPluginAsr;
interface AsrPluginOption {
length?: number;
interval?: number;
sampleRate?: number;
hideTimeout?: number;
onAudioChunk?: (buffer: ArrayBuffer) => void | Promise<void>;
}
interface AsrPluginInstance {
name: 'artplayerPluginAsr';
hide: () => void;
append: () => void;
}
declare function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer) => AsrPluginInstance;
-1
View File
@@ -58,7 +58,6 @@ export type Utils = {
export type Template = {
readonly $container: HTMLDivElement;
readonly $original: HTMLDivElement;
readonly $player: HTMLDivElement;
readonly $video: HTMLVideoElement;
readonly $track: HTMLTrackElement;