PySide6.QtMultimedia.QAudioBufferInput¶
- class QAudioBufferInput¶
The
QAudioBufferInputclass is used for providing custom audio buffers toQMediaRecorderthroughQMediaCaptureSession.Details
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QAudioBufferInputis only supported with the FFmpeg backend.Custom audio buffers can be recorded by connecting a
QAudioBufferInputand aQMediaRecorderto aQMediaCaptureSession. For a pull mode implementation, callsendAudioBuffer()in response to thereadyToSendAudioBuffer()signal. In the snippet below this is done by connecting the signal to a slot in a custom media generator class. The slot function emits another signal with a new audio buffer, which is connected tosendAudioBuffer():session = QMediaCaptureSession() recorder = QMediaRecorder() audioInput = QAudioBufferInput() session.setRecorder(recorder) session.setAudioBufferInput(audioInput) MediaGenerator generator # Custom class providing audio buffers audioInput.readyToSendAudioBuffer.connect( generator.nextAudioBuffer) generator.audioBufferReady.connect( audioInput.sendAudioBuffer) recorder.record()
Here’s a minimal implementation of the slot function that provides audio buffers:
def nextAudioBuffer(self): buffer = nextBuffer() audioBufferReady.emit(buffer)
For more details see
readyToSendAudioBuffer()andsendAudioBuffer().See also
Added in version 6.8.
Synopsis¶
Methods¶
def
__init__()def
captureSession()def
format()
Signals¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Constructs a new
QAudioBufferInputobject withparent.- __init__(format[, parent=None])
- Parameters:
format –
QAudioFormatparent –
QObject
Constructs a new
QAudioBufferInputobject with audioformatandparent.The specified
formatwill work as a hint for the initialization of the matching audio encoder upon invokingrecord(). If the format is not specified or not valid, the audio encoder will be initialized upon sending the first audio buffer.We recommend specifying the format if you know in advance what kind of audio buffers you’re going to send.
- captureSession()¶
- Return type:
Returns the capture session this audio buffer input is connected to, or a
nullptrif the audio buffer input is not connected to a capture session.Use
setAudioBufferInput()to connect the audio buffer input to a session.- format()¶
- Return type:
Returns the audio format that was specified upon construction of the audio buffer input.
- readyToSendAudioBuffer()¶
Signals that a new audio buffer can be sent to the audio buffer input. After receiving the signal, if you have audio date to be sent, invoke
sendAudioBufferonce or in a loop until it returnsfalse.See also
- sendAudioBuffer(audioBuffer)¶
- Parameters:
audioBuffer –
QAudioBuffer- Return type:
bool
Sends
QAudioBuffertoQMediaRecorderthroughQMediaCaptureSession.Returns
trueif the specifiedaudioBufferhas been sent successfully to the destination. Returnsfalse, if the buffer hasn’t been sent, which can happen if the instance is not assigned toQMediaCaptureSession, the session doesn’t have a media recorder, the media recorder is not started or its queue is full. ThereadyToSendAudioBuffer()signal will be emitted as soon as the destination is able to handle a new audio buffer.Sending of an empty audio buffer is treated by
QMediaRecorderas an end of the input stream.QMediaRecorderstops the recording automatically ifautoStopistrueand all the inputs have reported the end of the stream.