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<int>(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)
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值