| def bufferSize () |
| def bytesReady () |
| def elapsedUSecs () |
| def error () |
| def format () |
| def notify () |
| def notifyInterval () |
| def operator= (arg__1) |
| def periodSize () |
| def processedUSecs () |
| def reset () |
| def resume () |
| def setBufferSize (bytes) |
| def setNotifyInterval (milliSeconds) |
| def start () |
| def start (device) |
| def state () |
| def stateChanged (arg__1) |
| def stop () |
| def suspend () |
The 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 QAudioInput with a specific QAudioDeviceInfo . When you create the audio input, you should also send in the QAudioFormat to be used for the recording (see the QAudioFormat class description for details).
To record to a file:
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 QAudioDeviceInfo for a specific device. You also need to pass in the QAudioFormat in which you wish to record.
Starting up the QAudioInput is simply a matter of calling QAudioInput.start() with a QIODevice opened for writing. For instance, to record to a file, you can:
QFile outputFile; // class member. QAudioInput* audio; // class member.{ outputFile.setFileName("/tmp/test.raw"); outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); QAudioFormat format; // set up the format you want, eg. format.setFrequency(8000); format.setChannels(1); format.setSampleSize(8); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); if (QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); if (!info.isFormatSupported(format)) { qWarning()<<"default format not supported try to use nearest"; format = info.nearestFormat(format); } audio = new QAudioInput(format, this); QTimer::singleShot(3000, this, SLOT(stopRecording())); audio->start(&outputFile); // Records audio for 3000ms }This 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 QAudioInput.error() function to check what went wrong. We stop recording in the stopRecording() slot.
void stopRecording() { audio->stop(); outputFile->close(); delete audio; }At any point in time, 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 QAudioInput.suspend() , QAudioInput.resume() , QAudioInput.stop() , QAudioInput.reset() , and QAudioInput.start() . The current state is reported by QAudioInput.state() . QAudioOutput will also signal you when the state changes ( QAudioInput.stateChanged() ).
QAudioInput provides several ways of measuring the time that has passed since the 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 QAudioInput.elapsedUSecs() function returns the time elapsed since QAudioInput.start() was called regardless of which states the QAudioInput has been in.
If an error should occur, you can fetch its reason with QAudioInput.error() . The possible error reasons are described by the QAudio.Error enum. The QAudioInput will enter the StoppedState when an error is encountered. Connect to the QAudioInput.stateChanged() signal to handle the error:
<Code snippet "/home/renato/work/pyside/pyside/doc/codesnippets/doc/src/snippets/audio/main.cpp:0" not found>See also
| 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: | int |
|---|
Returns the audio buffer size in milliseconds.
If called before QAudioInput.start() , returns platform default value. If called before QAudioInput.start() but QAudioInput.setBufferSize() was called prior, returns value set by QAudioInput.setBufferSize() . If called after QAudioInput.start() , returns the actual buffer size being used. This may not be what was set previously by QAudioInput.setBufferSize() .
See also
| Return type: | int |
|---|
Returns the amount of audio data available to read in bytes.
| Return type: | qint64 |
|---|
Returns the microseconds since QAudioInput.start() was called, including time in Idle and Suspend states.
| Return type: | Error |
|---|
Returns the error state.
| Return type: | QAudioFormat |
|---|
Returns the QAudioFormat being used.
| Return type: | int |
|---|
Returns the notify interval in milliseconds.
See also
| Parameter: | arg__1 – QAudioInput |
|---|---|
| Return type: | QAudioInput |
| Return type: | int |
|---|
Returns the period size in bytes.
Note: This is the recommended read size in bytes.
| Return type: | qint64 |
|---|
Returns the amount of audio data processed since QAudioInput.start() was called in microseconds.
| Parameter: | bytes – int |
|---|
Sets the audio buffer size to value milliseconds.
Note: This function can be called anytime before QAudioInput.start() , calls to this are ignored after QAudioInput.start() . It should not be assumed that the buffer size set is the actual buffer size used, calling QAudioInput.bufferSize() anytime after QAudioInput.start() will return the actual buffer size being used.
See also
| Parameter: | milliSeconds – int |
|---|
Sets the interval for QAudioInput.notify() signal to be emitted. This is based on the ms of audio data processed not on actual real-time. The resolution of the timer is platform specific.
See also
| Return type: | QIODevice |
|---|
Returns a pointer to the QIODevice being used to handle the data transfer. This QIODevice can be used to read() audio data directly.
See also
QIODevice
| Parameter: | device – QIODevice |
|---|
Uses the device as the QIODevice to transfer data. Passing a QIODevice allows the data to be transfered without any extra code. All that is required is to open the QIODevice .
See also
QIODevice
| Return type: | State |
|---|
Returns the state of audio processing.
| Parameter: | arg__1 – State |
|---|