gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

626 lines
42KB

  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="sunau — Read and write Sun AU files" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/sunau.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/sunau.py The sunau module provides a convenient interface to the Sun AU sound format. Note that this module is interface-compatible with the modules aifc and wave. An audio file co..." />
  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="Source code: Lib/sunau.py The sunau module provides a convenient interface to the Sun AU sound format. Note that this module is interface-compatible with the modules aifc and wave. An audio file co..." />
  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>sunau — Read and write Sun AU files &#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="telnetlib — Telnet client" href="telnetlib.html" />
  33. <link rel="prev" title="spwd — The shadow password database" href="spwd.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/sunau.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">sunau</span></code> — Read and write Sun AU files</a><ul>
  86. <li><a class="reference internal" href="#au-read-objects">AU_read Objects</a></li>
  87. <li><a class="reference internal" href="#au-write-objects">AU_write Objects</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div>
  92. <div>
  93. <h4>Previous topic</h4>
  94. <p class="topless"><a href="spwd.html"
  95. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code> — The shadow password database</a></p>
  96. </div>
  97. <div>
  98. <h4>Next topic</h4>
  99. <p class="topless"><a href="telnetlib.html"
  100. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code> — Telnet client</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/sunau.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="telnetlib.html" title="telnetlib — Telnet client"
  127. accesskey="N">next</a> |</li>
  128. <li class="right" >
  129. <a href="spwd.html" title="spwd — The shadow password database"
  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">sunau</span></code> — Read and write Sun AU files</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-sunau">
  170. <span id="sunau-read-and-write-sun-au-files"></span><h1><a class="reference internal" href="#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a> — Read and write Sun AU files<a class="headerlink" href="#module-sunau" title="Link to this heading">¶</a></h1>
  171. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/sunau.py">Lib/sunau.py</a></p>
  172. <div class="deprecated-removed">
  173. <p><span class="versionmodified">Deprecated since version 3.11, will be removed in version 3.13: </span>The <a class="reference internal" href="#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a> module is deprecated
  174. (see <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/#sunau"><strong>PEP 594</strong></a> for details).</p>
  175. </div>
  176. <hr class="docutils" />
  177. <p>The <a class="reference internal" href="#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a> module provides a convenient interface to the Sun AU sound
  178. format. Note that this module is interface-compatible with the modules
  179. <a class="reference internal" href="aifc.html#module-aifc" title="aifc: Read and write audio files in AIFF or AIFC format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code></a> and <a class="reference internal" href="wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a>.</p>
  180. <p>An audio file consists of a header followed by the data. The fields of the
  181. header are:</p>
  182. <table class="docutils align-default">
  183. <thead>
  184. <tr class="row-odd"><th class="head"><p>Field</p></th>
  185. <th class="head"><p>Contents</p></th>
  186. </tr>
  187. </thead>
  188. <tbody>
  189. <tr class="row-even"><td><p>magic word</p></td>
  190. <td><p>The four bytes <code class="docutils literal notranslate"><span class="pre">.snd</span></code>.</p></td>
  191. </tr>
  192. <tr class="row-odd"><td><p>header size</p></td>
  193. <td><p>Size of the header, including info, in bytes.</p></td>
  194. </tr>
  195. <tr class="row-even"><td><p>data size</p></td>
  196. <td><p>Physical size of the data, in bytes.</p></td>
  197. </tr>
  198. <tr class="row-odd"><td><p>encoding</p></td>
  199. <td><p>Indicates how the audio samples are encoded.</p></td>
  200. </tr>
  201. <tr class="row-even"><td><p>sample rate</p></td>
  202. <td><p>The sampling rate.</p></td>
  203. </tr>
  204. <tr class="row-odd"><td><p># of channels</p></td>
  205. <td><p>The number of channels in the samples.</p></td>
  206. </tr>
  207. <tr class="row-even"><td><p>info</p></td>
  208. <td><p>ASCII string giving a description of the
  209. audio file (padded with null bytes).</p></td>
  210. </tr>
  211. </tbody>
  212. </table>
  213. <p>Apart from the info field, all header fields are 4 bytes in size. They are all
  214. 32-bit unsigned integers encoded in big-endian byte order.</p>
  215. <p>The <a class="reference internal" href="#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a> module defines the following functions:</p>
  216. <dl class="py function">
  217. <dt class="sig sig-object py" id="sunau.open">
  218. <span class="sig-prename descclassname"><span class="pre">sunau.</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">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.open" title="Link to this definition">¶</a></dt>
  219. <dd><p>If <em>file</em> is a string, open the file by that name, otherwise treat it as a
  220. seekable file-like object. <em>mode</em> can be any of</p>
  221. <dl class="simple">
  222. <dt><code class="docutils literal notranslate"><span class="pre">'r'</span></code></dt><dd><p>Read only mode.</p>
  223. </dd>
  224. <dt><code class="docutils literal notranslate"><span class="pre">'w'</span></code></dt><dd><p>Write only mode.</p>
  225. </dd>
  226. </dl>
  227. <p>Note that it does not allow read/write files.</p>
  228. <p>A <em>mode</em> of <code class="docutils literal notranslate"><span class="pre">'r'</span></code> returns an <code class="xref py py-class docutils literal notranslate"><span class="pre">AU_read</span></code> object, while a <em>mode</em> of <code class="docutils literal notranslate"><span class="pre">'w'</span></code>
  229. or <code class="docutils literal notranslate"><span class="pre">'wb'</span></code> returns an <code class="xref py py-class docutils literal notranslate"><span class="pre">AU_write</span></code> object.</p>
  230. </dd></dl>
  231. <p>The <a class="reference internal" href="#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a> module defines the following exception:</p>
  232. <dl class="py exception">
  233. <dt class="sig sig-object py" id="sunau.Error">
  234. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">Error</span></span><a class="headerlink" href="#sunau.Error" title="Link to this definition">¶</a></dt>
  235. <dd><p>An error raised when something is impossible because of Sun AU specs or
  236. implementation deficiency.</p>
  237. </dd></dl>
  238. <p>The <a class="reference internal" href="#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a> module defines the following data items:</p>
  239. <dl class="py data">
  240. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_MAGIC">
  241. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_MAGIC</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_MAGIC" title="Link to this definition">¶</a></dt>
  242. <dd><p>An integer every valid Sun AU file begins with, stored in big-endian form. This
  243. is the string <code class="docutils literal notranslate"><span class="pre">.snd</span></code> interpreted as an integer.</p>
  244. </dd></dl>
  245. <dl class="py data">
  246. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_MULAW_8">
  247. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_MULAW_8</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_MULAW_8" title="Link to this definition">¶</a></dt>
  248. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_LINEAR_8">
  249. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_LINEAR_8</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_LINEAR_8" title="Link to this definition">¶</a></dt>
  250. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_LINEAR_16">
  251. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_LINEAR_16</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_LINEAR_16" title="Link to this definition">¶</a></dt>
  252. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_LINEAR_24">
  253. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_LINEAR_24</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_LINEAR_24" title="Link to this definition">¶</a></dt>
  254. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_LINEAR_32">
  255. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_LINEAR_32</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_LINEAR_32" title="Link to this definition">¶</a></dt>
  256. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_ALAW_8">
  257. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_ALAW_8</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_ALAW_8" title="Link to this definition">¶</a></dt>
  258. <dd><p>Values of the encoding field from the AU header which are supported by this
  259. module.</p>
  260. </dd></dl>
  261. <dl class="py data">
  262. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_FLOAT">
  263. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_FLOAT</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_FLOAT" title="Link to this definition">¶</a></dt>
  264. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_DOUBLE">
  265. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_DOUBLE</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_DOUBLE" title="Link to this definition">¶</a></dt>
  266. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_ADPCM_G721">
  267. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_ADPCM_G721</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_ADPCM_G721" title="Link to this definition">¶</a></dt>
  268. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_ADPCM_G722">
  269. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_ADPCM_G722</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_ADPCM_G722" title="Link to this definition">¶</a></dt>
  270. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_ADPCM_G723_3">
  271. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_ADPCM_G723_3</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_ADPCM_G723_3" title="Link to this definition">¶</a></dt>
  272. <dt class="sig sig-object py" id="sunau.AUDIO_FILE_ENCODING_ADPCM_G723_5">
  273. <span class="sig-prename descclassname"><span class="pre">sunau.</span></span><span class="sig-name descname"><span class="pre">AUDIO_FILE_ENCODING_ADPCM_G723_5</span></span><a class="headerlink" href="#sunau.AUDIO_FILE_ENCODING_ADPCM_G723_5" title="Link to this definition">¶</a></dt>
  274. <dd><p>Additional known values of the encoding field from the AU header, but which are
  275. not supported by this module.</p>
  276. </dd></dl>
  277. <section id="au-read-objects">
  278. <span id="id1"></span><h2>AU_read Objects<a class="headerlink" href="#au-read-objects" title="Link to this heading">¶</a></h2>
  279. <p>AU_read objects, as returned by <a class="reference internal" href="#sunau.open" title="sunau.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> above, have the following methods:</p>
  280. <dl class="py method">
  281. <dt class="sig sig-object py" id="sunau.AU_read.close">
  282. <span class="sig-prename descclassname"><span class="pre">AU_read.</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="#sunau.AU_read.close" title="Link to this definition">¶</a></dt>
  283. <dd><p>Close the stream, and make the instance unusable. (This is called automatically
  284. on deletion.)</p>
  285. </dd></dl>
  286. <dl class="py method">
  287. <dt class="sig sig-object py" id="sunau.AU_read.getnchannels">
  288. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getnchannels</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getnchannels" title="Link to this definition">¶</a></dt>
  289. <dd><p>Returns number of audio channels (1 for mono, 2 for stereo).</p>
  290. </dd></dl>
  291. <dl class="py method">
  292. <dt class="sig sig-object py" id="sunau.AU_read.getsampwidth">
  293. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getsampwidth</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getsampwidth" title="Link to this definition">¶</a></dt>
  294. <dd><p>Returns sample width in bytes.</p>
  295. </dd></dl>
  296. <dl class="py method">
  297. <dt class="sig sig-object py" id="sunau.AU_read.getframerate">
  298. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getframerate</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getframerate" title="Link to this definition">¶</a></dt>
  299. <dd><p>Returns sampling frequency.</p>
  300. </dd></dl>
  301. <dl class="py method">
  302. <dt class="sig sig-object py" id="sunau.AU_read.getnframes">
  303. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getnframes</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getnframes" title="Link to this definition">¶</a></dt>
  304. <dd><p>Returns number of audio frames.</p>
  305. </dd></dl>
  306. <dl class="py method">
  307. <dt class="sig sig-object py" id="sunau.AU_read.getcomptype">
  308. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getcomptype</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getcomptype" title="Link to this definition">¶</a></dt>
  309. <dd><p>Returns compression type. Supported compression types are <code class="docutils literal notranslate"><span class="pre">'ULAW'</span></code>, <code class="docutils literal notranslate"><span class="pre">'ALAW'</span></code>
  310. and <code class="docutils literal notranslate"><span class="pre">'NONE'</span></code>.</p>
  311. </dd></dl>
  312. <dl class="py method">
  313. <dt class="sig sig-object py" id="sunau.AU_read.getcompname">
  314. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getcompname</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getcompname" title="Link to this definition">¶</a></dt>
  315. <dd><p>Human-readable version of <a class="reference internal" href="#sunau.AU_read.getcomptype" title="sunau.AU_read.getcomptype"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getcomptype()</span></code></a>. The supported types have the
  316. respective names <code class="docutils literal notranslate"><span class="pre">'CCITT</span> <span class="pre">G.711</span> <span class="pre">u-law'</span></code>, <code class="docutils literal notranslate"><span class="pre">'CCITT</span> <span class="pre">G.711</span> <span class="pre">A-law'</span></code> and <code class="docutils literal notranslate"><span class="pre">'not</span>
  317. <span class="pre">compressed'</span></code>.</p>
  318. </dd></dl>
  319. <dl class="py method">
  320. <dt class="sig sig-object py" id="sunau.AU_read.getparams">
  321. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getparams</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getparams" title="Link to this definition">¶</a></dt>
  322. <dd><p>Returns a <a class="reference internal" href="collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> <code class="docutils literal notranslate"><span class="pre">(nchannels,</span> <span class="pre">sampwidth,</span>
  323. <span class="pre">framerate,</span> <span class="pre">nframes,</span> <span class="pre">comptype,</span> <span class="pre">compname)</span></code>, equivalent to output of the
  324. <code class="xref py py-meth docutils literal notranslate"><span class="pre">get*()</span></code> methods.</p>
  325. </dd></dl>
  326. <dl class="py method">
  327. <dt class="sig sig-object py" id="sunau.AU_read.readframes">
  328. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">readframes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.readframes" title="Link to this definition">¶</a></dt>
  329. <dd><p>Reads and returns at most <em>n</em> frames of audio, as a <a class="reference internal" href="stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> object. The data
  330. will be returned in linear format. If the original data is in u-LAW format, it
  331. will be converted.</p>
  332. </dd></dl>
  333. <dl class="py method">
  334. <dt class="sig sig-object py" id="sunau.AU_read.rewind">
  335. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">rewind</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.rewind" title="Link to this definition">¶</a></dt>
  336. <dd><p>Rewind the file pointer to the beginning of the audio stream.</p>
  337. </dd></dl>
  338. <p>The following two methods define a term “position” which is compatible between
  339. them, and is otherwise implementation dependent.</p>
  340. <dl class="py method">
  341. <dt class="sig sig-object py" id="sunau.AU_read.setpos">
  342. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">setpos</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pos</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.setpos" title="Link to this definition">¶</a></dt>
  343. <dd><p>Set the file pointer to the specified position. Only values returned from
  344. <a class="reference internal" href="#sunau.AU_read.tell" title="sunau.AU_read.tell"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tell()</span></code></a> should be used for <em>pos</em>.</p>
  345. </dd></dl>
  346. <dl class="py method">
  347. <dt class="sig sig-object py" id="sunau.AU_read.tell">
  348. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">tell</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.tell" title="Link to this definition">¶</a></dt>
  349. <dd><p>Return current file pointer position. Note that the returned value has nothing
  350. to do with the actual position in the file.</p>
  351. </dd></dl>
  352. <p>The following two functions are defined for compatibility with the <a class="reference internal" href="aifc.html#module-aifc" title="aifc: Read and write audio files in AIFF or AIFC format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code></a>,
  353. and don’t do anything interesting.</p>
  354. <dl class="py method">
  355. <dt class="sig sig-object py" id="sunau.AU_read.getmarkers">
  356. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getmarkers</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getmarkers" title="Link to this definition">¶</a></dt>
  357. <dd><p>Returns <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  358. </dd></dl>
  359. <dl class="py method">
  360. <dt class="sig sig-object py" id="sunau.AU_read.getmark">
  361. <span class="sig-prename descclassname"><span class="pre">AU_read.</span></span><span class="sig-name descname"><span class="pre">getmark</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">id</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_read.getmark" title="Link to this definition">¶</a></dt>
  362. <dd><p>Raise an error.</p>
  363. </dd></dl>
  364. </section>
  365. <section id="au-write-objects">
  366. <span id="id2"></span><h2>AU_write Objects<a class="headerlink" href="#au-write-objects" title="Link to this heading">¶</a></h2>
  367. <p>AU_write objects, as returned by <a class="reference internal" href="#sunau.open" title="sunau.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> above, have the following methods:</p>
  368. <dl class="py method">
  369. <dt class="sig sig-object py" id="sunau.AU_write.setnchannels">
  370. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">setnchannels</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.setnchannels" title="Link to this definition">¶</a></dt>
  371. <dd><p>Set the number of channels.</p>
  372. </dd></dl>
  373. <dl class="py method">
  374. <dt class="sig sig-object py" id="sunau.AU_write.setsampwidth">
  375. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">setsampwidth</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.setsampwidth" title="Link to this definition">¶</a></dt>
  376. <dd><p>Set the sample width (in bytes.)</p>
  377. <div class="versionchanged">
  378. <p><span class="versionmodified changed">Changed in version 3.4: </span>Added support for 24-bit samples.</p>
  379. </div>
  380. </dd></dl>
  381. <dl class="py method">
  382. <dt class="sig sig-object py" id="sunau.AU_write.setframerate">
  383. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">setframerate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.setframerate" title="Link to this definition">¶</a></dt>
  384. <dd><p>Set the frame rate.</p>
  385. </dd></dl>
  386. <dl class="py method">
  387. <dt class="sig sig-object py" id="sunau.AU_write.setnframes">
  388. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">setnframes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.setnframes" title="Link to this definition">¶</a></dt>
  389. <dd><p>Set the number of frames. This can be later changed, when and if more frames
  390. are written.</p>
  391. </dd></dl>
  392. <dl class="py method">
  393. <dt class="sig sig-object py" id="sunau.AU_write.setcomptype">
  394. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">setcomptype</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.setcomptype" title="Link to this definition">¶</a></dt>
  395. <dd><p>Set the compression type and description. Only <code class="docutils literal notranslate"><span class="pre">'NONE'</span></code> and <code class="docutils literal notranslate"><span class="pre">'ULAW'</span></code> are
  396. supported on output.</p>
  397. </dd></dl>
  398. <dl class="py method">
  399. <dt class="sig sig-object py" id="sunau.AU_write.setparams">
  400. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">setparams</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tuple</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.setparams" title="Link to this definition">¶</a></dt>
  401. <dd><p>The <em>tuple</em> should be <code class="docutils literal notranslate"><span class="pre">(nchannels,</span> <span class="pre">sampwidth,</span> <span class="pre">framerate,</span> <span class="pre">nframes,</span> <span class="pre">comptype,</span>
  402. <span class="pre">compname)</span></code>, with values valid for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">set*()</span></code> methods. Set all
  403. parameters.</p>
  404. </dd></dl>
  405. <dl class="py method">
  406. <dt class="sig sig-object py" id="sunau.AU_write.tell">
  407. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">tell</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#sunau.AU_write.tell" title="Link to this definition">¶</a></dt>
  408. <dd><p>Return current position in the file, with the same disclaimer for the
  409. <a class="reference internal" href="#sunau.AU_read.tell" title="sunau.AU_read.tell"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AU_read.tell()</span></code></a> and <a class="reference internal" href="#sunau.AU_read.setpos" title="sunau.AU_read.setpos"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AU_read.setpos()</span></code></a> methods.</p>
  410. </dd></dl>
  411. <dl class="py method">
  412. <dt class="sig sig-object py" id="sunau.AU_write.writeframesraw">
  413. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">writeframesraw</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="#sunau.AU_write.writeframesraw" title="Link to this definition">¶</a></dt>
  414. <dd><p>Write audio frames, without correcting <em>nframes</em>.</p>
  415. <div class="versionchanged">
  416. <p><span class="versionmodified changed">Changed in version 3.4: </span>Any <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>
  417. </div>
  418. </dd></dl>
  419. <dl class="py method">
  420. <dt class="sig sig-object py" id="sunau.AU_write.writeframes">
  421. <span class="sig-prename descclassname"><span class="pre">AU_write.</span></span><span class="sig-name descname"><span class="pre">writeframes</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="#sunau.AU_write.writeframes" title="Link to this definition">¶</a></dt>
  422. <dd><p>Write audio frames and make sure <em>nframes</em> is correct.</p>
  423. <div class="versionchanged">
  424. <p><span class="versionmodified changed">Changed in version 3.4: </span>Any <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>
  425. </div>
  426. </dd></dl>
  427. <dl class="py method">
  428. <dt class="sig sig-object py" id="sunau.AU_write.close">
  429. <span class="sig-prename descclassname"><span class="pre">AU_write.</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="#sunau.AU_write.close" title="Link to this definition">¶</a></dt>
  430. <dd><p>Make sure <em>nframes</em> is correct, and close the file.</p>
  431. <p>This method is called upon deletion.</p>
  432. </dd></dl>
  433. <p>Note that it is invalid to set any parameters after calling <code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code>
  434. or <code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code>.</p>
  435. </section>
  436. </section>
  437. <div class="clearer"></div>
  438. </div>
  439. </div>
  440. </div>
  441. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  442. <div class="sphinxsidebarwrapper">
  443. <div>
  444. <h3><a href="../contents.html">Table of Contents</a></h3>
  445. <ul>
  446. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code> — Read and write Sun AU files</a><ul>
  447. <li><a class="reference internal" href="#au-read-objects">AU_read Objects</a></li>
  448. <li><a class="reference internal" href="#au-write-objects">AU_write Objects</a></li>
  449. </ul>
  450. </li>
  451. </ul>
  452. </div>
  453. <div>
  454. <h4>Previous topic</h4>
  455. <p class="topless"><a href="spwd.html"
  456. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code> — The shadow password database</a></p>
  457. </div>
  458. <div>
  459. <h4>Next topic</h4>
  460. <p class="topless"><a href="telnetlib.html"
  461. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code> — Telnet client</a></p>
  462. </div>
  463. <div role="note" aria-label="source link">
  464. <h3>This Page</h3>
  465. <ul class="this-page-menu">
  466. <li><a href="../bugs.html">Report a Bug</a></li>
  467. <li>
  468. <a href="https://github.com/python/cpython/blob/main/Doc/library/sunau.rst"
  469. rel="nofollow">Show Source
  470. </a>
  471. </li>
  472. </ul>
  473. </div>
  474. </div>
  475. <div id="sidebarbutton" title="Collapse sidebar">
  476. <span>«</span>
  477. </div>
  478. </div>
  479. <div class="clearer"></div>
  480. </div>
  481. <div class="related" role="navigation" aria-label="related navigation">
  482. <h3>Navigation</h3>
  483. <ul>
  484. <li class="right" style="margin-right: 10px">
  485. <a href="../genindex.html" title="General Index"
  486. >index</a></li>
  487. <li class="right" >
  488. <a href="../py-modindex.html" title="Python Module Index"
  489. >modules</a> |</li>
  490. <li class="right" >
  491. <a href="telnetlib.html" title="telnetlib — Telnet client"
  492. >next</a> |</li>
  493. <li class="right" >
  494. <a href="spwd.html" title="spwd — The shadow password database"
  495. >previous</a> |</li>
  496. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  497. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  498. <li class="switchers">
  499. <div class="language_switcher_placeholder"></div>
  500. <div class="version_switcher_placeholder"></div>
  501. </li>
  502. <li>
  503. </li>
  504. <li id="cpython-language-and-version">
  505. <a href="../index.html">3.12.3 Documentation</a> &#187;
  506. </li>
  507. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  508. <li class="nav-item nav-item-2"><a href="superseded.html" >Superseded Modules</a> &#187;</li>
  509. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code> — Read and write Sun AU files</a></li>
  510. <li class="right">
  511. <div class="inline-search" role="search">
  512. <form class="inline-search" action="../search.html" method="get">
  513. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  514. <input type="submit" value="Go" />
  515. </form>
  516. </div>
  517. |
  518. </li>
  519. <li class="right">
  520. <label class="theme-selector-label">
  521. Theme
  522. <select class="theme-selector" oninput="activateTheme(this.value)">
  523. <option value="auto" selected>Auto</option>
  524. <option value="light">Light</option>
  525. <option value="dark">Dark</option>
  526. </select>
  527. </label> |</li>
  528. </ul>
  529. </div>
  530. <div class="footer">
  531. &copy;
  532. <a href="../copyright.html">
  533. Copyright
  534. </a>
  535. 2001-2024, Python Software Foundation.
  536. <br />
  537. This page is licensed under the Python Software Foundation License Version 2.
  538. <br />
  539. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  540. <br />
  541. See <a href="/license.html">History and License</a> for more information.<br />
  542. <br />
  543. The Python Software Foundation is a non-profit corporation.
  544. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  545. <br />
  546. <br />
  547. Last updated on Apr 09, 2024 (13:47 UTC).
  548. <a href="/bugs.html">Found a bug</a>?
  549. <br />
  550. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  551. </div>
  552. </body>
  553. </html>
上海开阖软件有限公司 沪ICP备12045867号-1