cutcutcodec.core.classes.frame_audio.FrameAudio

class cutcutcodec.core.classes.frame_audio.FrameAudio(time: Fraction | Real | str, rate: Integral, layout: Layout | str | Integral, data: Tensor | ndarray | Container, **kwargs)[source]

An audio sample packet with time information.

Behaves like a torch tensor of shape (nb_channels, samples). The shape is consistent with pyav and torchaudio. Values are supposed to be between -1 and 1 but no verification is done.

Attributes

channelsint

The numbers of channels (readonly). For more informations about each channels, let see self.layout.

layoutcutcutcodec.core.classes.layout.Layout

The signification of each channels (readonly).

rateint

The frequency of the samples in Hz (readonly).

samplesint

The number of samples per channels (readonly).

timeFraction

The time of the first sample of the frame in second (readonly).

Initialise and create the class.

Parameters

timeFraction

The time of the first sample of the frame in second.

rateint

The frequency of the samples in Hz.

layoutcutcutcodec.core.classes.layout.Layout or str or numbers.Integral

The canonical name of the layout, let see cutcutcodec.core.classes.layout.Layout for the available layouts.

dataarraylike

Transmitted to cutcutcodec.core.classes.frame.Frame initialisator.

**kwargsdict

Transmitted to cutcutcodec.core.classes.frame.Frame initialisator.

property channels: int

Return the number of channels.

Examples

>>> import torch
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
>>> FrameAudio(0, 48000, "stereo", torch.empty(2, 1024)).channels
2
>>>
check_state() None[source]

Apply verifications.

Raises

AssertionError

If something wrong in this frame.

property layout: Layout

Return the signification of each channels.

Examples

>>> import torch
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
>>> FrameAudio(0, 48000, "stereo", torch.empty(2, 1024)).layout
Layout('stereo')
>>>
property rate: int

Return the frequency of the samples in Hz.

Examples

>>> import torch
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
>>> FrameAudio(0, 48000, "stereo", torch.empty(2, 1024)).rate
48000
>>>
property samples: int

Return the number of samples per channels.

Examples

>>> import torch
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
>>> FrameAudio(0, 48000, "stereo", torch.empty(2, 1024)).samples
1024
>>>
property time: Fraction

Return the time of the first sample of the frame in second.

Examples

>>> import torch
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
>>> FrameAudio(0, 48000, "stereo", torch.empty(2, 1024)).time
Fraction(0, 1)
>>>
property timestamps: Tensor

Return the time value of each sample of the frame.

The vector is cast on the same type than the samples and in the same device. The shape of the timestamps 1d vector is (self.samples,).

Examples

>>> import torch
>>> from cutcutcodec.core.classes.frame_audio import FrameAudio
>>> FrameAudio(1, 48000, "stereo", torch.empty(2, 1024)).timestamps
tensor([1.0000, 1.0000, 1.0000,  ..., 1.0213, 1.0213, 1.0213])
>>>