feat: add WAV format support for audio chunks in artplayer-plugin-asr

- Implemented pcmToWav function to convert PCM audio data to WAV format.
- Updated onAudioChunk callback to receive both PCM and WAV buffers.
- Modified TypeScript definitions to reflect changes in onAudioChunk parameter and append method.
This commit is contained in:
Harvey Zack committed 2025-05-23 10:23:27 +08:00
1 parent 62835bb042
commit 10337ddb1d
6 files changed
+81 -13

No files matched your search

+2 -2
View File
@@ -10,8 +10,8 @@ var art = new Artplayer({
interval: 40,
sampleRate: 16000,
autoHideTimeout: 10000,
// Use your AI tool to convert buffer into subtitles
onAudioChunk: (buffer) => startAsr(buffer),
// Use your AI tool to convert pcm/wav into subtitles
onAudioChunk: ({ pcm, wav }) => startAsr(pcm),
}),
]
});
+7 -2
View File
@@ -3,19 +3,24 @@ import type Artplayer from 'artplayer';
export = artplayerPluginAsr;
export as namespace artplayerPluginAsr;
interface AudioChunk {
pcm: ArrayBuffer;
wav: ArrayBuffer;
}
interface AsrPluginOption {
length?: number;
interval?: number;
sampleRate?: number;
autoHideTimeout?: number;
onAudioChunk?: (buffer: ArrayBuffer) => void | Promise<void>;
onAudioChunk?: (chunk: AudioChunk) => void | Promise<void>;
}
interface AsrPluginInstance {
name: 'artplayerPluginAsr';
stop: () => void;
hide: () => void;
append: () => void;
append: (subtitle: string) => void;
}
declare function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer) => AsrPluginInstance;