音频变速不变调 研究
class WSOLA(object):
def __init__(self, fs, speech_rate, shiftms=10):
self.fs = fs # tensor
self.speech_rate = speech_rate # 16000
self.shiftms = shiftms # shift length [ms] 25-15,
self.sl = int(self.fs * self.shiftms / 1000) # of samples in a shift 160
self.fl = self.sl * 2 # of samples in a frame 320
self.epstep = int(self.sl * self.speech_rate) # step size for WSOLA 192
self.win = np.hanning(self.fl) # window function for a frame
def duration_modification(self, x):
wlen = len(x)
wsolaed = np.zeros(int(wlen / self.speech_rate), dtype='d')
# initialization
sp = self.sl * 2 # 320
rp = sp + self.sl # 320 + 160
ep = sp + self.epstep # 320 + 192
outp = self.sl
# allocate first frame of waveform to outp
wsolaed[:outp] = x[:outp]
while wlen > ep + self.fl:
# copy wavform
ref = x[rp - self.sl:rp + self.sl]
buff = x[ep - self.fl:ep + self.fl]
# search minimum distance bepween ref and buff
delta = self._search_minimum_distance(ref, buff)
print(delta)
return
epd = ep + delta
# store WSOLAed waveform using over-lap add
spdata = x[sp:sp + self.sl] * self.win[self.sl:]
epdata = x[epd - self.sl:epd] * self.win[:self.sl]
if len(spdata) == len(wsolaed[outp:outp + self.sl]):
wsolaed[outp:outp + self.sl] = spdata + epdata
else:
wsolaed_len = len(wsolaed[outp:outp + self.sl])
wsolaed[outp:outp + self.sl] = spdata[:wsolaed_len] + \
epdata[:wsolaed_len]
outp += self.sl
# transtion to next frame
sp = epd
rp = sp + self.sl
ep += self.epstep
return wsolaed
def _search_minimum_distance(self, ref, buff):
if len(ref) < self.fl:
ref = np.r_[ref, np.zeros(self.fl - len(ref))]
# slicing and windowing one sample by one
buffmat = view_as_windows(buff, self.fl) * self.win
refwin = np.array(ref * self.win).reshape(1, self.fl)
corr = signal.correlate2d(buffmat, refwin, mode='valid')
print(len(corr) , np.argmax(corr))
return np.argmax(corr) - self.sl
https://blog.csdn.net/weixin_42476279/article/details/113566752
https://blog.csdn.net/qq_36002089/article/details/115630385
argmax
分类:
算法
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人