From 263c3e569ab0979af6daac3a20f3df18cc383347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= <sornjure@gmail.com> Date: Sat, 13 Jan 2024 03:48:53 +0100 Subject: [PATCH] Audio --- README.md | 31 +++++++++++++++---------------- index.html | 29 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 42e81eb..dca1510 100644 --- a/README.md +++ b/README.md @@ -2853,22 +2853,21 @@ import wave ``` ```python -<Wave_read> = wave.open('<path>', 'rb') # Opens the WAV file. -framerate = <Wave_read>.getframerate() # Number of frames per second. -nchannels = <Wave_read>.getnchannels() # Number of samples per frame. -sampwidth = <Wave_read>.getsampwidth() # Sample size in bytes. -nframes = <Wave_read>.getnframes() # Number of frames. -<params> = <Wave_read>.getparams() # Immutable collection of above. -<bytes> = <Wave_read>.readframes(nframes) # Returns next 'nframes' frames. -``` - -```python -<Wave_write> = wave.open('<path>', 'wb') # Truncates existing file. -<Wave_write>.setframerate(<int>) # 44100 for CD, 48000 for video. -<Wave_write>.setnchannels(<int>) # 1 for mono, 2 for stereo. -<Wave_write>.setsampwidth(<int>) # 2 for CD quality sound. -<Wave_write>.setparams(<params>) # Sets all parameters. -<Wave_write>.writeframes(<bytes>) # Appends frames to the file. +<Wave> = wave.open('<path>', 'rb') # Opens the WAV file. +<int> = <Wave>.getframerate() # Returns number of frames per second. +<int> = <Wave>.getnchannels() # Returns number of samples per frame. +<int> = <Wave>.getsampwidth() # Returns number of bytes per sample. +<params> = <Wave>.getparams() # Returns collection of listed params. +<bytes> = <Wave>.readframes(nframes) # Returns next n frames. All if -1. +``` + +```python +<Wave> = wave.open('<path>', 'wb') # Opens WAV file for writing. +<Wave>.setframerate(<int>) # Pass 44100 for CD, 48000 for video. +<Wave>.setnchannels(<int>) # Pass 1 for mono, 2 for stereo. +<Wave>.setsampwidth(<int>) # Pass 1 for 8-bit sound, 2 for CD. +<Wave>.setparams(<params>) # Sets all parameters. +<Wave>.writeframes(<bytes>) # Appends frames to the file. ``` * **Bytes object contains a sequence of frames, each consisting of one or more samples.** * **In a stereo signal, the first sample of a frame belongs to the left channel.** diff --git a/index.html b/index.html index d3cb7f2..cae574f 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@ <body> <header> - <aside>January 11, 2024</aside> + <aside>January 13, 2024</aside> <a href="https://gto76.github.io" rel="author">Jure Šorn</a> </header> @@ -2340,20 +2340,19 @@ imageio.mimsave(<span class="hljs-string">'test.gif'</span>, frames, duration=<s <div><h2 id="audio"><a href="#audio" name="audio">#</a>Audio</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> wave </code></pre></div> -<pre><code class="python language-python hljs"><Wave_read> = wave.open(<span class="hljs-string">'<path>'</span>, <span class="hljs-string">'rb'</span>) <span class="hljs-comment"># Opens the WAV file.</span> -framerate = <Wave_read>.getframerate() <span class="hljs-comment"># Number of frames per second.</span> -nchannels = <Wave_read>.getnchannels() <span class="hljs-comment"># Number of samples per frame.</span> -sampwidth = <Wave_read>.getsampwidth() <span class="hljs-comment"># Sample size in bytes.</span> -nframes = <Wave_read>.getnframes() <span class="hljs-comment"># Number of frames.</span> -<params> = <Wave_read>.getparams() <span class="hljs-comment"># Immutable collection of above.</span> -<bytes> = <Wave_read>.readframes(nframes) <span class="hljs-comment"># Returns next 'nframes' frames.</span> +<pre><code class="python language-python hljs"><Wave> = wave.open(<span class="hljs-string">'<path>'</span>, <span class="hljs-string">'rb'</span>) <span class="hljs-comment"># Opens the WAV file.</span> +<int> = <Wave>.getframerate() <span class="hljs-comment"># Returns number of frames per second.</span> +<int> = <Wave>.getnchannels() <span class="hljs-comment"># Returns number of samples per frame.</span> +<int> = <Wave>.getsampwidth() <span class="hljs-comment"># Returns number of bytes per sample.</span> +<params> = <Wave>.getparams() <span class="hljs-comment"># Returns collection of listed params.</span> +<bytes> = <Wave>.readframes(nframes) <span class="hljs-comment"># Returns next n frames. All if -1.</span> </code></pre> -<pre><code class="python language-python hljs"><Wave_write> = wave.open(<span class="hljs-string">'<path>'</span>, <span class="hljs-string">'wb'</span>) <span class="hljs-comment"># Truncates existing file.</span> -<Wave_write>.setframerate(<int>) <span class="hljs-comment"># 44100 for CD, 48000 for video.</span> -<Wave_write>.setnchannels(<int>) <span class="hljs-comment"># 1 for mono, 2 for stereo.</span> -<Wave_write>.setsampwidth(<int>) <span class="hljs-comment"># 2 for CD quality sound.</span> -<Wave_write>.setparams(<params>) <span class="hljs-comment"># Sets all parameters.</span> -<Wave_write>.writeframes(<bytes>) <span class="hljs-comment"># Appends frames to the file.</span> +<pre><code class="python language-python hljs"><Wave> = wave.open(<span class="hljs-string">'<path>'</span>, <span class="hljs-string">'wb'</span>) <span class="hljs-comment"># Opens WAV file for writing.</span> +<Wave>.setframerate(<int>) <span class="hljs-comment"># Pass 44100 for CD, 48000 for video.</span> +<Wave>.setnchannels(<int>) <span class="hljs-comment"># Pass 1 for mono, 2 for stereo.</span> +<Wave>.setsampwidth(<int>) <span class="hljs-comment"># Pass 1 for 8-bit sound, 2 for CD.</span> +<Wave>.setparams(<params>) <span class="hljs-comment"># Sets all parameters.</span> +<Wave>.writeframes(<bytes>) <span class="hljs-comment"># Appends frames to the file.</span> </code></pre> <ul> <li><strong>Bytes object contains a sequence of frames, each consisting of one or more samples.</strong></li> @@ -2933,7 +2932,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the activ <footer> - <aside>January 11, 2024</aside> + <aside>January 13, 2024</aside> <a href="https://gto76.github.io" rel="author">Jure Šorn</a> </footer>