Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class GraniteSpeechFeatureExtractor extends FeatureExtractor {
const { n_fft, hop_length, n_mels } = this.config.melspec_kwargs;

// Truncate to even number of frames for pair-stacking
const num_frames = 1 + Math.floor((audio.length - 1) / hop_length);
const num_frames = Math.floor(audio.length / hop_length) + 1;
const max_num_frames = num_frames - (num_frames % 2);

const mel = await spectrogram(audio, this.window, n_fft, hop_length, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,26 @@ export default () => {
},
MAX_TEST_EXECUTION_TIME,
);

it(
"tokens and features stay aligned for boundary audio lengths",
async () => {
const boundary_lengths = [4960, 9760, 139360]; // For L = 160 * (30k + 1)
const { projector_window_size, projector_downsample_rate } = processor.feature_extractor.config;
const effective_window_size = Math.floor(projector_window_size / projector_downsample_rate);

for (const L of boundary_lengths) {
const audio = new Float32Array(L);
const { input_features } = await processor.feature_extractor(audio);

const predicted_tokens = processor._get_num_audio_features(L);
const time_steps = input_features.dims[1];
const projector_tokens = Math.ceil(time_steps / projector_window_size) * effective_window_size;

expect(projector_tokens).toEqual(predicted_tokens);
}
},
MAX_TEST_EXECUTION_TIME,
);
});
};
Loading