Skip to content

Commit

Permalink
Remove chunk_callback option in ASR pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed May 31, 2024
1 parent 7236245 commit 6cb7481
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -1553,12 +1553,6 @@ export class ZeroShotAudioClassificationPipeline extends (/** @type {new (option
}
}

/**
* @typedef {{stride: number[], input_features: Tensor, is_last: boolean, tokens?: number[], token_timestamps?: number[]}} ChunkCallbackItem
* @callback ChunkCallback
* @param {ChunkCallbackItem} chunk The chunk to process.
*/

/**
* @typedef {Object} Chunk
* @property {[number, number]} timestamp The start and end timestamp of the chunk in seconds.
Expand All @@ -1575,7 +1569,6 @@ export class ZeroShotAudioClassificationPipeline extends (/** @type {new (option
* @property {boolean|'word'} [return_timestamps] Whether to return timestamps or not. Default is `false`.
* @property {number} [chunk_length_s] The length of audio chunks to process in seconds. Default is 0 (no chunking).
* @property {number} [stride_length_s] The length of overlap between consecutive audio chunks in seconds. If not provided, defaults to `chunk_length_s / 6`.
* @property {ChunkCallback} [chunk_callback] Callback function to be called with each chunk processed.
* @property {boolean} [force_full_sequences] Whether to force outputting full sequences or not. Default is `false`.
* @property {string} [language] The source language. Default is `null`, meaning it should be auto-detected. Use this to potentially improve performance if the source language is known.
* @property {string} [task] The task to perform. Default is `null`, meaning it should be auto-detected.
Expand Down Expand Up @@ -1735,7 +1728,6 @@ export class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options
async _call_whisper(audio, kwargs) {
const return_timestamps = kwargs.return_timestamps ?? false;
const chunk_length_s = kwargs.chunk_length_s ?? 0;
const chunk_callback = kwargs.chunk_callback ?? null;
const force_full_sequences = kwargs.force_full_sequences ?? false;
let stride_length_s = kwargs.stride_length_s ?? null;

Expand Down Expand Up @@ -1770,7 +1762,7 @@ export class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options

const toReturn = [];
for (const aud of preparedAudios) {
/** @type {ChunkCallbackItem[]} */
/** @type {{stride: number[], input_features: Tensor, is_last: boolean, tokens?: bigint[], token_timestamps?: number[]}[]} */
let chunks = [];
if (chunk_length_s > 0) {
if (stride_length_s === null) {
Expand Down Expand Up @@ -1834,10 +1826,6 @@ export class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options

// convert stride to seconds
chunk.stride = chunk.stride.map(x => x / sampling_rate);

if (chunk_callback !== null) {
chunk_callback(chunk)
}
}

// Merge text chunks
Expand Down

0 comments on commit 6cb7481

Please sign in to comment.