pitch = librosa.yin(y,fmin = librosa.note_to_hz('C1'),fmax = librosa.note_to_hz('C7'))
时间: 2024-05-22 19:11:34 浏览: 190
这段代码使用了`librosa`库中的`yin`函数来进行基频估计。`yin`函数实现了YIN算法,它是一种基于自相关函数的算法,用于估计音频信号的基频。其中,`y`是输入的音频信号,`fmin`和`fmax`分别指定了基频搜索的最小和最大频率范围,这里分别设置为`C1`和`C7`的频率。`librosa.note_to_hz`函数可以将音符转换为对应的频率。最终,`pitch`存储了估计出的基频序列。
相关问题
f0, voiced_flag, voiced_probs = librosa.pyin(y, fmin=librosa.note_to_hz('C2'), fmax=librosa.note_to_hz('C7'))计算原理
librosa.pyin函数是基于基音自适应算法(Pitch-adaptive Fourier decomposition,PAFD)的基音音高估计方法之一。它使用自相关函数(ACF)和差分函数(DF)来识别基音周期,并利用基音周期来计算基音频率。
函数参数中的y是一个长度为N的音频信号,fmin和fmax是基音频率的最小和最大值。函数返回值f0是一个长度为N的一维数组,包含信号中每个时间点的基音频率。voiced_flag是一个布尔类型的一维数组,它指示每个时间点声音是否有基音,其中True表示存在基音,False表示不存在基音。voiced_probs是一个长度为N的一维数组,它指示每个时间点是否存在基音的概率。
该函数的计算过程如下:
1. 对音频信号进行预处理,包括帧化、加窗和差分滤波。
2. 计算每个帧的自相关函数(ACF)和差分函数(DF)。
3. 根据ACF和DF计算每个帧中可能的周期,其中周期的范围由fmin和fmax定义。
4. 使用一个置信度函数来估计每个周期的置信度,以确定每个帧的基音周期。
5. 根据基音周期计算每个帧的基音频率。
6. 根据基音频率和置信度函数,估计每个帧是否有基音以及存在基音的概率。
需要注意的是,该函数的计算结果受到信号质量、信噪比、基音频率范围等因素的影响,因此结果可能存在一定的误差。
我的代码是s_output = librosa.effects.pitch_shift(s_input, 44100, n_step=12),当运行时报了这样的错pitch_shift() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument )were given
这个错误提示说明 `pitch_shift()` 函数只需要一个位置参数,但是你给它传递了两个位置参数。看起来你传递了 `s_input` 和 `44100` 作为两个位置参数,但是 `pitch_shift()` 只需要一个音频信号作为输入。
你可以尝试修改代码,只传递一个位置参数,如下所示:
```python
s_output = librosa.effects.pitch_shift(s_input, n_steps=12)
```
这里只传递了一个 `s_input` 参数,而 `n_steps` 参数使用了关键字参数的方式传递。这应该可以解决你的问题。
阅读全文
相关推荐















