gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

774 lines
59KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="ossaudiodev — Access to OSS-compatible audio devices" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/ossaudiodev.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This module allows you to access the OSS (Open Sound System) audio interface. OSS is available for a wide range of open-source and commercial Unices, and is the standard audio interface for Linux a..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="This module allows you to access the OSS (Open Sound System) audio interface. OSS is available for a wide range of open-source and commercial Unices, and is the standard audio interface for Linux a..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>ossaudiodev — Access to OSS-compatible audio devices &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="pipes — Interface to shell pipelines" href="pipes.html" />
  33. <link rel="prev" title="optparse — Parser for command line options" href="optparse.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/ossaudiodev.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code> — Access to OSS-compatible audio devices</a><ul>
  86. <li><a class="reference internal" href="#audio-device-objects">Audio Device Objects</a></li>
  87. <li><a class="reference internal" href="#mixer-device-objects">Mixer Device Objects</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div>
  92. <div>
  93. <h4>Previous topic</h4>
  94. <p class="topless"><a href="optparse.html"
  95. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code> — Parser for command line options</a></p>
  96. </div>
  97. <div>
  98. <h4>Next topic</h4>
  99. <p class="topless"><a href="pipes.html"
  100. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code> — Interface to shell pipelines</a></p>
  101. </div>
  102. <div role="note" aria-label="source link">
  103. <h3>This Page</h3>
  104. <ul class="this-page-menu">
  105. <li><a href="../bugs.html">Report a Bug</a></li>
  106. <li>
  107. <a href="https://github.com/python/cpython/blob/main/Doc/library/ossaudiodev.rst"
  108. rel="nofollow">Show Source
  109. </a>
  110. </li>
  111. </ul>
  112. </div>
  113. </nav>
  114. </div>
  115. </div>
  116. <div class="related" role="navigation" aria-label="related navigation">
  117. <h3>Navigation</h3>
  118. <ul>
  119. <li class="right" style="margin-right: 10px">
  120. <a href="../genindex.html" title="General Index"
  121. accesskey="I">index</a></li>
  122. <li class="right" >
  123. <a href="../py-modindex.html" title="Python Module Index"
  124. >modules</a> |</li>
  125. <li class="right" >
  126. <a href="pipes.html" title="pipes — Interface to shell pipelines"
  127. accesskey="N">next</a> |</li>
  128. <li class="right" >
  129. <a href="optparse.html" title="optparse — Parser for command line options"
  130. accesskey="P">previous</a> |</li>
  131. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  132. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  133. <li class="switchers">
  134. <div class="language_switcher_placeholder"></div>
  135. <div class="version_switcher_placeholder"></div>
  136. </li>
  137. <li>
  138. </li>
  139. <li id="cpython-language-and-version">
  140. <a href="../index.html">3.12.3 Documentation</a> &#187;
  141. </li>
  142. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  143. <li class="nav-item nav-item-2"><a href="superseded.html" accesskey="U">Superseded Modules</a> &#187;</li>
  144. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code> — Access to OSS-compatible audio devices</a></li>
  145. <li class="right">
  146. <div class="inline-search" role="search">
  147. <form class="inline-search" action="../search.html" method="get">
  148. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  149. <input type="submit" value="Go" />
  150. </form>
  151. </div>
  152. |
  153. </li>
  154. <li class="right">
  155. <label class="theme-selector-label">
  156. Theme
  157. <select class="theme-selector" oninput="activateTheme(this.value)">
  158. <option value="auto" selected>Auto</option>
  159. <option value="light">Light</option>
  160. <option value="dark">Dark</option>
  161. </select>
  162. </label> |</li>
  163. </ul>
  164. </div>
  165. <div class="document">
  166. <div class="documentwrapper">
  167. <div class="bodywrapper">
  168. <div class="body" role="main">
  169. <section id="module-ossaudiodev">
  170. <span id="ossaudiodev-access-to-oss-compatible-audio-devices"></span><h1><a class="reference internal" href="#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a> — Access to OSS-compatible audio devices<a class="headerlink" href="#module-ossaudiodev" title="Link to this heading">¶</a></h1>
  171. <div class="deprecated-removed">
  172. <p><span class="versionmodified">Deprecated since version 3.11, will be removed in version 3.13: </span>The <a class="reference internal" href="#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a> module is deprecated
  173. (see <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/#ossaudiodev"><strong>PEP 594</strong></a> for details).</p>
  174. </div>
  175. <hr class="docutils" />
  176. <p>This module allows you to access the OSS (Open Sound System) audio interface.
  177. OSS is available for a wide range of open-source and commercial Unices, and is
  178. the standard audio interface for Linux and recent versions of FreeBSD.</p>
  179. <div class="versionchanged">
  180. <p><span class="versionmodified changed">Changed in version 3.3: </span>Operations in this module now raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> where <a class="reference internal" href="exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>
  181. was raised.</p>
  182. </div>
  183. <div class="admonition seealso">
  184. <p class="admonition-title">See also</p>
  185. <dl class="simple">
  186. <dt><a class="reference external" href="http://www.opensound.com/pguide/oss.pdf">Open Sound System Programmer’s Guide</a></dt><dd><p>the official documentation for the OSS C API</p>
  187. </dd>
  188. </dl>
  189. <p>The module defines a large number of constants supplied by the OSS device
  190. driver; see <code class="docutils literal notranslate"><span class="pre">&lt;sys/soundcard.h&gt;</span></code> on either Linux or FreeBSD for a listing.</p>
  191. </div>
  192. <p><a class="reference internal" href="#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a> defines the following variables and functions:</p>
  193. <dl class="py exception">
  194. <dt class="sig sig-object py" id="ossaudiodev.OSSAudioError">
  195. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">ossaudiodev.</span></span><span class="sig-name descname"><span class="pre">OSSAudioError</span></span><a class="headerlink" href="#ossaudiodev.OSSAudioError" title="Link to this definition">¶</a></dt>
  196. <dd><p>This exception is raised on certain errors. The argument is a string describing
  197. what went wrong.</p>
  198. <p>(If <a class="reference internal" href="#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a> receives an error from a system call such as
  199. <code class="xref c c-func docutils literal notranslate"><span class="pre">open()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">write()</span></code>, or <code class="xref c c-func docutils literal notranslate"><span class="pre">ioctl()</span></code>, it raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.
  200. Errors detected directly by <a class="reference internal" href="#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a> result in <a class="reference internal" href="#ossaudiodev.OSSAudioError" title="ossaudiodev.OSSAudioError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSSAudioError</span></code></a>.)</p>
  201. <p>(For backwards compatibility, the exception class is also available as
  202. <code class="docutils literal notranslate"><span class="pre">ossaudiodev.error</span></code>.)</p>
  203. </dd></dl>
  204. <dl class="py function">
  205. <dt class="sig sig-object py" id="ossaudiodev.open">
  206. <span class="sig-prename descclassname"><span class="pre">ossaudiodev.</span></span><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.open" title="Link to this definition">¶</a></dt>
  207. <dt class="sig sig-object py">
  208. <span class="sig-prename descclassname"><span class="pre">ossaudiodev.</span></span><span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">device</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span></dt>
  209. <dd><p>Open an audio device and return an OSS audio device object. This object
  210. supports many file-like methods, such as <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code>, and
  211. <code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code> (although there are subtle differences between conventional Unix
  212. read/write semantics and those of OSS audio devices). It also supports a number
  213. of audio-specific methods; see below for the complete list of methods.</p>
  214. <p><em>device</em> is the audio device filename to use. If it is not specified, this
  215. module first looks in the environment variable <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">AUDIODEV</span></code> for a device
  216. to use. If not found, it falls back to <code class="file docutils literal notranslate"><span class="pre">/dev/dsp</span></code>.</p>
  217. <p><em>mode</em> is one of <code class="docutils literal notranslate"><span class="pre">'r'</span></code> for read-only (record) access, <code class="docutils literal notranslate"><span class="pre">'w'</span></code> for
  218. write-only (playback) access and <code class="docutils literal notranslate"><span class="pre">'rw'</span></code> for both. Since many sound cards
  219. only allow one process to have the recorder or player open at a time, it is a
  220. good idea to open the device only for the activity needed. Further, some
  221. sound cards are half-duplex: they can be opened for reading or writing, but
  222. not both at once.</p>
  223. <p>Note the unusual calling syntax: the <em>first</em> argument is optional, and the
  224. second is required. This is a historical artifact for compatibility with the
  225. older <code class="xref py py-mod docutils literal notranslate"><span class="pre">linuxaudiodev</span></code> module which <a class="reference internal" href="#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a> supersedes.</p>
  226. </dd></dl>
  227. <dl class="py function">
  228. <dt class="sig sig-object py" id="ossaudiodev.openmixer">
  229. <span class="sig-prename descclassname"><span class="pre">ossaudiodev.</span></span><span class="sig-name descname"><span class="pre">openmixer</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">device</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.openmixer" title="Link to this definition">¶</a></dt>
  230. <dd><p>Open a mixer device and return an OSS mixer device object. <em>device</em> is the
  231. mixer device filename to use. If it is not specified, this module first looks
  232. in the environment variable <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">MIXERDEV</span></code> for a device to use. If not
  233. found, it falls back to <code class="file docutils literal notranslate"><span class="pre">/dev/mixer</span></code>.</p>
  234. </dd></dl>
  235. <section id="audio-device-objects">
  236. <span id="ossaudio-device-objects"></span><h2>Audio Device Objects<a class="headerlink" href="#audio-device-objects" title="Link to this heading">¶</a></h2>
  237. <p>Before you can write to or read from an audio device, you must call three
  238. methods in the correct order:</p>
  239. <ol class="arabic simple">
  240. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">setfmt()</span></code> to set the output format</p></li>
  241. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">channels()</span></code> to set the number of channels</p></li>
  242. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">speed()</span></code> to set the sample rate</p></li>
  243. </ol>
  244. <p>Alternately, you can use the <code class="xref py py-meth docutils literal notranslate"><span class="pre">setparameters()</span></code> method to set all three audio
  245. parameters at once. This is more convenient, but may not be as flexible in all
  246. cases.</p>
  247. <p>The audio device objects returned by <a class="reference internal" href="#ossaudiodev.open" title="ossaudiodev.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> define the following methods
  248. and (read-only) attributes:</p>
  249. <dl class="py method">
  250. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.close">
  251. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.close" title="Link to this definition">¶</a></dt>
  252. <dd><p>Explicitly close the audio device. When you are done writing to or reading from
  253. an audio device, you should explicitly close it. A closed device cannot be used
  254. again.</p>
  255. </dd></dl>
  256. <dl class="py method">
  257. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.fileno">
  258. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">fileno</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.fileno" title="Link to this definition">¶</a></dt>
  259. <dd><p>Return the file descriptor associated with the device.</p>
  260. </dd></dl>
  261. <dl class="py method">
  262. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.read">
  263. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">size</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.read" title="Link to this definition">¶</a></dt>
  264. <dd><p>Read <em>size</em> bytes from the audio input and return them as a Python string.
  265. Unlike most Unix device drivers, OSS audio devices in blocking mode (the
  266. default) will block <a class="reference internal" href="#ossaudiodev.oss_audio_device.read" title="ossaudiodev.oss_audio_device.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a> until the entire requested amount of data is
  267. available.</p>
  268. </dd></dl>
  269. <dl class="py method">
  270. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.write">
  271. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.write" title="Link to this definition">¶</a></dt>
  272. <dd><p>Write a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> <em>data</em> to the audio device and return the
  273. number of bytes written. If the audio device is in blocking mode (the
  274. default), the entire data is always written (again, this is different from
  275. usual Unix device semantics). If the device is in non-blocking mode, some
  276. data may not be written—see <a class="reference internal" href="#ossaudiodev.oss_audio_device.writeall" title="ossaudiodev.oss_audio_device.writeall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeall()</span></code></a>.</p>
  277. <div class="versionchanged">
  278. <p><span class="versionmodified changed">Changed in version 3.5: </span>Writable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is now accepted.</p>
  279. </div>
  280. </dd></dl>
  281. <dl class="py method">
  282. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.writeall">
  283. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">writeall</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">data</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.writeall" title="Link to this definition">¶</a></dt>
  284. <dd><p>Write a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> <em>data</em> to the audio device: waits until
  285. the audio device is able to accept data, writes as much data as it will
  286. accept, and repeats until <em>data</em> has been completely written. If the device
  287. is in blocking mode (the default), this has the same effect as
  288. <a class="reference internal" href="#ossaudiodev.oss_audio_device.write" title="ossaudiodev.oss_audio_device.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a>; <a class="reference internal" href="#ossaudiodev.oss_audio_device.writeall" title="ossaudiodev.oss_audio_device.writeall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeall()</span></code></a> is only useful in non-blocking mode. Has
  289. no return value, since the amount of data written is always equal to the
  290. amount of data supplied.</p>
  291. <div class="versionchanged">
  292. <p><span class="versionmodified changed">Changed in version 3.5: </span>Writable <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is now accepted.</p>
  293. </div>
  294. </dd></dl>
  295. <div class="versionchanged">
  296. <p><span class="versionmodified changed">Changed in version 3.2: </span>Audio device objects also support the context management protocol, i.e. they can
  297. be used in a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement.</p>
  298. </div>
  299. <p>The following methods each map to exactly one <code class="xref c c-func docutils literal notranslate"><span class="pre">ioctl()</span></code> system call. The
  300. correspondence is obvious: for example, <code class="xref py py-meth docutils literal notranslate"><span class="pre">setfmt()</span></code> corresponds to the
  301. <code class="docutils literal notranslate"><span class="pre">SNDCTL_DSP_SETFMT</span></code> ioctl, and <code class="xref py py-meth docutils literal notranslate"><span class="pre">sync()</span></code> to <code class="docutils literal notranslate"><span class="pre">SNDCTL_DSP_SYNC</span></code> (this can
  302. be useful when consulting the OSS documentation). If the underlying
  303. <code class="xref c c-func docutils literal notranslate"><span class="pre">ioctl()</span></code> fails, they all raise <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
  304. <dl class="py method">
  305. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.nonblock">
  306. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">nonblock</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.nonblock" title="Link to this definition">¶</a></dt>
  307. <dd><p>Put the device into non-blocking mode. Once in non-blocking mode, there is no
  308. way to return it to blocking mode.</p>
  309. </dd></dl>
  310. <dl class="py method">
  311. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.getfmts">
  312. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">getfmts</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.getfmts" title="Link to this definition">¶</a></dt>
  313. <dd><p>Return a bitmask of the audio output formats supported by the soundcard. Some
  314. of the formats supported by OSS are:</p>
  315. <table class="docutils align-default">
  316. <thead>
  317. <tr class="row-odd"><th class="head"><p>Format</p></th>
  318. <th class="head"><p>Description</p></th>
  319. </tr>
  320. </thead>
  321. <tbody>
  322. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_MU_LAW</span></code></p></td>
  323. <td><p>a logarithmic encoding (used by Sun <code class="docutils literal notranslate"><span class="pre">.au</span></code>
  324. files and <code class="file docutils literal notranslate"><span class="pre">/dev/audio</span></code>)</p></td>
  325. </tr>
  326. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_A_LAW</span></code></p></td>
  327. <td><p>a logarithmic encoding</p></td>
  328. </tr>
  329. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_IMA_ADPCM</span></code></p></td>
  330. <td><p>a 4:1 compressed format defined by the
  331. Interactive Multimedia Association</p></td>
  332. </tr>
  333. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_U8</span></code></p></td>
  334. <td><p>Unsigned, 8-bit audio</p></td>
  335. </tr>
  336. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_S16_LE</span></code></p></td>
  337. <td><p>Signed, 16-bit audio, little-endian byte
  338. order (as used by Intel processors)</p></td>
  339. </tr>
  340. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_S16_BE</span></code></p></td>
  341. <td><p>Signed, 16-bit audio, big-endian byte order
  342. (as used by 68k, PowerPC, Sparc)</p></td>
  343. </tr>
  344. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_S8</span></code></p></td>
  345. <td><p>Signed, 8 bit audio</p></td>
  346. </tr>
  347. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_U16_LE</span></code></p></td>
  348. <td><p>Unsigned, 16-bit little-endian audio</p></td>
  349. </tr>
  350. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_U16_BE</span></code></p></td>
  351. <td><p>Unsigned, 16-bit big-endian audio</p></td>
  352. </tr>
  353. </tbody>
  354. </table>
  355. <p>Consult the OSS documentation for a full list of audio formats, and note that
  356. most devices support only a subset of these formats. Some older devices only
  357. support <code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_U8</span></code>; the most common format used today is
  358. <code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_S16_LE</span></code>.</p>
  359. </dd></dl>
  360. <dl class="py method">
  361. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.setfmt">
  362. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">setfmt</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">format</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.setfmt" title="Link to this definition">¶</a></dt>
  363. <dd><p>Try to set the current audio format to <em>format</em>—see <a class="reference internal" href="#ossaudiodev.oss_audio_device.getfmts" title="ossaudiodev.oss_audio_device.getfmts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getfmts()</span></code></a> for a
  364. list. Returns the audio format that the device was set to, which may not be the
  365. requested format. May also be used to return the current audio format—do this
  366. by passing an “audio format” of <code class="xref py py-const docutils literal notranslate"><span class="pre">AFMT_QUERY</span></code>.</p>
  367. </dd></dl>
  368. <dl class="py method">
  369. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.channels">
  370. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">channels</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">nchannels</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.channels" title="Link to this definition">¶</a></dt>
  371. <dd><p>Set the number of output channels to <em>nchannels</em>. A value of 1 indicates
  372. monophonic sound, 2 stereophonic. Some devices may have more than 2 channels,
  373. and some high-end devices may not support mono. Returns the number of channels
  374. the device was set to.</p>
  375. </dd></dl>
  376. <dl class="py method">
  377. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.speed">
  378. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">speed</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">samplerate</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.speed" title="Link to this definition">¶</a></dt>
  379. <dd><p>Try to set the audio sampling rate to <em>samplerate</em> samples per second. Returns
  380. the rate actually set. Most sound devices don’t support arbitrary sampling
  381. rates. Common rates are:</p>
  382. <table class="docutils align-default">
  383. <thead>
  384. <tr class="row-odd"><th class="head"><p>Rate</p></th>
  385. <th class="head"><p>Description</p></th>
  386. </tr>
  387. </thead>
  388. <tbody>
  389. <tr class="row-even"><td><p>8000</p></td>
  390. <td><p>default rate for <code class="file docutils literal notranslate"><span class="pre">/dev/audio</span></code></p></td>
  391. </tr>
  392. <tr class="row-odd"><td><p>11025</p></td>
  393. <td><p>speech recording</p></td>
  394. </tr>
  395. <tr class="row-even"><td><p>22050</p></td>
  396. <td></td>
  397. </tr>
  398. <tr class="row-odd"><td><p>44100</p></td>
  399. <td><p>CD quality audio (at 16 bits/sample and 2
  400. channels)</p></td>
  401. </tr>
  402. <tr class="row-even"><td><p>96000</p></td>
  403. <td><p>DVD quality audio (at 24 bits/sample)</p></td>
  404. </tr>
  405. </tbody>
  406. </table>
  407. </dd></dl>
  408. <dl class="py method">
  409. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.sync">
  410. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">sync</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.sync" title="Link to this definition">¶</a></dt>
  411. <dd><p>Wait until the sound device has played every byte in its buffer. (This happens
  412. implicitly when the device is closed.) The OSS documentation recommends closing
  413. and re-opening the device rather than using <a class="reference internal" href="#ossaudiodev.oss_audio_device.sync" title="ossaudiodev.oss_audio_device.sync"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sync()</span></code></a>.</p>
  414. </dd></dl>
  415. <dl class="py method">
  416. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.reset">
  417. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">reset</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.reset" title="Link to this definition">¶</a></dt>
  418. <dd><p>Immediately stop playing or recording and return the device to a state where it
  419. can accept commands. The OSS documentation recommends closing and re-opening
  420. the device after calling <a class="reference internal" href="#ossaudiodev.oss_audio_device.reset" title="ossaudiodev.oss_audio_device.reset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reset()</span></code></a>.</p>
  421. </dd></dl>
  422. <dl class="py method">
  423. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.post">
  424. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">post</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.post" title="Link to this definition">¶</a></dt>
  425. <dd><p>Tell the driver that there is likely to be a pause in the output, making it
  426. possible for the device to handle the pause more intelligently. You might use
  427. this after playing a spot sound effect, before waiting for user input, or before
  428. doing disk I/O.</p>
  429. </dd></dl>
  430. <p>The following convenience methods combine several ioctls, or one ioctl and some
  431. simple calculations.</p>
  432. <dl class="py method">
  433. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.setparameters">
  434. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">setparameters</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">format</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nchannels</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">samplerate</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">strict=False</span></span></em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.setparameters" title="Link to this definition">¶</a></dt>
  435. <dd><p>Set the key audio sampling parameters—sample format, number of channels, and
  436. sampling rate—in one method call. <em>format</em>, <em>nchannels</em>, and <em>samplerate</em>
  437. should be as specified in the <a class="reference internal" href="#ossaudiodev.oss_audio_device.setfmt" title="ossaudiodev.oss_audio_device.setfmt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setfmt()</span></code></a>, <a class="reference internal" href="#ossaudiodev.oss_audio_device.channels" title="ossaudiodev.oss_audio_device.channels"><code class="xref py py-meth docutils literal notranslate"><span class="pre">channels()</span></code></a>, and
  438. <a class="reference internal" href="#ossaudiodev.oss_audio_device.speed" title="ossaudiodev.oss_audio_device.speed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">speed()</span></code></a> methods. If <em>strict</em> is true, <a class="reference internal" href="#ossaudiodev.oss_audio_device.setparameters" title="ossaudiodev.oss_audio_device.setparameters"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setparameters()</span></code></a> checks to
  439. see if each parameter was actually set to the requested value, and raises
  440. <a class="reference internal" href="#ossaudiodev.OSSAudioError" title="ossaudiodev.OSSAudioError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSSAudioError</span></code></a> if not. Returns a tuple (<em>format</em>, <em>nchannels</em>,
  441. <em>samplerate</em>) indicating the parameter values that were actually set by the
  442. device driver (i.e., the same as the return values of <a class="reference internal" href="#ossaudiodev.oss_audio_device.setfmt" title="ossaudiodev.oss_audio_device.setfmt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setfmt()</span></code></a>,
  443. <a class="reference internal" href="#ossaudiodev.oss_audio_device.channels" title="ossaudiodev.oss_audio_device.channels"><code class="xref py py-meth docutils literal notranslate"><span class="pre">channels()</span></code></a>, and <a class="reference internal" href="#ossaudiodev.oss_audio_device.speed" title="ossaudiodev.oss_audio_device.speed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">speed()</span></code></a>).</p>
  444. <p>For example,</p>
  445. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">fmt</span><span class="p">,</span> <span class="n">channels</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span> <span class="o">=</span> <span class="n">dsp</span><span class="o">.</span><span class="n">setparameters</span><span class="p">(</span><span class="n">fmt</span><span class="p">,</span> <span class="n">channels</span><span class="p">,</span> <span class="n">rate</span><span class="p">)</span>
  446. </pre></div>
  447. </div>
  448. <p>is equivalent to</p>
  449. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">fmt</span> <span class="o">=</span> <span class="n">dsp</span><span class="o">.</span><span class="n">setfmt</span><span class="p">(</span><span class="n">fmt</span><span class="p">)</span>
  450. <span class="n">channels</span> <span class="o">=</span> <span class="n">dsp</span><span class="o">.</span><span class="n">channels</span><span class="p">(</span><span class="n">channels</span><span class="p">)</span>
  451. <span class="n">rate</span> <span class="o">=</span> <span class="n">dsp</span><span class="o">.</span><span class="n">rate</span><span class="p">(</span><span class="n">rate</span><span class="p">)</span>
  452. </pre></div>
  453. </div>
  454. </dd></dl>
  455. <dl class="py method">
  456. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.bufsize">
  457. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">bufsize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.bufsize" title="Link to this definition">¶</a></dt>
  458. <dd><p>Returns the size of the hardware buffer, in samples.</p>
  459. </dd></dl>
  460. <dl class="py method">
  461. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.obufcount">
  462. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">obufcount</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.obufcount" title="Link to this definition">¶</a></dt>
  463. <dd><p>Returns the number of samples that are in the hardware buffer yet to be played.</p>
  464. </dd></dl>
  465. <dl class="py method">
  466. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.obuffree">
  467. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">obuffree</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_audio_device.obuffree" title="Link to this definition">¶</a></dt>
  468. <dd><p>Returns the number of samples that could be queued into the hardware buffer to
  469. be played without blocking.</p>
  470. </dd></dl>
  471. <p>Audio device objects also support several read-only attributes:</p>
  472. <dl class="py attribute">
  473. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.closed">
  474. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">closed</span></span><a class="headerlink" href="#ossaudiodev.oss_audio_device.closed" title="Link to this definition">¶</a></dt>
  475. <dd><p>Boolean indicating whether the device has been closed.</p>
  476. </dd></dl>
  477. <dl class="py attribute">
  478. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.name">
  479. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">name</span></span><a class="headerlink" href="#ossaudiodev.oss_audio_device.name" title="Link to this definition">¶</a></dt>
  480. <dd><p>String containing the name of the device file.</p>
  481. </dd></dl>
  482. <dl class="py attribute">
  483. <dt class="sig sig-object py" id="ossaudiodev.oss_audio_device.mode">
  484. <span class="sig-prename descclassname"><span class="pre">oss_audio_device.</span></span><span class="sig-name descname"><span class="pre">mode</span></span><a class="headerlink" href="#ossaudiodev.oss_audio_device.mode" title="Link to this definition">¶</a></dt>
  485. <dd><p>The I/O mode for the file, either <code class="docutils literal notranslate"><span class="pre">&quot;r&quot;</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;rw&quot;</span></code>, or <code class="docutils literal notranslate"><span class="pre">&quot;w&quot;</span></code>.</p>
  486. </dd></dl>
  487. </section>
  488. <section id="mixer-device-objects">
  489. <span id="id1"></span><h2>Mixer Device Objects<a class="headerlink" href="#mixer-device-objects" title="Link to this heading">¶</a></h2>
  490. <p>The mixer object provides two file-like methods:</p>
  491. <dl class="py method">
  492. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.close">
  493. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.close" title="Link to this definition">¶</a></dt>
  494. <dd><p>This method closes the open mixer device file. Any further attempts to use the
  495. mixer after this file is closed will raise an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
  496. </dd></dl>
  497. <dl class="py method">
  498. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.fileno">
  499. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">fileno</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.fileno" title="Link to this definition">¶</a></dt>
  500. <dd><p>Returns the file handle number of the open mixer device file.</p>
  501. </dd></dl>
  502. <div class="versionchanged">
  503. <p><span class="versionmodified changed">Changed in version 3.2: </span>Mixer objects also support the context management protocol.</p>
  504. </div>
  505. <p>The remaining methods are specific to audio mixing:</p>
  506. <dl class="py method">
  507. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.controls">
  508. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">controls</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.controls" title="Link to this definition">¶</a></dt>
  509. <dd><p>This method returns a bitmask specifying the available mixer controls (“Control”
  510. being a specific mixable “channel”, such as <code class="xref py py-const docutils literal notranslate"><span class="pre">SOUND_MIXER_PCM</span></code> or
  511. <code class="xref py py-const docutils literal notranslate"><span class="pre">SOUND_MIXER_SYNTH</span></code>). This bitmask indicates a subset of all available
  512. mixer controls—the <code class="xref py py-const docutils literal notranslate"><span class="pre">SOUND_MIXER_*</span></code> constants defined at module level.
  513. To determine if, for example, the current mixer object supports a PCM mixer, use
  514. the following Python code:</p>
  515. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">mixer</span><span class="o">=</span><span class="n">ossaudiodev</span><span class="o">.</span><span class="n">openmixer</span><span class="p">()</span>
  516. <span class="k">if</span> <span class="n">mixer</span><span class="o">.</span><span class="n">controls</span><span class="p">()</span> <span class="o">&amp;</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">ossaudiodev</span><span class="o">.</span><span class="n">SOUND_MIXER_PCM</span><span class="p">):</span>
  517. <span class="c1"># PCM is supported</span>
  518. <span class="o">...</span> <span class="n">code</span> <span class="o">...</span>
  519. </pre></div>
  520. </div>
  521. <p>For most purposes, the <code class="xref py py-const docutils literal notranslate"><span class="pre">SOUND_MIXER_VOLUME</span></code> (master volume) and
  522. <code class="xref py py-const docutils literal notranslate"><span class="pre">SOUND_MIXER_PCM</span></code> controls should suffice—but code that uses the mixer
  523. should be flexible when it comes to choosing mixer controls. On the Gravis
  524. Ultrasound, for example, <code class="xref py py-const docutils literal notranslate"><span class="pre">SOUND_MIXER_VOLUME</span></code> does not exist.</p>
  525. </dd></dl>
  526. <dl class="py method">
  527. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.stereocontrols">
  528. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">stereocontrols</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.stereocontrols" title="Link to this definition">¶</a></dt>
  529. <dd><p>Returns a bitmask indicating stereo mixer controls. If a bit is set, the
  530. corresponding control is stereo; if it is unset, the control is either
  531. monophonic or not supported by the mixer (use in combination with
  532. <a class="reference internal" href="#ossaudiodev.oss_mixer_device.controls" title="ossaudiodev.oss_mixer_device.controls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">controls()</span></code></a> to determine which).</p>
  533. <p>See the code example for the <a class="reference internal" href="#ossaudiodev.oss_mixer_device.controls" title="ossaudiodev.oss_mixer_device.controls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">controls()</span></code></a> function for an example of getting
  534. data from a bitmask.</p>
  535. </dd></dl>
  536. <dl class="py method">
  537. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.reccontrols">
  538. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">reccontrols</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.reccontrols" title="Link to this definition">¶</a></dt>
  539. <dd><p>Returns a bitmask specifying the mixer controls that may be used to record. See
  540. the code example for <a class="reference internal" href="#ossaudiodev.oss_mixer_device.controls" title="ossaudiodev.oss_mixer_device.controls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">controls()</span></code></a> for an example of reading from a bitmask.</p>
  541. </dd></dl>
  542. <dl class="py method">
  543. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.get">
  544. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">control</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.get" title="Link to this definition">¶</a></dt>
  545. <dd><p>Returns the volume of a given mixer control. The returned volume is a 2-tuple
  546. <code class="docutils literal notranslate"><span class="pre">(left_volume,right_volume)</span></code>. Volumes are specified as numbers from 0
  547. (silent) to 100 (full volume). If the control is monophonic, a 2-tuple is still
  548. returned, but both volumes are the same.</p>
  549. <p>Raises <a class="reference internal" href="#ossaudiodev.OSSAudioError" title="ossaudiodev.OSSAudioError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSSAudioError</span></code></a> if an invalid control is specified, or
  550. <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if an unsupported control is specified.</p>
  551. </dd></dl>
  552. <dl class="py method">
  553. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.set">
  554. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">set</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">control</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">(left</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right)</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.set" title="Link to this definition">¶</a></dt>
  555. <dd><p>Sets the volume for a given mixer control to <code class="docutils literal notranslate"><span class="pre">(left,right)</span></code>. <code class="docutils literal notranslate"><span class="pre">left</span></code> and
  556. <code class="docutils literal notranslate"><span class="pre">right</span></code> must be ints and between 0 (silent) and 100 (full volume). On
  557. success, the new volume is returned as a 2-tuple. Note that this may not be
  558. exactly the same as the volume specified, because of the limited resolution of
  559. some soundcard’s mixers.</p>
  560. <p>Raises <a class="reference internal" href="#ossaudiodev.OSSAudioError" title="ossaudiodev.OSSAudioError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSSAudioError</span></code></a> if an invalid mixer control was specified, or if the
  561. specified volumes were out-of-range.</p>
  562. </dd></dl>
  563. <dl class="py method">
  564. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.get_recsrc">
  565. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">get_recsrc</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.get_recsrc" title="Link to this definition">¶</a></dt>
  566. <dd><p>This method returns a bitmask indicating which control(s) are currently being
  567. used as a recording source.</p>
  568. </dd></dl>
  569. <dl class="py method">
  570. <dt class="sig sig-object py" id="ossaudiodev.oss_mixer_device.set_recsrc">
  571. <span class="sig-prename descclassname"><span class="pre">oss_mixer_device.</span></span><span class="sig-name descname"><span class="pre">set_recsrc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bitmask</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#ossaudiodev.oss_mixer_device.set_recsrc" title="Link to this definition">¶</a></dt>
  572. <dd><p>Call this function to specify a recording source. Returns a bitmask indicating
  573. the new recording source (or sources) if successful; raises <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> if an
  574. invalid source was specified. To set the current recording source to the
  575. microphone input:</p>
  576. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">mixer</span><span class="o">.</span><span class="n">setrecsrc</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">ossaudiodev</span><span class="o">.</span><span class="n">SOUND_MIXER_MIC</span><span class="p">)</span>
  577. </pre></div>
  578. </div>
  579. </dd></dl>
  580. </section>
  581. </section>
  582. <div class="clearer"></div>
  583. </div>
  584. </div>
  585. </div>
  586. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  587. <div class="sphinxsidebarwrapper">
  588. <div>
  589. <h3><a href="../contents.html">Table of Contents</a></h3>
  590. <ul>
  591. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code> — Access to OSS-compatible audio devices</a><ul>
  592. <li><a class="reference internal" href="#audio-device-objects">Audio Device Objects</a></li>
  593. <li><a class="reference internal" href="#mixer-device-objects">Mixer Device Objects</a></li>
  594. </ul>
  595. </li>
  596. </ul>
  597. </div>
  598. <div>
  599. <h4>Previous topic</h4>
  600. <p class="topless"><a href="optparse.html"
  601. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code> — Parser for command line options</a></p>
  602. </div>
  603. <div>
  604. <h4>Next topic</h4>
  605. <p class="topless"><a href="pipes.html"
  606. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code> — Interface to shell pipelines</a></p>
  607. </div>
  608. <div role="note" aria-label="source link">
  609. <h3>This Page</h3>
  610. <ul class="this-page-menu">
  611. <li><a href="../bugs.html">Report a Bug</a></li>
  612. <li>
  613. <a href="https://github.com/python/cpython/blob/main/Doc/library/ossaudiodev.rst"
  614. rel="nofollow">Show Source
  615. </a>
  616. </li>
  617. </ul>
  618. </div>
  619. </div>
  620. <div id="sidebarbutton" title="Collapse sidebar">
  621. <span>«</span>
  622. </div>
  623. </div>
  624. <div class="clearer"></div>
  625. </div>
  626. <div class="related" role="navigation" aria-label="related navigation">
  627. <h3>Navigation</h3>
  628. <ul>
  629. <li class="right" style="margin-right: 10px">
  630. <a href="../genindex.html" title="General Index"
  631. >index</a></li>
  632. <li class="right" >
  633. <a href="../py-modindex.html" title="Python Module Index"
  634. >modules</a> |</li>
  635. <li class="right" >
  636. <a href="pipes.html" title="pipes — Interface to shell pipelines"
  637. >next</a> |</li>
  638. <li class="right" >
  639. <a href="optparse.html" title="optparse — Parser for command line options"
  640. >previous</a> |</li>
  641. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  642. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  643. <li class="switchers">
  644. <div class="language_switcher_placeholder"></div>
  645. <div class="version_switcher_placeholder"></div>
  646. </li>
  647. <li>
  648. </li>
  649. <li id="cpython-language-and-version">
  650. <a href="../index.html">3.12.3 Documentation</a> &#187;
  651. </li>
  652. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  653. <li class="nav-item nav-item-2"><a href="superseded.html" >Superseded Modules</a> &#187;</li>
  654. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code> — Access to OSS-compatible audio devices</a></li>
  655. <li class="right">
  656. <div class="inline-search" role="search">
  657. <form class="inline-search" action="../search.html" method="get">
  658. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  659. <input type="submit" value="Go" />
  660. </form>
  661. </div>
  662. |
  663. </li>
  664. <li class="right">
  665. <label class="theme-selector-label">
  666. Theme
  667. <select class="theme-selector" oninput="activateTheme(this.value)">
  668. <option value="auto" selected>Auto</option>
  669. <option value="light">Light</option>
  670. <option value="dark">Dark</option>
  671. </select>
  672. </label> |</li>
  673. </ul>
  674. </div>
  675. <div class="footer">
  676. &copy;
  677. <a href="../copyright.html">
  678. Copyright
  679. </a>
  680. 2001-2024, Python Software Foundation.
  681. <br />
  682. This page is licensed under the Python Software Foundation License Version 2.
  683. <br />
  684. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  685. <br />
  686. See <a href="/license.html">History and License</a> for more information.<br />
  687. <br />
  688. The Python Software Foundation is a non-profit corporation.
  689. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  690. <br />
  691. <br />
  692. Last updated on Apr 09, 2024 (13:47 UTC).
  693. <a href="/bugs.html">Found a bug</a>?
  694. <br />
  695. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  696. </div>
  697. </body>
  698. </html>
上海开阖软件有限公司 沪ICP备12045867号-1