def __test(order): a1 = pysptk.lpc(x, order, use_scipy=False) a2 = pysptk.lpc(x, order, use_scipy=True) a3 = pysptk.levdur(pysptk.acorr(x, order), use_scipy=False) a4 = pysptk.levdur(pysptk.acorr(x, order), use_scipy=True) assert np.all(np.isfinite(a1)) assert np.allclose(a1, a2) assert np.allclose(a1, a3) assert np.allclose(a1, a4)
def test_lpc(order): x = windowed_dummy_data(1024) a1 = pysptk.lpc(x, order, use_scipy=False) a2 = pysptk.lpc(x, order, use_scipy=True) a3 = pysptk.levdur(pysptk.acorr(x, order), use_scipy=False) a4 = pysptk.levdur(pysptk.acorr(x, order), use_scipy=True) assert np.all(np.isfinite(a1)) assert np.allclose(a1, a2) assert np.allclose(a1, a3) assert np.allclose(a1, a4)
def task3(): def lpc(data,order=10): data=data.astype("int64") acf=sig.correlate(in1=data, in2=data, mode="full",method="direct") mid=len(acf)//2 matrix=np.array([acf[mid-i:mid-i+order] for i in range(order)]) print(matrix.dtype) gammavec=acf[mid+1:mid+1+order] sol=la.solve(matrix,gammavec) print(sol) return sol rate,data_a=wav.read(f"oving8/vowels/a.wav") _, data_ae=wav.read("oving8/vowels/ae.wav") a = lpc(data_a) b = lpc(data_ae) filtered_a=sig.lfilter(b, a, data_ae) wav.write("filtered_a.wav",rate,filtered_a)
def test_lpc(): # frame -l 512 -p 80 < test16k.float | window -l 512 | dmp +f | awk \ # '{print $2}' > test16k_windowed.txt frames = (np.loadtxt(join(DATA_DIR, "test16k_windowed.txt")).reshape( 759, 512).astype(np.float64)) # frame -l 512 -p 80 < test16k.float | window -l 512 | lpc -m 25 -l 512 > test16k.lpc lpc = (np.fromfile(join(DATA_DIR, "test16k.lpc"), np.float32).reshape(759, 26).astype(np.float64)) lpc_hat = pysptk.lpc(frames, order=25) # yeah may have a bug... assert np.allclose(lpc, lpc_hat, atol=1e-1)
def __test_synthesis(filt): # dummy source excitation source = __dummy_source() hopsize = 80 # dummy filter coef. windowed = __dummy_windowed_frames(source, frame_len=512, hopsize=hopsize) lpc = pysptk.lpc(windowed, filt.order) lsp = pysptk.lpc2lsp(lpc) # make sure lsp has loggain lsp[:, 0] = np.log(lsp[:, 0]) # synthesis synthesizer = Synthesizer(filt, hopsize) y = synthesizer.synthesis(source, lsp) assert np.all(np.isfinite(y))
def test_lpc2lsp(): for order in [15, 20, 25, 30]: yield __test_transform_base, pysptk.lpc2lsp, order def __test_invalid_otype(dummy_lpc, otype): pysptk.lpc2lsp(dummy_lpc, otype=otype) np.random.seed(98765) dummy_lpc = pysptk.lpc(np.random.rand(512), 21) # invalid otype yield raises(ValueError)(__test_invalid_otype), dummy_lpc, 2 yield raises(ValueError)(__test_invalid_otype), dummy_lpc, 3 lsp1 = pysptk.lpc2lsp(dummy_lpc, otype=2, fs=16000) lsp2 = pysptk.lpc2lsp(dummy_lpc, otype=3, fs=16) assert np.allclose(lsp1, lsp2) # loggain lsp3 = pysptk.lpc2lsp(dummy_lpc, otype=3, fs=16, loggain=True) assert lsp3[0] == np.log(lsp2[0])
def __test_synthesis(filt): # dummy source excitation source = __dummy_source() hopsize = 80 # dummy filter coef. windowed = __dummy_windowed_frames(source, frame_len=512, hopsize=hopsize) lpc = pysptk.lpc(windowed, filt.order) lpc[:, 0] = 0 b = -lpc # synthesis synthesizer = Synthesizer(filt, hopsize) y = synthesizer.synthesis(source, b) assert np.all(np.isfinite(y)) # transpose synthesizer = Synthesizer(filt, hopsize, transpose=True) y = synthesizer.synthesis(source, b) assert np.all(np.isfinite(y))
import pysptk from scipy.io import wavfile import librosa.util frame_length = 2048 hop_length = 512 order = 20 path = '../ETTS_newdata/data/wav/lmy00001.wav' # LPC sr, x = wavfile.read(path) x = x.astype(np.float64) librosa.util.valid_audio(x) x = np.pad(x, int(frame_length // 2), mode='reflect') frames = librosa.util.frame(x, frame_length=frame_length, hop_length=hop_length).astype(np.float64).T frames *= pysptk.blackman(frame_length) lpc = pysptk.lpc(frames, order) lpc[:, 0] = np.log(lpc[:, 0]) #MFCC y, sr = librosa.load(path) y = y.astype(np.float64) mfcc = librosa.feature.mfcc(y=y, sr=sr, n_fft=frame_length, hop_length=hop_length) print(d)
hop_length=HOP_LENGTH).astype(np.float64).T frames *= pysptk.blackman(FRAME_LENGTH) # 窓掛け(ブラックマン窓) # ピッチ抽出 pitch = pysptk.swipe(x, fs=fs, hopsize=HOP_LENGTH, min=MIN_F0, max=MAX_F0, otype="pitch") # 励振源信号(声帯音源)の生成 source_excitation = pysptk.excite(pitch, HOP_LENGTH) # 線形予測分析による線形予測符号化(LPC)係数の抽出 lpc = pysptk.lpc(frames, ORDER) lpc[:, 0] = np.log(lpc[:, 0]) # LPC係数をPARCOR係数に変換 parcor = pysptk.lpc2par(lpc) # 全極フィルタの作成 synthesizer = Synthesizer(AllPoleLatticeDF(order=ORDER), HOP_LENGTH) # 励振源信号でフィルタを駆動して音声を合成 y = synthesizer.synthesis(source_excitation, parcor) # 音声の書き込み y = y.astype(np.int16) wavfile.write(OUT_WAVE_FILE, fs, y)
def test_lpc_failure(): pysptk.lpc(np.zeros(256), 40, use_scipy=False)
def __test_min_det(min_det): pysptk.lpc(x, min_det=min_det, use_scipy=False)
def __test(order): a = pysptk.lpc(x, order) assert np.all(np.isfinite(a))
def test_lpc_failure(): with pytest.raises(RuntimeError): pysptk.lpc(np.zeros(256), 40, use_scipy=False)
print(p) x[-4] = 0 x[-3] = 0 x[-2] = 0 x[-1] = 0 sumi = 0 for j in range(101): for i in range(4): sumi += p * x[j] print(x[j] - sumi) np.random.seed(1) N = 10 b1 = np.random.rand(N) b2 = np.random.rand(N) X = np.column_stack([x, x]) X -= X.mean(axis=0) fact = N - 1 by_hand = np.dot(X.T, X.conj()) / fact print(by_hand) import seaborn import scipy import pysptk from pysptk.synthesis import AllPoleDF lpc = pysptk.lpc(x, 4) print(lpc)
def test_lpc_failure(): pysptk.lpc(np.zeros(256), 40)
def __test_min_det(min_det): pysptk.lpc(x, min_det=min_det)