我想比较两个语音文件。 第一个文件(ref)和比较文件(comp)分别由不同的人发音。 我的假设是,语音相似度越接近,发音、语调、语气就会相同。 然而,问题是这两个文件的长度不同。可以比较吗?
!pip install librosa # colab
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import librosa
import librosa.display
plt.figure(figsize=(10, 3))
x_1, fs_1 = librosa.load('voice_tar.wav')
x_2, fs_2 = librosa.load('voice_comp.wav')
print('<Voice_tar>', 'audio shape:', x_1.shape, 'length:', x_1.shape[0]/float(fs_1), 'secs')
print('<Voice_comp>', 'audio shape:', x_2.shape, 'length:', x_2.shape[0]/float(fs_2), 'secs')
fig, ax = plt.subplots(nrows=2, sharex=True, sharey=True)
librosa.display.waveshow(x_1, sr=fs_1, ax=ax[0])
ax[0].set(title='Voice_tar')
ax[0].label_outer()
librosa.display.waveshow(x_2, sr=fs_2, ax=ax[1])
ax[1].set(title='Voice_comp')
结果如下。
这是2个语音文件的图像。
并且,如何通过 ibrosa.segment.cross_similarity() 获得相似度?
我也在研究这个问题;直接处理音频更好,但是上面仍然没有解决方案,您可以尝试将其转换为具有图像问题的计算机视觉,如下
读取 2 个音频,将其特征写入 2 个图像,例如
x, sr = librosa.load(duongdan)
if show:
librosa.display.waveshow(y_ref, sr=sr1, alpha=0.4)
plt.show()
fea = librosa.feature.spectral_centroid(y=x, sr=sr)[0] # or any feature you want
frames = range(len(fea)) # Computing the time variable for visualization
t = librosa.frames_to_time(frames)
plt.plot(t, fea, color='b')
计算这两个图像之间的相似度,使用 phash 作为 https://pypi.org/project/ImageHash/ 或 https://github.com/thorn-oss/perception; 或者我考虑过直方图,但是还没有做任何事