def fft_conv1d(inputs: tf.Tensor, filters: tf.Tensor):
    """FFT based convolution in 1D.

    We round the input length to the closest upper power of 2 before FFT.

    Args:
     inputs: a tf.Tensor<float>[batch_size, seq_length, 1] of input sequences.
     filters: a tf.Tensor<float>[filter_length, 1, channels]

    Returns:
     A tf.Tensor<float>[batch_size, seq_length, channels] containing the response
     to the 1D convolutions with the filters, and a tf.Tensor<float>[1,] with the
     L1 norm of the filters FFT.
    """
    seq_length = tf.shape(inputs)[1]
    fft_length = upper_power_of_2(seq_length)
    filter_length = tf.shape(filters)[0]
    f_inputs = tf.signal.rfft(
        tf.transpose(inputs, (0, 2, 1)), fft_length=[fft_length])
    f_filters = tf.signal.rfft(
        tf.transpose(filters, (1, 2, 0)), fft_length=[fft_length])
    f_filters_l1 = tf.reduce_sum(tf.math.abs(f_filters))
    result = tf.transpose(
        tf.signal.irfft(f_inputs * tf.math.conj(f_filters)), (0, 2, 1))
    output = tf.roll(result, filter_length // 2 - 1, axis=1)
    output = output[:, :seq_length, :]

    shape = tf.concat([tf.shape(inputs)[:-1], tf.shape(filters)[-1:]], axis=0)
    return tf.reshape(output, shape), f_filters_l1
FFT based convolution in 1D.

    We round the input length to the closest upper power of 2 before FFT.

    Args:
     inputs: a tf.Tensor<float>[batch_size, seq_length, 1] of input sequences.
     filters: a tf.Tensor<float>[filter_length, 1, channels]

    Returns:
     A tf.Tensor<float>[batch_size, seq_length, channels] containing the response
     to the 1D convolutions with the filters, and a tf.Tensor<float>[1,] with the
     L1 norm of the filters FFT.
    
leaf_audio/convolution.py