QAudioFormat

PyQt5.QtMultimedia.QAudioFormat

Description

The QAudioFormat class stores audio stream parameter information.

An audio format specifies how data in an audio stream is arranged, i.e, how the stream is to be interpreted. The encoding itself is specified by the codec() used for the stream.

In addition to the encoding, QAudioFormat contains other parameters that further specify how the audio sample data is arranged. These are the frequency, the number of channels, the sample size, the sample type, and the byte order. The following table describes these in more detail.

Parameter

Description

Sample Rate

Samples per second of audio data in Hertz.

Number of channels

The number of audio channels (typically one for mono or two for stereo)

Sample size

How much data is stored in each sample (typically 8 or 16 bits)

Sample type

Numerical representation of sample (typically signed integer, unsigned integer or float)

Byte order

Byte ordering of sample (typically little endian, big endian)

This class is typically used in conjunction with QAudioInput or QAudioOutput to allow you to specify the parameters of the audio stream being read or written, or with QAudioBuffer when dealing with samples in memory.

You can obtain audio formats compatible with the audio device used through functions in QAudioDeviceInfo. This class also lets you query available parameter values for a device, so that you can set the parameters yourself. See the QAudioDeviceInfo class description for details. You need to know the format of the audio streams you wish to play or record.

In the common case of interleaved linear PCM data, the codec will be “audio/pcm”, and the samples for all channels will be interleaved. One sample for each channel for the same instant in time is referred to as a frame in Qt Multimedia (and other places).

Enums

Endian

Member

Value

Description

BigEndian

QSysInfo::BigEndian

Samples are big endian byte order

LittleEndian

QSysInfo::LittleEndian

Samples are little endian byte order


SampleType

Member

Value

Description

Float

3

Samples are floats

SignedInt

1

Samples are signed integers

Unknown

0

Not Set

UnSignedInt

2

Samples are unsigned intergers

Methods

__init__()

Construct a new audio format.

Values are initialized as follows:


__init__(QAudioFormat)

Construct a new audio format using other.


byteOrder() → Endian

Returns the current value.

See also

setByteOrder().


bytesForDuration(int) → int

TODO


bytesForFrames(int) → int

TODO


bytesPerFrame() → int

TODO


channelCount() → int

Returns the current channel count value.

See also

setChannelCount().


codec() → str

Returns the current codec identifier.


durationForBytes(int) → int

TODO


durationForFrames(int) → int

TODO


__eq__(QAudioFormat) → bool

TODO


framesForBytes(int) → int

TODO


framesForDuration(int) → int

TODO


isValid() → bool

Returns true if all of the parameters are valid.


__ne__(QAudioFormat) → bool

TODO


sampleRate() → int

Returns the current sample rate in Hertz.

See also

setSampleRate().


sampleSize() → int

Returns the current sample size value, in bits.

See also

setSampleSize().


sampleType() → SampleType

Returns the current SampleType value.

See also

setSampleType().


setByteOrder(Endian)

Sets the byteOrder() to byteOrder.

See also

byteOrder().


setChannelCount(int)

Sets the channel count to channels.

See also

channelCount().


setCodec(str)

Sets the codec to codec.

The parameter to this function should be one of the types reported by the supportedCodecs() function for the audio device you are working with.


setSampleRate(int)

Sets the sample rate to samplerate Hertz.

See also

sampleRate().


setSampleSize(int)

Sets the sample size to the sampleSize specified, in bits.

This is typically 8 or 16, but some systems may support higher sample sizes.

See also

sampleSize().


setSampleType(SampleType)

Sets the sampleType() to sampleType.

See also

sampleType().