Newer
Older
padparadscha / python / test.py
@honosuke honosuke on 20 Nov 2018 856 bytes cleanliness commit
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
import soundfile as sf
import pyworld as pw

f0_1 = []
def pch(n):
    if n != 0:
        return 440
    else:
        return n

wavfile = './hoge.wav'

data, fs = sf.read(wavfile)

#_f0, t = pw.dio(data,fs) # 基本周波数の抽出
#f0 = pw.stonemask(data, _f0, t, fs)  # 基本周波数の修正
#sp = pw.cheaptrick(data, f0, t, fs)  # スペクトル包絡の抽出
#ap = pw.d4c(data, f0, t, fs)  # 非周期性指標の抽出

f0 , sp, ap = pw.wav2world(data, fs)
#

for val in f0:
    if val != 0:
        f0_1.append(pch(val))
    else:
        f0_1.append(val)

f0_2 = np.array(f0_1)

        
#
#y = pw.synthesize(f0, sp, ap, fs, pw.default_frame_period)
y = pw.synthesize(f0_2, sp, ap, fs, pw.default_frame_period)
sf.write('./output.wav', y, fs)

print(type(f0))
print(type(f0_2))