<Wave_write>.setnchannels(<int>) <spanclass="hljs-comment"># Number of samples per frame.</span>
<Wave_write>.setsampwidth(<int>) <spanclass="hljs-comment"># Sample size in bytes.</span>
<Wave_write>.setframerate(<int>) <spanclass="hljs-comment"># Frames per second.</span>
<Wave_write>.setframerate(<int>) <spanclass="hljs-comment"># 44100 for CD, 48000 for video.</span>
<Wave_write>.setnchannels(<int>) <spanclass="hljs-comment"># 1 for mono, 2 for stereo.</span>
<Wave_write>.setsampwidth(<int>) <spanclass="hljs-comment"># 2 for CD quality sound.</span>
<Wave_write>.writeframes(<bytes>)
</code></pre>
<ul>
<li><strong>Bytes object contains a seqence of frames, each consisting of one or more samples.</strong></li>
<li><strong>Each sample consists of one or more bytes that, when converted to an integer, indicate the displacement of a speaker membrane at a given moment.</strong></li>
<li><strong>If sample width is one, then the integer is interpreted as unsigned.</strong></li>
<li><strong>For all other sample sizes the integer is interpreted as signed with little-endian byte order.</strong></li>
<li><strong>In stereo signal first sample of a frame belongs to the left channel.</strong></li>
<div><h4id="addsnoisetoamonowavfile">Adds noise to a mono WAV file:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> random <spanclass="hljs-keyword">import</span> random
add_noise = <spanclass="hljs-keyword">lambda</span> value: max(<spanclass="hljs-number">-1</span>, min(<spanclass="hljs-number">1</span>, value + (random()<spanclass="hljs-number">-0.5</span>)*<spanclass="hljs-number">0.03</span>))
frames_f = (add_noise(a) <spanclass="hljs-keyword">for</span> a <spanclass="hljs-keyword">in</span> read_wav_file(<spanclass="hljs-string">'test.wav'</span>))
frames_f = (a + (random()<spanclass="hljs-number">-0.5</span>) * <spanclass="hljs-number">0.03</span><spanclass="hljs-keyword">for</span> a <spanclass="hljs-keyword">in</span> read_wav_file(<spanclass="hljs-string">'test.wav'</span>))