The PySide.QtMultimedia.QAudioInput class provides an interface for receiving audio data from an audio input device.
You can construct an audio input with the system’s default audio input device . It is also possible to create PySide.QtMultimedia.QAudioInput with a specific PySide.QtMultimedia.QAudioDeviceInfo . When you create the audio input, you should also send in the PySide.QtMultimedia.QAudioFormat to be used for the recording (see the PySide.QtMultimedia.QAudioFormat class description for details).
To record to a file:
PySide.QtMultimedia.QAudioInput lets you record audio with an audio input device. The default constructor of this class will use the systems default audio device, but you can also specify a PySide.QtMultimedia.QAudioDeviceInfo for a specific device. You also need to pass in the PySide.QtMultimedia.QAudioFormat in which you wish to record.
Starting up the PySide.QtMultimedia.QAudioInput is simply a matter of calling PySide.QtMultimedia.QAudioInput.start() with a PySide.QtCore.QIODevice opened for writing. For instance, to record to a file, you can:
@Slot(QAudio.State) def stateChanged(self, newState): if newState == QAudio.StopState: if self.output.error() != QAudio.NoError: # Perform error handling else: # Normal stop ... @Slot(QAudio.State) def stateChanged(self, newState): if newState == QAudio.StopState: if self.input.error() != QAudio.NoError: # Error handlingThis will start recording if the format specified is supported by the input device (you can check this with QAudioDeviceInfo.isFormatSupported() . In case there are any snags, use the PySide.QtMultimedia.QAudioInput.error() function to check what went wrong. We stop recording in the stopRecording() slot.
format = QAudioFormat() format.setFrequency(44100)At any point in time, PySide.QtMultimedia.QAudioInput will be in one of four states: active, suspended, stopped, or idle. These states are specified by the QAudio.State enum. You can request a state change directly through PySide.QtMultimedia.QAudioInput.suspend() , PySide.QtMultimedia.QAudioInput.resume() , PySide.QtMultimedia.QAudioInput.stop() , PySide.QtMultimedia.QAudioInput.reset() , and PySide.QtMultimedia.QAudioInput.start() . The current state is reported by PySide.QtMultimedia.QAudioInput.state() . PySide.QtMultimedia.QAudioOutput will also signal you when the state changes ( PySide.QtMultimedia.QAudioInput.stateChanged() ).
PySide.QtMultimedia.QAudioInput provides several ways of measuring the time that has passed since the PySide.QtMultimedia.QAudioInput.start() of the recording. The processedUSecs() function returns the length of the stream in microseconds written, i.e., it leaves out the times the audio input was suspended or idle. The PySide.QtMultimedia.QAudioInput.elapsedUSecs() function returns the time elapsed since PySide.QtMultimedia.QAudioInput.start() was called regardless of which states the PySide.QtMultimedia.QAudioInput has been in.
If an error should occur, you can fetch its reason with PySide.QtMultimedia.QAudioInput.error() . The possible error reasons are described by the QAudio.Error enum. The PySide.QtMultimedia.QAudioInput will enter the StoppedState when an error is encountered. Connect to the PySide.QtMultimedia.QAudioInput.stateChanged() signal to handle the error:
format.setSampleType(QAudioFormat.SignedInt) info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice()) if not info.isFormatSupported(format): format = info.nearestFormat(format)
On Symbian, processes which use this class must have the UserEnvironment platform security capability. If the client process lacks this capability, calls to either overload of PySide.QtMultimedia.QAudioInput.start() will fail. This failure is indicated by the PySide.QtMultimedia.QAudioInput object setting its PySide.QtMultimedia.QAudioInput.error() value to QAudio.OpenError and then emitting a PySide.QtMultimedia.QAudioInput.stateChanged() ( QAudio.StoppedState ) signal.
Platform security capabilities are added via the TARGET.CAPABILITY qmake variable.
Parameters: |
|
---|
Construct a new audio input and attach it to parent . The device referenced by audioDevice is used with the input format parameters.
Construct a new audio input and attach it to parent . The default audio input device is used with the output format parameters.
Return type: | PySide.QtCore.int |
---|
Returns the audio buffer size in milliseconds.
If called before PySide.QtMultimedia.QAudioInput.start() , returns platform default value. If called before PySide.QtMultimedia.QAudioInput.start() but PySide.QtMultimedia.QAudioInput.setBufferSize() was called prior, returns value set by PySide.QtMultimedia.QAudioInput.setBufferSize() . If called after PySide.QtMultimedia.QAudioInput.start() , returns the actual buffer size being used. This may not be what was set previously by PySide.QtMultimedia.QAudioInput.setBufferSize() .
Return type: | PySide.QtCore.int |
---|
Returns the amount of audio data available to read in bytes.
NOTE: returned value is only valid while in QAudio.ActiveState or QAudio.IdleState state, otherwise returns zero.
Return type: | PySide.QtCore.qint64 |
---|
Returns the microseconds since PySide.QtMultimedia.QAudioInput.start() was called, including time in Idle and Suspend states.
Return type: | PySide.QtMultimedia.QAudio.Error |
---|
Returns the error state.
Return type: | PySide.QtMultimedia.QAudioFormat |
---|
Returns the PySide.QtMultimedia.QAudioFormat being used.
Return type: | PySide.QtCore.int |
---|
Returns the notify interval in milliseconds.
Return type: | PySide.QtCore.int |
---|
Returns the period size in bytes.
Note: This is the recommended read size in bytes.
Return type: | PySide.QtCore.qint64 |
---|
Returns the amount of audio data processed since PySide.QtMultimedia.QAudioInput.start() was called in microseconds.
Drops all audio data in the buffers, resets buffers to zero.
Resumes processing audio data after a PySide.QtMultimedia.QAudioInput.suspend() .
Sets PySide.QtMultimedia.QAudioInput.error() to QAudio.NoError . Sets PySide.QtMultimedia.QAudioInput.state() to QAudio.ActiveState if you previously called start( PySide.QtCore.QIODevice *). Sets PySide.QtMultimedia.QAudioInput.state() to QAudio.IdleState if you previously called PySide.QtMultimedia.QAudioInput.start() . emits PySide.QtMultimedia.QAudioInput.stateChanged() signal.
Parameters: | bytes – PySide.QtCore.int |
---|
Sets the audio buffer size to value milliseconds.
Note: This function can be called anytime before PySide.QtMultimedia.QAudioInput.start() , calls to this are ignored after PySide.QtMultimedia.QAudioInput.start() . It should not be assumed that the buffer size set is the actual buffer size used, calling PySide.QtMultimedia.QAudioInput.bufferSize() anytime after PySide.QtMultimedia.QAudioInput.start() will return the actual buffer size being used.
Parameters: | milliSeconds – PySide.QtCore.int |
---|
Sets the interval for PySide.QtMultimedia.QAudioInput.notify() signal to be emitted. This is based on the ms of audio data processed not on actual real-time. The minimum resolution of the timer is platform specific and values should be checked with PySide.QtMultimedia.QAudioInput.notifyInterval() to confirm actual value being used.
Parameters: | device – PySide.QtCore.QIODevice |
---|
Uses the device as the PySide.QtCore.QIODevice to transfer data. Passing a PySide.QtCore.QIODevice allows the data to be transferred without any extra code. All that is required is to open the PySide.QtCore.QIODevice . PySide.QtMultimedia.QAudioInput does not take ownership of device .
The PySide.QtMultimedia.QAudioInput will write to the device when new data is available. You can subclass PySide.QtCore.QIODevice and reimplement PySide.QtCore.QIODevice.writeData() if you wish to access the data. If you simply want to save data to a file, you can pass a PySide.QtCore.QFile to this function.
If able to successfully get audio data from the systems audio device the PySide.QtMultimedia.QAudioInput.state() is set to either QAudio.ActiveState or QAudio.IdleState , PySide.QtMultimedia.QAudioInput.error() is set to QAudio.NoError and the PySide.QtMultimedia.QAudioInput.stateChanged() signal is emitted.
If a problem occurs during this process the PySide.QtMultimedia.QAudioInput.error() is set to QAudio.OpenError , PySide.QtMultimedia.QAudioInput.state() is set to QAudio.StoppedState and PySide.QtMultimedia.QAudioInput.stateChanged() signal is emitted.
QAudioInput#Symbian Platform Security Requirements
See also
Return type: | PySide.QtCore.QIODevice |
---|
Returns a pointer to a new PySide.QtCore.QIODevice that will be used to handle the data transfer. This PySide.QtCore.QIODevice can be used to PySide.QtCore.QIODevice.read() audio data directly. You will typically connect to the PySide.QtCore.QIODevice.readyRead() signal, and read from the device in the slot you connect to. PySide.QtMultimedia.QAudioInput keeps ownership of the device.
If able to access the systems audio device the PySide.QtMultimedia.QAudioInput.state() is set to QAudio.IdleState , PySide.QtMultimedia.QAudioInput.error() is set to QAudio.NoError and the PySide.QtMultimedia.QAudioInput.stateChanged() signal is emitted.
If a problem occurs during this process the PySide.QtMultimedia.QAudioInput.error() is set to QAudio.OpenError , PySide.QtMultimedia.QAudioInput.state() is set to QAudio.StoppedState and PySide.QtMultimedia.QAudioInput.stateChanged() signal is emitted.
QAudioInput#Symbian Platform Security Requirements
See also
Return type: | PySide.QtMultimedia.QAudio.State |
---|
Returns the state of audio processing.
Parameters: | arg__1 – PySide.QtMultimedia.QAudio.State |
---|
Stops the audio input, detaching from the system resource.
Sets PySide.QtMultimedia.QAudioInput.error() to QAudio.NoError , PySide.QtMultimedia.QAudioInput.state() to QAudio.StoppedState and emit PySide.QtMultimedia.QAudioInput.stateChanged() signal.
Stops processing audio data, preserving buffered audio data.
Sets PySide.QtMultimedia.QAudioInput.error() to QAudio.NoError , PySide.QtMultimedia.QAudioInput.state() to QAudio.SuspendedState and emit PySide.QtMultimedia.QAudioInput.stateChanged() signal.