1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import numpy as np import pyworld as world import pyworld import librosa import librosa.display import os import soundfile
wav, fs = soundfile.read(os.getcwd()+"/bed (537).wav")
frame_period = 5.0 hop_length = int(fs * frame_period * 0.001) fftlen = world.get_cheaptrick_fft_size(fs)
f0, timeaxis = pyworld.harvest(wav, fs, frame_period=frame_period, f0_floor=71.0, f0_ceil=800.0) sp = pyworld.cheaptrick(wav, f0, timeaxis, fs) ap = pyworld.d4c(wav, f0, timeaxis, fs)
print(ap.shape) print(f"ap {np.isnan(ap).any()}")
wav = pyworld.synthesize(f0, sp, ap, fs, frame_period)
soundfile.write('test.wav', wav, fs)
x, sr = soundfile.read(os.getcwd()+"/bed (537).wav")
f01, timeaxis1 = pyworld.harvest(x, sr, frame_period=frame_period, f0_floor=71.0, f0_ceil=800.0) sp1 = pyworld.cheaptrick(x, f01, timeaxis1, fs) ap1 = pyworld.d4c(x, f01, timeaxis1, fs)
''' 以上这样,直接用soundfile 读取成float64 数据, 然后再直接用 soundfile.write 保存float64的文件 或者是 先转化成float32 再保存成文件, 保存出来的文件再次用soundfile 读取出来, 再次用测试ap是否有 nan值,都没有问题。 综上,能用soundfile就避免用librosa,读取和写入文件都是这个道理;ßå '''
print('************') print(ap1.shape) print(f"ap1 {np.isnan(ap1).any()}")
print(f"ap {np.isnan(ap).any()}")
count = 0 for x in ap: count = count+1
print(count)
if np.isnan(ap).any():
f0, sp, ap = world.wav2world(np.absolute(x),fs,fftlen,frame_period) print(f"ap abs {np.isnan(ap).any()}")
exit()
|