pyworld 部分 api 介绍

  1. 读取音频
import librosa
import pyworld
sound, _ = librosa.load(wav_path, sr=16000)
print(f'sound.shape = {sound.shape}') #sound.shape = (80000,)
  1. 提取基频F0
sr = 16000
#输入sound 需要为 double类型 librosa load 的waveform 是 float32
print(f'sound.dtype = {sound.dtype}') # sound.dtype = float32
sound = sound.astype(np.double)#第一种
_f0, t = pw.dio(sound, sr)    # raw pitch extractor
f0 = pw.stonemask(sound, _f0, t, sr)  # pitch refinement
#第二种
f0, timeaxis = pyworld.harvest(sound, sr)print(f'f0.shape = {f0.shape}') # f0.shape = (1001,)

基频维度计算
源码

#python
f0_length = GetSamplesForHarvest(fs, x_length, option.frame_period)
#c++
int GetSamplesForHarvest(int fs, int x_length, double frame_period) {return static_cast(1000.0 * x_length / fs / frame_period) + 1;
}

3.提取非周期特征AP

fft_size = 1024
ap = pyworld.d4c(sound, f0, timeaxis, sr, fft_size=fft_size)print(f'ap.shape = {ap.shape}') # ap.shape = (1001, 513)

维度计算

dim = fft_size//2 + 1
  1. 提取 频谱包络 SP
sp = pyworld.cheaptrick(wav, f0, timeaxis, sr, fft_size=fft_size)
print(f'sp.shape = {sp.shape}')#ap.shape = (1001, 513)
# 降维
coded_sp = pyworld.code_spectral_envelope(sp, sr, dim=128)
print(f'coded_sp.shape = {coded_sp.shape}') #coded_sp.shape = (1001, 128)


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部