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.

557 lines
38KB

  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="aifc — Read and write AIFF and AIFC files" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/aifc.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/aifc.py This module provides support for reading and writing AIFF and AIFF-C files. AIFF is Audio Interchange File Format, a format for storing digital audio samples in a file. AIF..." />
  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/aifc.py This module provides support for reading and writing AIFF and AIFF-C files. AIFF is Audio Interchange File Format, a format for storing digital audio samples in a file. AIF..." />
  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>aifc — Read and write AIFF and AIFC 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="audioop — Manipulate raw audio data" href="audioop.html" />
  33. <link rel="prev" title="Superseded Modules" href="superseded.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/aifc.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. <h4>Previous topic</h4>
  84. <p class="topless"><a href="superseded.html"
  85. title="previous chapter">Superseded Modules</a></p>
  86. </div>
  87. <div>
  88. <h4>Next topic</h4>
  89. <p class="topless"><a href="audioop.html"
  90. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code> — Manipulate raw audio data</a></p>
  91. </div>
  92. <div role="note" aria-label="source link">
  93. <h3>This Page</h3>
  94. <ul class="this-page-menu">
  95. <li><a href="../bugs.html">Report a Bug</a></li>
  96. <li>
  97. <a href="https://github.com/python/cpython/blob/main/Doc/library/aifc.rst"
  98. rel="nofollow">Show Source
  99. </a>
  100. </li>
  101. </ul>
  102. </div>
  103. </nav>
  104. </div>
  105. </div>
  106. <div class="related" role="navigation" aria-label="related navigation">
  107. <h3>Navigation</h3>
  108. <ul>
  109. <li class="right" style="margin-right: 10px">
  110. <a href="../genindex.html" title="General Index"
  111. accesskey="I">index</a></li>
  112. <li class="right" >
  113. <a href="../py-modindex.html" title="Python Module Index"
  114. >modules</a> |</li>
  115. <li class="right" >
  116. <a href="audioop.html" title="audioop — Manipulate raw audio data"
  117. accesskey="N">next</a> |</li>
  118. <li class="right" >
  119. <a href="superseded.html" title="Superseded Modules"
  120. accesskey="P">previous</a> |</li>
  121. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  122. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  123. <li class="switchers">
  124. <div class="language_switcher_placeholder"></div>
  125. <div class="version_switcher_placeholder"></div>
  126. </li>
  127. <li>
  128. </li>
  129. <li id="cpython-language-and-version">
  130. <a href="../index.html">3.12.3 Documentation</a> &#187;
  131. </li>
  132. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  133. <li class="nav-item nav-item-2"><a href="superseded.html" accesskey="U">Superseded Modules</a> &#187;</li>
  134. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code> — Read and write AIFF and AIFC files</a></li>
  135. <li class="right">
  136. <div class="inline-search" role="search">
  137. <form class="inline-search" action="../search.html" method="get">
  138. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  139. <input type="submit" value="Go" />
  140. </form>
  141. </div>
  142. |
  143. </li>
  144. <li class="right">
  145. <label class="theme-selector-label">
  146. Theme
  147. <select class="theme-selector" oninput="activateTheme(this.value)">
  148. <option value="auto" selected>Auto</option>
  149. <option value="light">Light</option>
  150. <option value="dark">Dark</option>
  151. </select>
  152. </label> |</li>
  153. </ul>
  154. </div>
  155. <div class="document">
  156. <div class="documentwrapper">
  157. <div class="bodywrapper">
  158. <div class="body" role="main">
  159. <section id="module-aifc">
  160. <span id="aifc-read-and-write-aiff-and-aifc-files"></span><h1><a class="reference internal" href="#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> — Read and write AIFF and AIFC files<a class="headerlink" href="#module-aifc" title="Link to this heading">¶</a></h1>
  161. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/aifc.py">Lib/aifc.py</a></p>
  162. <div class="deprecated-removed" id="index-0">
  163. <p><span class="versionmodified">Deprecated since version 3.11, will be removed in version 3.13: </span>The <a class="reference internal" href="#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> module is deprecated
  164. (see <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/#aifc"><strong>PEP 594</strong></a> for details).</p>
  165. </div>
  166. <hr class="docutils" />
  167. <p>This module provides support for reading and writing AIFF and AIFF-C files.
  168. AIFF is Audio Interchange File Format, a format for storing digital audio
  169. samples in a file. AIFF-C is a newer version of the format that includes the
  170. ability to compress the audio data.</p>
  171. <p>Audio files have a number of parameters that describe the audio data. The
  172. sampling rate or frame rate is the number of times per second the sound is
  173. sampled. The number of channels indicate if the audio is mono, stereo, or
  174. quadro. Each frame consists of one sample per channel. The sample size is the
  175. size in bytes of each sample. Thus a frame consists of
  176. <code class="docutils literal notranslate"><span class="pre">nchannels</span> <span class="pre">*</span> <span class="pre">samplesize</span></code> bytes, and a second’s worth of audio consists of
  177. <code class="docutils literal notranslate"><span class="pre">nchannels</span> <span class="pre">*</span> <span class="pre">samplesize</span> <span class="pre">*</span> <span class="pre">framerate</span></code> bytes.</p>
  178. <p>For example, CD quality audio has a sample size of two bytes (16 bits), uses two
  179. channels (stereo) and has a frame rate of 44,100 frames/second. This gives a
  180. frame size of 4 bytes (2*2), and a second’s worth occupies 2*2*44100 bytes
  181. (176,400 bytes).</p>
  182. <p>Module <a class="reference internal" href="#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> defines the following function:</p>
  183. <dl class="py function">
  184. <dt class="sig sig-object py" id="aifc.open">
  185. <span class="sig-prename descclassname"><span class="pre">aifc.</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><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.open" title="Link to this definition">¶</a></dt>
  186. <dd><p>Open an AIFF or AIFF-C file and return an object instance with methods that are
  187. described below. The argument <em>file</em> is either a string naming a file or a
  188. <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file object</span></a>. <em>mode</em> must be <code class="docutils literal notranslate"><span class="pre">'r'</span></code> or <code class="docutils literal notranslate"><span class="pre">'rb'</span></code> when the file must be
  189. opened for reading, or <code class="docutils literal notranslate"><span class="pre">'w'</span></code> or <code class="docutils literal notranslate"><span class="pre">'wb'</span></code> when the file must be opened for writing.
  190. If omitted, <code class="docutils literal notranslate"><span class="pre">file.mode</span></code> is used if it exists, otherwise <code class="docutils literal notranslate"><span class="pre">'rb'</span></code> is used. When
  191. used for writing, the file object should be seekable, unless you know ahead of
  192. time how many samples you are going to write in total and use
  193. <code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">setnframes()</span></code>.
  194. The <a class="reference internal" href="#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function may 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. When
  195. the <code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code> block completes, the <a class="reference internal" href="#aifc.aifc.close" title="aifc.aifc.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method is called.</p>
  196. <div class="versionchanged">
  197. <p><span class="versionmodified changed">Changed in version 3.4: </span>Support for the <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 was added.</p>
  198. </div>
  199. </dd></dl>
  200. <p>Objects returned by <a class="reference internal" href="#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> when a file is opened for reading have the
  201. following methods:</p>
  202. <dl class="py method">
  203. <dt class="sig sig-object py" id="aifc.aifc.getnchannels">
  204. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getnchannels" title="Link to this definition">¶</a></dt>
  205. <dd><p>Return the number of audio channels (1 for mono, 2 for stereo).</p>
  206. </dd></dl>
  207. <dl class="py method">
  208. <dt class="sig sig-object py" id="aifc.aifc.getsampwidth">
  209. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getsampwidth" title="Link to this definition">¶</a></dt>
  210. <dd><p>Return the size in bytes of individual samples.</p>
  211. </dd></dl>
  212. <dl class="py method">
  213. <dt class="sig sig-object py" id="aifc.aifc.getframerate">
  214. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getframerate" title="Link to this definition">¶</a></dt>
  215. <dd><p>Return the sampling rate (number of audio frames per second).</p>
  216. </dd></dl>
  217. <dl class="py method">
  218. <dt class="sig sig-object py" id="aifc.aifc.getnframes">
  219. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getnframes" title="Link to this definition">¶</a></dt>
  220. <dd><p>Return the number of audio frames in the file.</p>
  221. </dd></dl>
  222. <dl class="py method">
  223. <dt class="sig sig-object py" id="aifc.aifc.getcomptype">
  224. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getcomptype" title="Link to this definition">¶</a></dt>
  225. <dd><p>Return a bytes array of length 4 describing the type of compression
  226. used in the audio file. For AIFF files, the returned value is
  227. <code class="docutils literal notranslate"><span class="pre">b'NONE'</span></code>.</p>
  228. </dd></dl>
  229. <dl class="py method">
  230. <dt class="sig sig-object py" id="aifc.aifc.getcompname">
  231. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getcompname" title="Link to this definition">¶</a></dt>
  232. <dd><p>Return a bytes array convertible to a human-readable description
  233. of the type of compression used in the audio file. For AIFF files,
  234. the returned value is <code class="docutils literal notranslate"><span class="pre">b'not</span> <span class="pre">compressed'</span></code>.</p>
  235. </dd></dl>
  236. <dl class="py method">
  237. <dt class="sig sig-object py" id="aifc.aifc.getparams">
  238. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getparams" title="Link to this definition">¶</a></dt>
  239. <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>
  240. <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
  241. <code class="xref py py-meth docutils literal notranslate"><span class="pre">get*()</span></code> methods.</p>
  242. </dd></dl>
  243. <dl class="py method">
  244. <dt class="sig sig-object py" id="aifc.aifc.getmarkers">
  245. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getmarkers" title="Link to this definition">¶</a></dt>
  246. <dd><p>Return a list of markers in the audio file. A marker consists of a tuple of
  247. three elements. The first is the mark ID (an integer), the second is the mark
  248. position in frames from the beginning of the data (an integer), the third is the
  249. name of the mark (a string).</p>
  250. </dd></dl>
  251. <dl class="py method">
  252. <dt class="sig sig-object py" id="aifc.aifc.getmark">
  253. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.getmark" title="Link to this definition">¶</a></dt>
  254. <dd><p>Return the tuple as described in <a class="reference internal" href="#aifc.aifc.getmarkers" title="aifc.aifc.getmarkers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getmarkers()</span></code></a> for the mark with the given
  255. <em>id</em>.</p>
  256. </dd></dl>
  257. <dl class="py method">
  258. <dt class="sig sig-object py" id="aifc.aifc.readframes">
  259. <span class="sig-prename descclassname"><span class="pre">aifc.</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">nframes</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.readframes" title="Link to this definition">¶</a></dt>
  260. <dd><p>Read and return the next <em>nframes</em> frames from the audio file. The returned
  261. data is a string containing for each frame the uncompressed samples of all
  262. channels.</p>
  263. </dd></dl>
  264. <dl class="py method">
  265. <dt class="sig sig-object py" id="aifc.aifc.rewind">
  266. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.rewind" title="Link to this definition">¶</a></dt>
  267. <dd><p>Rewind the read pointer. The next <a class="reference internal" href="#aifc.aifc.readframes" title="aifc.aifc.readframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readframes()</span></code></a> will start from the
  268. beginning.</p>
  269. </dd></dl>
  270. <dl class="py method">
  271. <dt class="sig sig-object py" id="aifc.aifc.setpos">
  272. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.setpos" title="Link to this definition">¶</a></dt>
  273. <dd><p>Seek to the specified frame number.</p>
  274. </dd></dl>
  275. <dl class="py method">
  276. <dt class="sig sig-object py" id="aifc.aifc.tell">
  277. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.tell" title="Link to this definition">¶</a></dt>
  278. <dd><p>Return the current frame number.</p>
  279. </dd></dl>
  280. <dl class="py method">
  281. <dt class="sig sig-object py" id="aifc.aifc.close">
  282. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.close" title="Link to this definition">¶</a></dt>
  283. <dd><p>Close the AIFF file. After calling this method, the object can no longer be
  284. used.</p>
  285. </dd></dl>
  286. <p>Objects returned by <a class="reference internal" href="#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> when a file is opened for writing have all the
  287. above methods, except for <code class="xref py py-meth docutils literal notranslate"><span class="pre">readframes()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">setpos()</span></code>. In addition
  288. the following methods exist. The <code class="xref py py-meth docutils literal notranslate"><span class="pre">get*()</span></code> methods can only be called after
  289. the corresponding <code class="xref py py-meth docutils literal notranslate"><span class="pre">set*()</span></code> methods have been called. Before the first
  290. <code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code>, all parameters except for the
  291. number of frames must be filled in.</p>
  292. <dl class="py method">
  293. <dt class="sig sig-object py" id="aifc.aifc.aiff">
  294. <span class="sig-prename descclassname"><span class="pre">aifc.</span></span><span class="sig-name descname"><span class="pre">aiff</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.aiff" title="Link to this definition">¶</a></dt>
  295. <dd><p>Create an AIFF file. The default is that an AIFF-C file is created, unless the
  296. name of the file ends in <code class="docutils literal notranslate"><span class="pre">'.aiff'</span></code> in which case the default is an AIFF file.</p>
  297. </dd></dl>
  298. <dl class="py method">
  299. <dt class="sig sig-object py" id="aifc.aifc.aifc">
  300. <span class="sig-prename descclassname"><span class="pre">aifc.</span></span><span class="sig-name descname"><span class="pre">aifc</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.aifc" title="Link to this definition">¶</a></dt>
  301. <dd><p>Create an AIFF-C file. The default is that an AIFF-C file is created, unless
  302. the name of the file ends in <code class="docutils literal notranslate"><span class="pre">'.aiff'</span></code> in which case the default is an AIFF
  303. file.</p>
  304. </dd></dl>
  305. <dl class="py method">
  306. <dt class="sig sig-object py" id="aifc.aifc.setnchannels">
  307. <span class="sig-prename descclassname"><span class="pre">aifc.</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">nchannels</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.setnchannels" title="Link to this definition">¶</a></dt>
  308. <dd><p>Specify the number of channels in the audio file.</p>
  309. </dd></dl>
  310. <dl class="py method">
  311. <dt class="sig sig-object py" id="aifc.aifc.setsampwidth">
  312. <span class="sig-prename descclassname"><span class="pre">aifc.</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">width</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.setsampwidth" title="Link to this definition">¶</a></dt>
  313. <dd><p>Specify the size in bytes of audio samples.</p>
  314. </dd></dl>
  315. <dl class="py method">
  316. <dt class="sig sig-object py" id="aifc.aifc.setframerate">
  317. <span class="sig-prename descclassname"><span class="pre">aifc.</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">rate</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.setframerate" title="Link to this definition">¶</a></dt>
  318. <dd><p>Specify the sampling frequency in frames per second.</p>
  319. </dd></dl>
  320. <dl class="py method">
  321. <dt class="sig sig-object py" id="aifc.aifc.setnframes">
  322. <span class="sig-prename descclassname"><span class="pre">aifc.</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">nframes</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.setnframes" title="Link to this definition">¶</a></dt>
  323. <dd><p>Specify the number of frames that are to be written to the audio file. If this
  324. parameter is not set, or not set correctly, the file needs to support seeking.</p>
  325. </dd></dl>
  326. <dl class="py method">
  327. <dt class="sig sig-object py" id="aifc.aifc.setcomptype">
  328. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.setcomptype" title="Link to this definition">¶</a></dt>
  329. <dd><p id="index-2">Specify the compression type. If not specified, the audio data will
  330. not be compressed. In AIFF files, compression is not possible.
  331. The name parameter should be a human-readable description of the
  332. compression type as a bytes array, the type parameter should be a
  333. bytes array of length 4. Currently the following compression types
  334. are supported: <code class="docutils literal notranslate"><span class="pre">b'NONE'</span></code>, <code class="docutils literal notranslate"><span class="pre">b'ULAW'</span></code>, <code class="docutils literal notranslate"><span class="pre">b'ALAW'</span></code>, <code class="docutils literal notranslate"><span class="pre">b'G722'</span></code>.</p>
  335. </dd></dl>
  336. <dl class="py method">
  337. <dt class="sig sig-object py" id="aifc.aifc.setparams">
  338. <span class="sig-prename descclassname"><span class="pre">aifc.</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">nchannels</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sampwidth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">framerate</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">comptype</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">compname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#aifc.aifc.setparams" title="Link to this definition">¶</a></dt>
  339. <dd><p>Set all the above parameters at once. The argument is a tuple consisting of the
  340. various parameters. This means that it is possible to use the result of a
  341. <a class="reference internal" href="#aifc.aifc.getparams" title="aifc.aifc.getparams"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code></a> call as argument to <a class="reference internal" href="#aifc.aifc.setparams" title="aifc.aifc.setparams"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setparams()</span></code></a>.</p>
  342. </dd></dl>
  343. <dl class="py method">
  344. <dt class="sig sig-object py" id="aifc.aifc.setmark">
  345. <span class="sig-prename descclassname"><span class="pre">aifc.</span></span><span class="sig-name descname"><span class="pre">setmark</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">id</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pos</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="#aifc.aifc.setmark" title="Link to this definition">¶</a></dt>
  346. <dd><p>Add a mark with the given id (larger than 0), and the given name at the given
  347. position. This method can be called at any time before <a class="reference internal" href="#aifc.aifc.close" title="aifc.aifc.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a>.</p>
  348. </dd></dl>
  349. <dl class="py method">
  350. <dt class="sig sig-object py">
  351. <span class="sig-prename descclassname"><span class="pre">aifc.</span></span><span class="sig-name descname"><span class="pre">tell</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
  352. <dd><p>Return the current write position in the output file. Useful in combination
  353. with <a class="reference internal" href="#aifc.aifc.setmark" title="aifc.aifc.setmark"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setmark()</span></code></a>.</p>
  354. </dd></dl>
  355. <dl class="py method">
  356. <dt class="sig sig-object py" id="aifc.aifc.writeframes">
  357. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.writeframes" title="Link to this definition">¶</a></dt>
  358. <dd><p>Write data to the output file. This method can only be called after the audio
  359. file parameters have been set.</p>
  360. <div class="versionchanged">
  361. <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>
  362. </div>
  363. </dd></dl>
  364. <dl class="py method">
  365. <dt class="sig sig-object py" id="aifc.aifc.writeframesraw">
  366. <span class="sig-prename descclassname"><span class="pre">aifc.</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="#aifc.aifc.writeframesraw" title="Link to this definition">¶</a></dt>
  367. <dd><p>Like <a class="reference internal" href="#aifc.aifc.writeframes" title="aifc.aifc.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a>, except that the header of the audio file is not
  368. updated.</p>
  369. <div class="versionchanged">
  370. <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>
  371. </div>
  372. </dd></dl>
  373. <dl class="py method">
  374. <dt class="sig sig-object py">
  375. <span class="sig-prename descclassname"><span class="pre">aifc.</span></span><span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
  376. <dd><p>Close the AIFF file. The header of the file is updated to reflect the actual
  377. size of the audio data. After calling this method, the object can no longer be
  378. used.</p>
  379. </dd></dl>
  380. </section>
  381. <div class="clearer"></div>
  382. </div>
  383. </div>
  384. </div>
  385. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  386. <div class="sphinxsidebarwrapper">
  387. <div>
  388. <h4>Previous topic</h4>
  389. <p class="topless"><a href="superseded.html"
  390. title="previous chapter">Superseded Modules</a></p>
  391. </div>
  392. <div>
  393. <h4>Next topic</h4>
  394. <p class="topless"><a href="audioop.html"
  395. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code> — Manipulate raw audio data</a></p>
  396. </div>
  397. <div role="note" aria-label="source link">
  398. <h3>This Page</h3>
  399. <ul class="this-page-menu">
  400. <li><a href="../bugs.html">Report a Bug</a></li>
  401. <li>
  402. <a href="https://github.com/python/cpython/blob/main/Doc/library/aifc.rst"
  403. rel="nofollow">Show Source
  404. </a>
  405. </li>
  406. </ul>
  407. </div>
  408. </div>
  409. <div id="sidebarbutton" title="Collapse sidebar">
  410. <span>«</span>
  411. </div>
  412. </div>
  413. <div class="clearer"></div>
  414. </div>
  415. <div class="related" role="navigation" aria-label="related navigation">
  416. <h3>Navigation</h3>
  417. <ul>
  418. <li class="right" style="margin-right: 10px">
  419. <a href="../genindex.html" title="General Index"
  420. >index</a></li>
  421. <li class="right" >
  422. <a href="../py-modindex.html" title="Python Module Index"
  423. >modules</a> |</li>
  424. <li class="right" >
  425. <a href="audioop.html" title="audioop — Manipulate raw audio data"
  426. >next</a> |</li>
  427. <li class="right" >
  428. <a href="superseded.html" title="Superseded Modules"
  429. >previous</a> |</li>
  430. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  431. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  432. <li class="switchers">
  433. <div class="language_switcher_placeholder"></div>
  434. <div class="version_switcher_placeholder"></div>
  435. </li>
  436. <li>
  437. </li>
  438. <li id="cpython-language-and-version">
  439. <a href="../index.html">3.12.3 Documentation</a> &#187;
  440. </li>
  441. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  442. <li class="nav-item nav-item-2"><a href="superseded.html" >Superseded Modules</a> &#187;</li>
  443. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code> — Read and write AIFF and AIFC files</a></li>
  444. <li class="right">
  445. <div class="inline-search" role="search">
  446. <form class="inline-search" action="../search.html" method="get">
  447. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  448. <input type="submit" value="Go" />
  449. </form>
  450. </div>
  451. |
  452. </li>
  453. <li class="right">
  454. <label class="theme-selector-label">
  455. Theme
  456. <select class="theme-selector" oninput="activateTheme(this.value)">
  457. <option value="auto" selected>Auto</option>
  458. <option value="light">Light</option>
  459. <option value="dark">Dark</option>
  460. </select>
  461. </label> |</li>
  462. </ul>
  463. </div>
  464. <div class="footer">
  465. &copy;
  466. <a href="../copyright.html">
  467. Copyright
  468. </a>
  469. 2001-2024, Python Software Foundation.
  470. <br />
  471. This page is licensed under the Python Software Foundation License Version 2.
  472. <br />
  473. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  474. <br />
  475. See <a href="/license.html">History and License</a> for more information.<br />
  476. <br />
  477. The Python Software Foundation is a non-profit corporation.
  478. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  479. <br />
  480. <br />
  481. Last updated on Apr 09, 2024 (13:47 UTC).
  482. <a href="/bugs.html">Found a bug</a>?
  483. <br />
  484. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  485. </div>
  486. </body>
  487. </html>
上海开阖软件有限公司 沪ICP备12045867号-1