File: qaudioinput.html

package info (click to toggle)
python-qt4 4.7.3-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,504 kB
  • ctags: 4,680
  • sloc: python: 28,738; cpp: 8,897; sh: 245; xml: 243; makefile: 150
file content (110 lines) | stat: -rw-r--r-- 16,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QAudioInput Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QAudioInput Class Reference<br /><sup><sup>[<a href="qtmultimedia.html">QtMultimedia</a> module]</sup></sup></h1><p>The QAudioInput class provides an interface for receiving audio data from an audio input device. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qaudioinput.html#QAudioInput">__init__</a></b> (<i>self</i>, QAudioFormat&#160;<i>format</i>&#160;=&#160;QAudioFormat(), QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qaudioinput.html#QAudioInput-2">__init__</a></b> (<i>self</i>, QAudioDeviceInfo, QAudioFormat&#160;<i>format</i>&#160;=&#160;QAudioFormat(), QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />int <b><a href="qaudioinput.html#bufferSize">bufferSize</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qaudioinput.html#bytesReady">bytesReady</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qaudioinput.html#elapsedUSecs">elapsedUSecs</a></b> (<i>self</i>)</li><li><div class="fn" />QAudio.Error <b><a href="qaudioinput.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />QAudioFormat <b><a href="qaudioinput.html#format">format</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qaudioinput.html#notifyInterval">notifyInterval</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qaudioinput.html#periodSize">periodSize</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qaudioinput.html#processedUSecs">processedUSecs</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qaudioinput.html#reset">reset</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qaudioinput.html#resume">resume</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qaudioinput.html#setBufferSize">setBufferSize</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qaudioinput.html#setNotifyInterval">setNotifyInterval</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qaudioinput.html#start">start</a></b> (<i>self</i>, QIODevice)</li><li><div class="fn" />QIODevice <b><a href="qaudioinput.html#start-2">start</a></b> (<i>self</i>)</li><li><div class="fn" />QAudio.State <b><a href="qaudioinput.html#state">state</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qaudioinput.html#stop">stop</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qaudioinput.html#suspend">suspend</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qaudioinput.html#notify">notify</a></b> ()</li><li><div class="fn" />void <b><a href="qaudioinput.html#stateChanged">stateChanged</a></b> (QAudio::State)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QAudioInput class provides an interface for receiving audio data from an audio input device.</p>
<p>You can construct an audio input with the system's <a href="qaudiodeviceinfo.html#defaultInputDevice">default audio input device</a>. It is also possible to create QAudioInput with a specific <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a>. When you create the audio input, you should also send in the <a href="qaudioformat.html">QAudioFormat</a> to be used for the recording (see the <a href="qaudioformat.html">QAudioFormat</a> class description for details).</p>
<p>To record to a file:</p>
<p>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 <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a> for a specific device. You also need to pass in the <a href="qaudioformat.html">QAudioFormat</a> in which you wish to record.</p>
<p>Starting up the QAudioInput is simply a matter of calling <a href="qaudioinput.html#start">start</a>() with a <a href="qiodevice.html">QIODevice</a> opened for writing. For instance, to record to a file, you can:</p>
<pre> QFile outputFile;   <span class="comment">// class member.</span>
 QAudioInput* audio; <span class="comment">// class member.</span></pre>
<pre> {
   outputFile.setFileName("/tmp/test.raw");
   outputFile.open( QIODevice.WriteOnly | QIODevice.Truncate );

   QAudioFormat format;
   <span class="comment">// set up the format you want, eg.</span>
   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()&lt;&lt;"default format not supported try to use nearest";
       format = info.nearestFormat(format);
   }

   audio = new QAudioInput(format, this);
   QTimer.singleShot(3000, this, SLOT(stopRecording()));
   audio-&gt;start(&amp;outputFile);
   <span class="comment">// Records audio for 3000ms</span>
 }</pre>
<p>This will start recording if the format specified is supported by the input device (you can check this with <a href="qaudiodeviceinfo.html#isFormatSupported">QAudioDeviceInfo.isFormatSupported</a>(). In case there are any snags, use the <a href="qaudioinput.html#error">error</a>() function to check what went wrong. We stop recording in the <tt>stopRecording()</tt> slot.</p>
<pre> void stopRecording()
 {
   audio-&gt;stop();
   outputFile-&gt;close();
   delete audio;
 }</pre>
<p>At any point in time, QAudioInput will be in one of four states: active, suspended, stopped, or idle. These states are specified by the <a href="qaudio.html#State-enum">QAudio.State</a> enum. You can request a state change directly through <a href="qaudioinput.html#suspend">suspend</a>(), <a href="qaudioinput.html#resume">resume</a>(), <a href="qaudioinput.html#stop">stop</a>(), <a href="qaudioinput.html#reset">reset</a>(), and <a href="qaudioinput.html#start">start</a>(). The current state is reported by <a href="qaudioinput.html#state">state</a>(). <a href="qaudiooutput.html">QAudioOutput</a> will also signal you when the state changes (<a href="qaudioinput.html#stateChanged">stateChanged</a>()).</p>
<p>QAudioInput provides several ways of measuring the time that has passed since the <a href="qaudioinput.html#start">start</a>() of the recording. The <tt>processedUSecs()</tt> 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 <a href="qaudioinput.html#elapsedUSecs">elapsedUSecs</a>() function returns the time elapsed since <a href="qaudioinput.html#start">start</a>() was called regardless of which states the QAudioInput has been in.</p>
<p>If an error should occur, you can fetch its reason with <a href="qaudioinput.html#error">error</a>(). The possible error reasons are described by the <a href="qaudio.html#Error-enum">QAudio.Error</a> enum. The QAudioInput will enter the <a href="qaudio.html#State-enum">StoppedState</a> when an error is encountered. Connect to the <a href="qaudioinput.html#stateChanged">stateChanged</a>() signal to handle the error:</p>
<pre>     void stateChanged(QAudio.State newState)
     {
         switch(newState) {
             case QAudio.StopState:
             if (input-&gt;error() != QAudio.NoError) {
                 <span class="comment">// Error handling</span>
             } else {

             }
             break;</pre>
<p>See also <a href="qaudiooutput.html">QAudioOutput</a> and <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QAudioInput" />QAudioInput.__init__ (<i>self</i>, <a href="qaudioformat.html">QAudioFormat</a>&#160;<i>format</i>&#160;=&#160;QAudioFormat(), <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Construct a new audio input and attach it to <i>parent</i>. The default audio input device is used with the output <i>format</i> parameters.</p>
<h3 class="fn"><a name="QAudioInput-2" />QAudioInput.__init__ (<i>self</i>, <a href="qaudiodeviceinfo.html">QAudioDeviceInfo</a>, <a href="qaudioformat.html">QAudioFormat</a>&#160;<i>format</i>&#160;=&#160;QAudioFormat(), <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Construct a new audio input and attach it to <i>parent</i>. The device referenced by <i>audioDevice</i> is used with the input <i>format</i> parameters.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/~QAudioInput" />
<h3 class="fn"><a name="bufferSize" />int QAudioInput.bufferSize (<i>self</i>)</h3><p>Returns the audio buffer size in milliseconds.</p>
<p>If called before <a href="qaudioinput.html#start">start</a>(), returns platform default value. If called before <a href="qaudioinput.html#start">start</a>() but <a href="qaudioinput.html#setBufferSize">setBufferSize</a>() was called prior, returns value set by <a href="qaudioinput.html#setBufferSize">setBufferSize</a>(). If called after <a href="qaudioinput.html#start">start</a>(), returns the actual buffer size being used. This may not be what was set previously by <a href="qaudioinput.html#setBufferSize">setBufferSize</a>().</p>
<p>See also <a href="qaudioinput.html#setBufferSize">setBufferSize</a>().</p>
<a name="//apple_ref/cpp/instm/QAudioInput/bytesReady" />
<h3 class="fn"><a name="bytesReady" />int QAudioInput.bytesReady (<i>self</i>)</h3><p>Returns the amount of audio data available to read in bytes.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/elapsedUSecs" />
<h3 class="fn"><a name="elapsedUSecs" />int QAudioInput.elapsedUSecs (<i>self</i>)</h3><p>Returns the microseconds since <a href="qaudioinput.html#start">start</a>() was called, including time in Idle and Suspend states.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/error" />
<h3 class="fn"><a name="error" /><a href="qaudio.html#Error-enum">QAudio.Error</a> QAudioInput.error (<i>self</i>)</h3><p>Returns the error state.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/format" />
<h3 class="fn"><a name="format" /><a href="qaudioformat.html">QAudioFormat</a> QAudioInput.format (<i>self</i>)</h3><p>Returns the <a href="qaudioformat.html">QAudioFormat</a> being used.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/notify" />
<h3 class="fn"><a name="notifyInterval" />int QAudioInput.notifyInterval (<i>self</i>)</h3><p>Returns the notify interval in milliseconds.</p>
<p>See also <a href="qaudioinput.html#setNotifyInterval">setNotifyInterval</a>().</p>
<a name="//apple_ref/cpp/instm/QAudioInput/periodSize" />
<h3 class="fn"><a name="periodSize" />int QAudioInput.periodSize (<i>self</i>)</h3><p>Returns the period size in bytes.</p>
<p>Note: This is the recommended read size in bytes.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/processedUSecs" />
<h3 class="fn"><a name="processedUSecs" />int QAudioInput.processedUSecs (<i>self</i>)</h3><p>Returns the amount of audio data processed since <a href="qaudioinput.html#start">start</a>() was called in microseconds.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/reset" />
<h3 class="fn"><a name="reset" />QAudioInput.reset (<i>self</i>)</h3><p>Drops all audio data in the buffers, resets buffers to zero.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/resume" />
<h3 class="fn"><a name="resume" />QAudioInput.resume (<i>self</i>)</h3><p>Resumes processing audio data after a <a href="qaudioinput.html#suspend">suspend</a>().</p>
<a name="//apple_ref/cpp/instm/QAudioInput/setBufferSize" />
<h3 class="fn"><a name="setBufferSize" />QAudioInput.setBufferSize (<i>self</i>, int)</h3><p>Sets the audio buffer size to <i>value</i> milliseconds.</p>
<p>Note: This function can be called anytime before <a href="qaudioinput.html#start">start</a>(), calls to this are ignored after <a href="qaudioinput.html#start">start</a>(). It should not be assumed that the buffer size set is the actual buffer size used, calling <a href="qaudioinput.html#bufferSize">bufferSize</a>() anytime after <a href="qaudioinput.html#start">start</a>() will return the actual buffer size being used.</p>
<p>See also <a href="qaudioinput.html#bufferSize">bufferSize</a>().</p>
<a name="//apple_ref/cpp/instm/QAudioInput/setNotifyInterval" />
<h3 class="fn"><a name="setNotifyInterval" />QAudioInput.setNotifyInterval (<i>self</i>, int)</h3><p>Sets the interval for <a href="qaudioinput.html#notify">notify</a>() signal to be emitted. This is based on the <i>ms</i> of audio data processed not on actual real-time. The resolution of the timer is platform specific.</p>
<p>See also <a href="qaudioinput.html#notifyInterval">notifyInterval</a>().</p>
<a name="//apple_ref/cpp/instm/QAudioInput/start" />
<h3 class="fn"><a name="start" />QAudioInput.start (<i>self</i>, <a href="qiodevice.html">QIODevice</a>)</h3><p>Uses the <i>device</i> as the <a href="qiodevice.html">QIODevice</a> to transfer data. Passing a <a href="qiodevice.html">QIODevice</a> allows the data to be transfered without any extra code. All that is required is to open the <a href="qiodevice.html">QIODevice</a>.</p>
<p>See also <a href="qiodevice.html">QIODevice</a>.</p>
<h3 class="fn"><a name="start-2" /><a href="qiodevice.html">QIODevice</a> QAudioInput.start (<i>self</i>)</h3><p>Returns a pointer to the <a href="qiodevice.html">QIODevice</a> being used to handle the data transfer. This <a href="qiodevice.html">QIODevice</a> can be used to read() audio data directly.</p>
<p>See also <a href="qiodevice.html">QIODevice</a>.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/state" />
<h3 class="fn"><a name="state" /><a href="qaudio.html#State-enum">QAudio.State</a> QAudioInput.state (<i>self</i>)</h3><p>Returns the state of audio processing.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/stateChanged" />
<h3 class="fn"><a name="stop" />QAudioInput.stop (<i>self</i>)</h3><p>Stops the audio input.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/suspend" />
<h3 class="fn"><a name="suspend" />QAudioInput.suspend (<i>self</i>)</h3><p>Stops processing audio data, preserving buffered audio data.</p>
<p /><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="notify" />void notify ()</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when x ms of audio data has been processed the interval set by setNotifyInterval(x).</p>
<a name="//apple_ref/cpp/instm/QAudioInput/notifyInterval" />
<h3 class="fn"><a name="stateChanged" />void stateChanged (QAudio::State)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when the device <i>state</i> has changed.</p>
<a name="//apple_ref/cpp/instm/QAudioInput/stop" />
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.7.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt&#160;4.6.2</td></tr></table></div></address></body></html>