(
waveform,
window,
frame_length,
hop_length,
{
fft_length = null,
power = 1.0,
center = true,
pad_mode = 'reflect',
onesided = true,
preemphasis = null,
preemphasis_htk_flavor = true,
mel_filters = null,
mel_floor = 1e-10,
log_mel = null,
max_log_mel = null,
reference = 1.0,
min_value = 1e-10,
db_range = null,
remove_dc_offset = null,
// Custom parameters for efficiency reasons
min_num_frames = null,
max_num_frames = null,
do_pad = true,
transpose = false,
mel_offset = 0,
mel_floor_mode = 'clamp',
} = {},
)
| 479 | * @returns {Promise<Tensor>} Spectrogram of shape `(num_frequency_bins, length)` (regular spectrogram) or shape `(num_mel_filters, length)` (mel spectrogram). |
| 480 | */ |
| 481 | export async function spectrogram( |
| 482 | waveform, |
| 483 | window, |
| 484 | frame_length, |
| 485 | hop_length, |
| 486 | { |
| 487 | fft_length = null, |
| 488 | power = 1.0, |
| 489 | center = true, |
| 490 | pad_mode = 'reflect', |
| 491 | onesided = true, |
| 492 | preemphasis = null, |
| 493 | preemphasis_htk_flavor = true, |
| 494 | mel_filters = null, |
| 495 | mel_floor = 1e-10, |
| 496 | log_mel = null, |
| 497 | max_log_mel = null, |
| 498 | reference = 1.0, |
| 499 | min_value = 1e-10, |
| 500 | db_range = null, |
| 501 | remove_dc_offset = null, |
| 502 | |
| 503 | // Custom parameters for efficiency reasons |
| 504 | min_num_frames = null, |
| 505 | max_num_frames = null, |
| 506 | do_pad = true, |
| 507 | transpose = false, |
| 508 | mel_offset = 0, |
| 509 | mel_floor_mode = 'clamp', |
| 510 | } = {}, |
| 511 | ) { |
| 512 | const window_length = window.length; |
| 513 | if (fft_length === null) { |
| 514 | fft_length = frame_length; |
| 515 | } |
| 516 | if (frame_length > fft_length) { |
| 517 | throw Error(`frame_length (${frame_length}) may not be larger than fft_length (${fft_length})`); |
| 518 | } |
| 519 | |
| 520 | if (window_length !== frame_length) { |
| 521 | throw new Error(`Length of the window (${window_length}) must equal frame_length (${frame_length})`); |
| 522 | } |
| 523 | |
| 524 | if (hop_length <= 0) { |
| 525 | throw new Error('hop_length must be greater than zero'); |
| 526 | } |
| 527 | |
| 528 | if (power === null && mel_filters !== null) { |
| 529 | throw new Error( |
| 530 | 'You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. ' + |
| 531 | 'Specify `power` to fix this issue.', |
| 532 | ); |
| 533 | } |
| 534 | |
| 535 | if (!preemphasis_htk_flavor) { |
| 536 | throw new Error('`preemphasis_htk_flavor=false` is not currently supported.'); |
| 537 | } |
| 538 |
no test coverage detected