Learn R Programming

torchaudio (version 0.2.2)

transform_to_tensor: Convert an audio object into a tensor

Description

Converts a tuneR Wave object or numeric vector into a torch_tensor of shape (Channels x Samples). Convert Audio Object to Tensor.

Usage

transform_to_tensor(
  audio,
  out = NULL,
  normalization = TRUE,
  channels_first = TRUE
)

Value

list(Tensor, int): An output tensor of size `[C x L]` or `[L x C]` where
    L is the number of audio frames and
    C is the number of channels.
    An integer which is the sample rate of the audio (as listed in the metadata of the file)

Arguments

audio

(numeric or Wave): A numeric vector or Wave object, usually from tuneR::readMP3 or tuneR::readWave.

out

(Tensor): An optional output tensor to use instead of creating one. (Default: NULL)

normalization

(bool, float or function): Optional normalization. If boolean TRUE, then output is divided by 2^(bits-1). If bits info is not available it assumes the input is signed 32-bit audio. If numeric, then output is divided by that number. If function, then the output is passed as a parameter to the given function, then the output is divided by the result. (Default: TRUE)

channels_first

(bool): Set channels first or length first in result. (Default: TRUE)

Details

If audio is a numeric vector, attributes "channels" and "sample_rate" will be used if exists. Numeric vectors returned from av::read_audio_bin have both attributes by default.