RawAudioSamples#
- class torchcodec.decoders.RawAudioSamples(data: Tensor, sample_rate: int, pts_seconds: float, duration_seconds: float, _generation: int = 0)[source]#
One decoded audio frame’s samples, exactly as the decoder produced them.
You cannot build one yourself: an
AudioPacketDecodercreates them. Use anAudioConverterto turn them into normalised float32AudioSamples, or readdatadirectly:for packet in demuxer: for raw_samples in audio_packet_decoder.decode(packet): print(raw_samples.data.shape) # e.g. [2, 1024] print(raw_samples.data.dtype) # e.g. float32, for an fltp source print(raw_samples.sample_rate) # e.g. 16000
Examples using
RawAudioSamples:- data: Tensor#
Always a contiguous
[num_channels, num_samples]tensor, whatever the source’s sample format. Planar and packed sources alike come out with that same shape and layout (they are copied).The dtype is whichever one holds the source’s samples exactly:
uint8foru8,int16fors16,int32fors32,int64fors64,float32forfltandfloat64fordbl. The integer ones are not normalised to[-1, 1]; that is what anAudioConverterdoes.