これは、スタックに関する私の最初の投稿です。これまでのところ、このサイトは非常に役に立ちましたが、私は初心者であり、Python でのオーディオのピッチシフトに関連する問題について明確な説明が必要です。現在のモジュールがインストールされています: numpy、scipy、pygame、および scikits の「samplerate」API。
私の目標は、ステレオ ファイルを取得し、できるだけ少ない手順で異なるピッチで再生することです。現在、pygame.sndarray を使用してファイルを配列にロードし、scikits.samplerate.resample を使用してサンプルレート変換を適用し、pygame を使用して再生用に出力をサウンド オブジェクトに戻します。問題は、スピーカーからガベージ オーディオが出力されることです。確かに、いくつかの手順が欠けています (数学とオーディオについて何も知らないことに加えて)。
ありがとう。
import time, numpy, pygame.mixer, pygame.sndarray
from scikits.samplerate import resample
pygame.mixer.init(44100,-16,2,4096)
# choose a file and make a sound object
sound_file = "tone.wav"
sound = pygame.mixer.Sound(sound_file)
# load the sound into an array
snd_array = pygame.sndarray.array(sound)
# resample. args: (target array, ratio, mode), outputs ratio * target array.
# this outputs a bunch of garbage and I don't know why.
snd_resample = resample(snd_array, 1.5, "sinc_fastest")
# take the resampled array, make it an object and stop playing after 2 seconds.
snd_out = pygame.sndarray.make_sound(snd_resample)
snd_out.play()
time.sleep(2)