def linear_to_mel_weight_matrix(
        self,
        num_mel_bins=20,
        num_spectrogram_bins=129,
        sampling_rate=8000,
        lower_edge_hertz=125.0,
        upper_edge_hertz=3800.0,
        dtype="float32",
    ):
        """Returns a matrix to warp linear scale spectrograms to the mel scale.

        Returns a weight matrix that can be used to re-weight a tensor
        containing `num_spectrogram_bins` linearly sampled frequency information
        from `[0, sampling_rate / 2]` into `num_mel_bins` frequency information
        from `[lower_edge_hertz, upper_edge_hertz]` on the mel scale.

        This function follows the [Hidden Markov Model Toolkit (HTK)](
        http://htk.eng.cam.ac.uk/) convention, defining the mel scale in
        terms of a frequency in hertz according to the following formula:

        ```mel(f) = 2595 * log10( 1 + f/700)```

        In the returned matrix, all the triangles (filterbanks) have a peak
        value of 1.0.

        For example, the returned matrix `A` can be used to right-multiply a
        spectrogram `S` of shape `[frames, num_spectrogram_bins]` of linear
        scale spectrum values (e.g. STFT magnitudes) to generate a
        "mel spectrogram" `M` of shape `[frames, num_mel_bins]`.

        ```
        # `S` has shape [frames, num_spectrogram_bins]
        # `M` has shape [frames, num_mel_bins]
        M = keras.ops.matmul(S, A)
        ```

        The matrix can be used with `keras.ops.tensordot` to convert an
        arbitrary rank `Tensor` of linear-scale spectral bins into the
        mel scale.

        ```
        # S has shape [..., num_spectrogram_bins].
        # M has shape [..., num_mel_bins].
        M = keras.ops.tensordot(S, A, 1)
        ```

        References:
        - [Mel scale (Wikipedia)](https://en.wikipedia.org/wiki/Mel_scale)

        Args:
            num_mel_bins: Python int. How many bands in the resulting
                mel spectrum.
            num_spectrogram_bins: An integer `Tensor`. How many bins there are
                in the source spectrogram data, which is understood to be
                `fft_size // 2 + 1`, i.e. the spectrogram only contains the
                nonredundant FFT bins.
            sampling_rate: An integer or float `Tensor`. Samples per second of
                the input signal used to create the spectrogram. Used to figure
                out the frequencies corresponding to each spectrogram bin,
                which dictates how they are mapped into the mel scale.
            lower_edge_hertz: Python float. Lower bound on the frequencies to be
                included in the mel spectrum. This corresponds to the lower
                edge of the lowest triangular band.
            upper_edge_hertz: Python float. The desired top edge of the highest
                frequency band.
            dtype: The `DType` of the result matrix. Must be a floating point
                type.

        Returns:
            A tensor of shape `[num_spectrogram_bins, num_mel_bins]`.
        """

        # This function can be constant folded by graph optimization since
        # there are no Tensor inputs.
        sampling_rate = self.backend.cast(sampling_rate, dtype)
        lower_edge_hertz = self.backend.convert_to_tensor(
            lower_edge_hertz,
            dtype,
        )
        upper_edge_hertz = self.backend.convert_to_tensor(
            upper_edge_hertz,
            dtype,
        )
        zero = self.backend.convert_to_tensor(0.0, dtype)

        # HTK excludes the spectrogram DC bin.
        bands_to_zero = 1
        nyquist_hertz = sampling_rate / 2.0
        linear_frequencies = self.backend.numpy.linspace(
            zero, nyquist_hertz, num_spectrogram_bins
        )[bands_to_zero:]
        spectrogram_bins_mel = self.backend.numpy.expand_dims(
            self._hertz_to_mel(linear_frequencies), 1
        )

        # Compute num_mel_bins triples of (lower_edge, center, upper_edge). The
        # center of each band is the lower and upper edge of the adjacent bands.
        # Accordingly, we divide [lower_edge_hertz, upper_edge_hertz] into
        # num_mel_bins + 2 pieces.
        band_edges_mel = self.backend.math.extract_sequences(
            self.backend.numpy.linspace(
                self._hertz_to_mel(lower_edge_hertz),
                self._hertz_to_mel(upper_edge_hertz),
                num_mel_bins + 2,
            ),
            sequence_length=3,
            sequence_stride=1,
        )

        # Split the triples up and reshape them into [1, num_mel_bins] tensors.
        lower_edge_mel, center_mel, upper_edge_mel = tuple(
            self.backend.numpy.reshape(t, [1, num_mel_bins])
            for t in self.backend.numpy.split(band_edges_mel, 3, axis=1)
        )

        # Calculate lower and upper slopes for every spectrogram bin.
        # Line segments are linear in the mel domain, not Hertz.
        lower_slopes = (spectrogram_bins_mel - lower_edge_mel) / (
            center_mel - lower_edge_mel
        )
        upper_slopes = (upper_edge_mel - spectrogram_bins_mel) / (
            upper_edge_mel - center_mel
        )

        # Intersect the line segments with each other and zero.
        mel_weights_matrix = self.backend.numpy.maximum(
            zero, self.backend.numpy.minimum(lower_slopes, upper_slopes)
        )

        # Re-add the zeroed lower bins we sliced out above.
        return self.backend.numpy.pad(
            mel_weights_matrix,
            [[bands_to_zero, 0], [0, 0]],
        )
Returns a matrix to warp linear scale spectrograms to the mel scale.

        Returns a weight matrix that can be used to re-weight a tensor
        containing `num_spectrogram_bins` linearly sampled frequency information
        from `[0, sampling_rate / 2]` into `num_mel_bins` frequency information
        from `[lower_edge_hertz, upper_edge_hertz]` on the mel scale.

        This function follows the [Hidden Markov Model Toolkit (HTK)](
        http://htk.eng.cam.ac.uk/) convention, defining the mel scale in
        terms of a frequency in hertz according to the following formula:

        ```mel(f) = 2595 * log10( 1 + f/700)```

        In the returned matrix, all the triangles (filterbanks) have a peak
        value of 1.0.

        For example, the returned matrix `A` can be used to right-multiply a
        spectrogram `S` of shape `[frames, num_spectrogram_bins]` of linear
        scale spectrum values (e.g. STFT magnitudes) to generate a
        "mel spectrogram" `M` of shape `[frames, num_mel_bins]`.

        ```
        # `S` has shape [frames, num_spectrogram_bins]
        # `M` has shape [frames, num_mel_bins]
        M = keras.ops.matmul(S, A)
        ```

        The matrix can be used with `keras.ops.tensordot` to convert an
        arbitrary rank `Tensor` of linear-scale spectral bins into the
        mel scale.

        ```
        # S has shape [..., num_spectrogram_bins].
        # M has shape [..., num_mel_bins].
        M = keras.ops.tensordot(S, A, 1)
        ```

        References:
        - [Mel scale (Wikipedia)](https://en.wikipedia.org/wiki/Mel_scale)

        Args:
            num_mel_bins: Python int. How many bands in the resulting
                mel spectrum.
            num_spectrogram_bins: An integer `Tensor`. How many bins there are
                in the source spectrogram data, which is understood to be
                `fft_size // 2 + 1`, i.e. the spectrogram only contains the
                nonredundant FFT bins.
            sampling_rate: An integer or float `Tensor`. Samples per second of
                the input signal used to create the spectrogram. Used to figure
                out the frequencies corresponding to each spectrogram bin,
                which dictates how they are mapped into the mel scale.
            lower_edge_hertz: Python float. Lower bound on the frequencies to be
                included in the mel spectrum. This corresponds to the lower
                edge of the lowest triangular band.
            upper_edge_hertz: Python float. The desired top edge of the highest
                frequency band.
            dtype: The `DType` of the result matrix. Must be a floating point
                type.

        Returns:
            A tensor of shape `[num_spectrogram_bins, num_mel_bins]`.
        
keras/src/layers/preprocessing/mel_spectrogram.py