{"id":225745,"date":"2014-06-09T23:36:03","date_gmt":"2014-06-09T19:36:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=225745"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=225745","title":{"rendered":"<span class=\"post_title\">\u041f\u0438\u0442\u043e\u043d, \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043d\u0430 \u0438 \u041f\u0438\u0430\u043d\u043e\u043f\u044c\u044e\u0442\u0435\u0440<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u043c \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0435 \u043d\u043e\u0432\u0430 \u2014 \u043e\u043d\u0430 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u0430 \u0430\u0436 29 \u043c\u0430\u0440\u0442\u0430. \u041d\u043e \u043d\u0430 \u0420\u0435\u0434\u0434\u0438\u0442\u0435 \u0435\u0435 \u0437\u0430\u043f\u043e\u0441\u0442\u0438\u043b\u0438 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434, \u0434\u0430 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0432\u043e\u0435\u0439 \u043e\u043d\u0430 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0430. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0441\u0442\u044c \u0435\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0432\u0442\u043e\u0440 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a: numpy, scipy \u0438 pygame. \u041f\u0440\u043e \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u0430\u0443\u0447\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0442, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u0439\u00bb \u0436\u0438\u0437\u043d\u0438. \u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430\u044f \u0432\u0438\u0434\u0435\u043e-\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0445\u043e\u0442\u044f \u0431\u044b \u0435\u0435 \u0442\u043e\u0447\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c.<\/p>\n<p>  \u0410\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d \u043d\u0435 \u043f\u043e PEP-8 \u0438 \u0437\u0430 \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u044f \u043d\u0435 \u0440\u0443\u0447\u0430\u044e\u0441\u044c. \u041d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0435\u0441\u0442\u044c \u043d\u0430 \u0413\u0438\u0442\u0425\u0430\u0431\u0435, \u0441\u0441\u044b\u043b\u043a\u0443 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  <i>\u0417\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0437\u0432\u0443\u043a, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0442\u043e\u043d 50 \u0440\u0430\u0437 \u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043d\u043e\u0432\u043e\u043c\u0443 \u0437\u0432\u0443\u043a\u0443 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u041f\u0438\u0430\u043d\u043e\u043f\u044c\u044e\u0442\u0435\u0440!<\/i><\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0417\u0432\u0443\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432 (\u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a, <i>list<\/i>) \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/1ab\/672\/698\/1ab672698be5b500d744996c69f6004a.png\"\/><\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u0432\u0443\u043a \u0432\u0434\u0432\u043e\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0443\u0434\u0430\u043b\u0438\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u0442\u043e\u0440\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/308\/899\/32a\/30889932ae1f54b35caa5623a90494f3.png\"\/><\/p>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0432 \u044d\u0442\u043e, \u043c\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0434\u0432\u043e\u0435 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0432\u0443\u043a\u0430, \u043d\u043e \u0438 \u0443\u0434\u0432\u043e\u0438\u043b\u0438 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043e\u0442\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0435\u0433\u043e \u0442\u043e\u043d \u0441\u0442\u0430\u043b \u0432\u044b\u0448\u0435.<\/p>\n<p>  \u041d\u0430\u043f\u0440\u043e\u0442\u0438\u0432, \u0435\u0441\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0437\u0432\u0443\u043a, \u0441 \u0431\u043e\u043b\u0435\u0435 \u0434\u043b\u0438\u043d\u043d\u044b\u043c \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u043c, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0438 \u043d\u0438\u0436\u0435 \u0442\u043e\u043d\u043e\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/4d0\/c1d\/1cc\/4d0c1d1ccfb8799f4ba7a32aaad46516.png\"\/><\/p>\n<p>  \u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0432\u0443\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0443:<\/p>\n<pre><code class=\"python\">import numpy as np  def speedx(sound_array, factor):     &quot;&quot;&quot; Multiplies the sound's speed by some `factor` &quot;&quot;&quot;     indices = np.round( np.arange(0, len(snd_array), factor) )     indices = indices[indices &lt; len(snd_array)].astype(int)     return sound_array[ indices.astype(int) ]<\/code><\/pre>\n<p>  C\u043b\u043e\u0436\u043d\u0435\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0442\u043e\u043d (\u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430), \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u043e\u043d, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043d\u0430).<\/p>\n<h4>\u0420\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430<\/h4>\n<p>  \u0420\u0430\u0441\u0442\u044f\u043d\u0443\u0442\u044c \u0437\u0432\u0443\u043a \u043c\u043e\u0436\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 <i>\u0444\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0432\u043e\u043a\u043e\u0434\u0435\u0440\u0430<\/i> (<i>phase vocoder<\/i>). \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0437\u0432\u0443\u043a \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043a\u0443\u0441\u043a\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c \u0438\u0445 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u043b\u0438\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 (\u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0437\u0432\u0443\u043a) \u0438\u043b\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 (\u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0440\u0430\u0441\u0442\u044f\u043d\u0443\u0442\u044c), \u043a\u0430\u043a \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/35b\/d83\/d56\/35bd83d5602e48709eb8d952c2f77636.png\"\/><\/p>\n<p>  \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u043a\u0443\u0441\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043b\u043e\u0445\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u0444\u0430\u0437\u043e\u0432\u0430\u044f \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435, \u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 <a href=\"http:\/\/audioprograming.wordpress.com\/2012\/03\/02\/a-phase-vocoder-in-python\/\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>:<\/p>\n<pre><code class=\"python\">def stretch(sound_array, f, window_size, h):     &quot;&quot;&quot; Stretches the sound by a factor `f` &quot;&quot;&quot;      phase  = np.zeros(window_size)     hanning_window = np.hanning(window_size)     result = np.zeros( len(sound_array) \/f + window_size)      for i in np.arange(0, len(sound_array)-(window_size+h), h*f):          # two potentially overlapping subarrays         a1 = sound_array[i: i + window_size]         a2 = sound_array[i + h: i + window_size + h]          # resynchronize the second array on the first         s1 =  np.fft.fft(hanning_window * a1)         s2 =  np.fft.fft(hanning_window * a2)         phase = (phase + np.angle(s2\/s1)) % 2*np.pi         a2_rephased = np.fft.ifft(np.abs(s2)*np.exp(1j*phase))          # add to result         i2 = int(i\/f)         result[i2 : i2 + window_size] += hanning_window*a2_rephased      result = ((2**(16-4)) * result\/result.max()) # normalize (16bit)      return result.astype('int16')<\/code><\/pre>\n<h4>\u0421\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043d\u0430<\/h4>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u043d\u0438\u044f \u0437\u0432\u0443\u043a\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u0442\u043e\u043d, \u0440\u0430\u0441\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u043c \u0437\u0432\u0443\u043a, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0442\u043e\u043d, \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0447\u0442\u043e\u0431\u044b \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0432\u0443\u043a \u0438\u043c\u0435\u043b \u0442\u0443 \u0436\u0435 \u0434\u043b\u0438\u043d\u0443, \u0447\u0442\u043e \u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u0442\u043e\u043d \u0438\u0437-\u0437\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0423\u0434\u0432\u043e\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0437\u0432\u0443\u043a\u0430 \u043f\u043e\u0432\u044b\u0441\u0438\u0442 \u0442\u043e\u043d \u043d\u0430 \u043e\u0434\u043d\u0443 \u043e\u043a\u0442\u0430\u0432\u0443, \u0438\u043b\u0438 12 \u043f\u043e\u043b\u0443\u0442\u043e\u043d\u043e\u0432. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u0442\u043e\u043d\u0430 \u043d\u0430 <i>n<\/i> \u043f\u043e\u043b\u0443\u0442\u043e\u043d\u043e\u0432, \u043d\u0430\u0434\u043e \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u0432\u044b\u0441\u043e\u0442\u0443 \u043d\u0430 2^(n\/12):<\/p>\n<pre><code class=\"python\">def pitchshift(snd_array, n, window_size=2**13, h=2**11):     &quot;&quot;&quot; Changes the pitch of a sound by ``n`` semitones. &quot;&quot;&quot;     factor = 2**(1.0 * n \/ 12.0)     stretched = stretch(snd_array, 1.0\/factor, window_size, h)     return speedx(stretched[window_size:], factor)<\/code><\/pre>\n<h4>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435: \u041f\u0438\u0430\u043d\u043e\u043f\u044c\u044e\u0442\u0435\u0440<\/h4>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u044b\u0442\u0430\u0435\u043c \u043d\u0430\u0448 \u043d\u043e\u0432\u044b\u0439 \u0442\u043e\u043d\u043e\u0441\u043c\u0435\u0441\u0442\u0438\u0442\u0435\u043b\u044c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0443\u043a\u043d\u0435\u043c \u043f\u043e \u0447\u0430\u0448\u0435:<\/p>\n<p>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/oXm0CLp40ws?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c 50 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u0437\u0432\u0443\u043a\u043e\u0432 \u043e\u0442 \u043e\u0447\u0435\u043d\u044c \u043d\u0438\u0437\u043a\u043e\u0433\u043e \u0434\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e:<\/p>\n<pre><code class=\"python\">from scipy.io import wavfile  fps, bowl_sound = wavfile.read(&quot;bowl.wav&quot;) tones = range(-25,25) transposed = [pitchshift(bowl_sound, n) for n in tones]<\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u043e\u0439 \u043a\u043b\u0430\u0432\u0438\u0448\u0435 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u043c \u0437\u0432\u0443\u043a, \u0441\u043b\u0435\u0434\u0443\u044f \u043f\u043e\u0440\u044f\u043b\u043a\u0443, \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 <a href=\"https:\/\/raw.githubusercontent.com\/Zulko\/pianoputer\/master\/typewriter.kb\">\u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435<\/a>, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"\/\/habrastorage.org\/files\/f2e\/9a3\/ca0\/f2e9a3ca063d4192975dfca694bf2a62.jpg\"\/><\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u0432 \u043f\u0438\u0430\u043d\u0438\u043d\u043e (<i>\u043f\u0438\u0430\u043d\u043e\u043f\u044c\u044e\u0442\u0435\u0440<\/i>):<\/p>\n<pre><code class=\"python\">import pygame  pygame.mixer.init(fps, -16, 1, 512) # so flexible ;) screen = pygame.display.set_mode((640,480)) # for the focus  # Get a list of the order of the keys of the keyboard in right order. # ``keys`` is like ['Q','W','E','R' ...]  keys = open('typewriter.kb').read().split('\\n')  sounds = map(pygame.sndarray.make_sound, transposed) key_sound = dict( zip(keys, sounds) ) is_playing = {k: False for k in keys}  while True:      event =  pygame.event.wait()      if event.type in (pygame.KEYDOWN, pygame.KEYUP):         key = pygame.key.name(event.key)      if event.type == pygame.KEYDOWN:          if (key in key_sound.keys()) and (not is_playing[key]):             key_sound[key].play(fade_ms=50)             is_playing[key] = True          elif event.key == pygame.K_ESCAPE:             pygame.quit()             raise KeyboardInterrupt      elif event.type == pygame.KEYUP and key in key_sound.keys():          key_sound[key].fadeout(50) # stops with 50ms fadeout         is_playing[key] = False<\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435! \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u044f \u0441\u044b\u0433\u0440\u0430\u044e \u0432\u0430\u043c \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0442\u0443\u0440\u0435\u0446\u043a\u0443\u044e \u043f\u0435\u0441\u0435\u043d\u043a\u0443 (<i>\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0442. \u041f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432.<\/i>)!<\/p>\n<p>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/z410eauCnHc?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043e\u043c\u0430, \u0432\u043e\u0442 <a href=\"https:\/\/github.com\/Zulko\/pianoputer\">\u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f. \u0414\u0443\u043c\u0430\u044e, \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e, \u0435\u0441\u043b\u0438 \u0431\u044b \u043a\u0442\u043e-\u0442\u043e \u0441\u0440\u0435\u0434\u0438 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 HTML5\/JS\/elm-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043b \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u041f\u0438\u0430\u043d\u043e\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u0442\u0430\u043a \u043e\u043d \u0441\u0442\u0430\u043b \u0431\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435, \u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u044b \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f <i>\u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/i> \u043c\u0443\u0437\u044b\u043a\u0438. \u042f \u043f\u043e\u043d\u0438\u043c\u0430\u044e, \u0447\u0442\u043e \u043b\u0435\u0433\u0447\u0435 \u0432\u0437\u044f\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0444\u043e\u0440\u0442\u0435\u043f\u0438\u0430\u043d\u043d\u0443\u044e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443 \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043d\u043e \u0432\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u0447\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0447\u0430\u0448\u0438 \u0438 60 \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435!<\/p>\n<p>  \u0414\u0430\u0436\u0435 \u0434\u0435\u0448\u0435\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u043d\u0446\u0438\u0435\u0439: \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0442\u044c \u0432 \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0436\u0435\u0441\u0442\u044b \u0447\u0435\u0440\u0435\u0437 \u0432\u0435\u0431-\u043a\u0430\u043c\u0435\u0440\u0443, \u043c\u043e\u0434\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u044f\u043a\u0438\u0435 \u0448\u0442\u0443\u043a\u0438 \u043c\u044b\u0448\u043a\u043e\u0439 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0441 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b. \u0421\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0441\u0430\u043c\u043e\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0430 \u041f\u0438\u0442\u043e\u043d\u0435\u2026 \u0410\u0440\u0442\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0435 \u0445\u0430\u043a\u0435\u0440\u044b, \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0436\u0435\u043b\u0430\u0435\u0442 \u0448\u0430\u0433\u043d\u0443\u0442\u044c \u0432 \u044d\u0442\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443?   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/225745\/\"> http:\/\/habrahabr.ru\/post\/225745\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430:<\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u043c \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0435 \u043d\u043e\u0432\u0430 \u2014 \u043e\u043d\u0430 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u0430 \u0430\u0436 29 \u043c\u0430\u0440\u0442\u0430. \u041d\u043e \u043d\u0430 \u0420\u0435\u0434\u0434\u0438\u0442\u0435 \u0435\u0435 \u0437\u0430\u043f\u043e\u0441\u0442\u0438\u043b\u0438 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434, \u0434\u0430 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0432\u043e\u0435\u0439 \u043e\u043d\u0430 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0430. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0441\u0442\u044c \u0435\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0432\u0442\u043e\u0440 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a: numpy, scipy \u0438 pygame. \u041f\u0440\u043e \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438, \u043d\u043e \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u0430\u0443\u0447\u043d\u044b\u0445 \u0440\u0430\u0431\u043e\u0442, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0432 \u00ab\u043e\u0431\u044b\u0447\u043d\u043e\u0439\u00bb \u0436\u0438\u0437\u043d\u0438. \u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430\u044f \u0432\u0438\u0434\u0435\u043e-\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0445\u043e\u0442\u044f \u0431\u044b \u0435\u0435 \u0442\u043e\u0447\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c.<\/p>\n<p>  \u0410\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d \u043d\u0435 \u043f\u043e PEP-8 \u0438 \u0437\u0430 \u0435\u0433\u043e \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u044f \u043d\u0435 \u0440\u0443\u0447\u0430\u044e\u0441\u044c. \u041d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0435\u0441\u0442\u044c \u043d\u0430 \u0413\u0438\u0442\u0425\u0430\u0431\u0435, \u0441\u0441\u044b\u043b\u043a\u0443 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>  <i>\u0417\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0437\u0432\u0443\u043a, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0442\u043e\u043d 50 \u0440\u0430\u0437 \u0438 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043d\u043e\u0432\u043e\u043c\u0443 \u0437\u0432\u0443\u043a\u0443 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 \u043d\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0435 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u041f\u0438\u0430\u043d\u043e\u043f\u044c\u044e\u0442\u0435\u0440!<\/i><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-225745","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/225745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=225745"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/225745\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=225745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=225745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=225745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}