第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

與librosa vs python_speech_features vs tensorflow

與librosa vs python_speech_features vs tensorflow

青春有我 2022-08-16 16:08:06
我正在嘗試從音頻(.wav文件)中提取MFCC功能,我已經(jīng)嘗試過(guò),但它們給出了完全不同的結(jié)果:python_speech_featureslibrosaaudio, sr = librosa.load(file, sr=None)# librosahop_length = int(sr/100)n_fft = int(sr/40)features_librosa = librosa.feature.mfcc(audio, sr, n_mfcc=13, hop_length=hop_length, n_fft=n_fft)# psffeatures_psf = mfcc(audio, sr, numcep=13, winlen=0.025, winstep=0.01)情節(jié)本身更接近librosa的情節(jié),但比例更接近python_speech_features。(請(qǐng)注意,這里我計(jì)算了80個(gè)mel條柱并取了前13個(gè);如果我只用13個(gè)箱子進(jìn)行計(jì)算,結(jié)果看起來(lái)也大不相同)。代碼如下:stfts = tf.signal.stft(audio, frame_length=n_fft, frame_step=hop_length, fft_length=512)spectrograms = tf.abs(stfts)num_spectrogram_bins = stfts.shape[-1]lower_edge_hertz, upper_edge_hertz, num_mel_bins = 80.0, 7600.0, 80linear_to_mel_weight_matrix = tf.signal.linear_to_mel_weight_matrix(    num_mel_bins, num_spectrogram_bins, sr, lower_edge_hertz, upper_edge_hertz)mel_spectrograms = tf.tensordot(spectrograms, linear_to_mel_weight_matrix, 1)mel_spectrograms.set_shape(spectrograms.shape[:-1].concatenate(linear_to_mel_weight_matrix.shape[-1:]))log_mel_spectrograms = tf.math.log(mel_spectrograms + 1e-6)features_tf = tf.signal.mfccs_from_log_mel_spectrograms(log_mel_spectrograms)[..., :13]features_tf = np.array(features_tf).T我想我的問(wèn)題是:哪個(gè)輸出更接近MFCC的實(shí)際樣子?
查看完整描述

2 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

這里至少有兩個(gè)因素可以解釋為什么你會(huì)得到不同的結(jié)果:

  1. mel尺度沒(méi)有單一的定義。 實(shí)現(xiàn)兩種方式:SlaneyHTK。其他包可能會(huì)并且將使用不同的定義,從而導(dǎo)致不同的結(jié)果。話雖如此,整體情況應(yīng)該是相似的。這就引出了第二個(gè)問(wèn)題...Librosa

  2. python_speech_features默認(rèn)情況下,將能量作為第一個(gè)(索引零)系數(shù)(默認(rèn)情況下),這意味著當(dāng)您要求例如13 MFCC時(shí),您實(shí)際上得到12 + 1。appendEnergyTrue

換句話說(shuō),您沒(méi)有比較13對(duì)13的系數(shù),而是13對(duì)12的系數(shù)。能量可以具有不同的量級(jí),因此由于不同的色標(biāo),會(huì)產(chǎn)生完全不同的圖像。librosapython_speech_features

現(xiàn)在,我將演示這兩個(gè)模塊如何產(chǎn)生類似的結(jié)果:

import librosa

import python_speech_features

import matplotlib.pyplot as plt

from scipy.signal.windows import hann

import seaborn as sns


n_mfcc = 13

n_mels = 40

n_fft = 512 

hop_length = 160

fmin = 0

fmax = None

sr = 16000

y, sr = librosa.load(librosa.util.example_audio_file(), sr=sr, duration=5,offset=30)


mfcc_librosa = librosa.feature.mfcc(y=y, sr=sr, n_fft=n_fft,

                                    n_mfcc=n_mfcc, n_mels=n_mels,

                                    hop_length=hop_length,

                                    fmin=fmin, fmax=fmax, htk=False)


mfcc_speech = python_speech_features.mfcc(signal=y, samplerate=sr, winlen=n_fft / sr, winstep=hop_length / sr,

                                          numcep=n_mfcc, nfilt=n_mels, nfft=n_fft, lowfreq=fmin, highfreq=fmax,

                                          preemph=0.0, ceplifter=0, appendEnergy=False, winfunc=hann)

http://img1.sycdn.imooc.com//62fb50ab000116ac09841192.jpg

如您所見(jiàn),比例不同,但整體情況看起來(lái)非常相似。請(qǐng)注意,我必須確保傳遞給模塊的許多參數(shù)是相同的。


查看完整回答
反對(duì) 回復(fù) 2022-08-16
?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

這就是那種讓我徹夜難眠的東西。這個(gè)答案是正確的(而且非常有用?。┑⒉煌暾?,因?yàn)樗鼪](méi)有解釋兩種方法之間的巨大差異。我的答案增加了一個(gè)重要的額外細(xì)節(jié),但仍然無(wú)法實(shí)現(xiàn)完全匹配。

正在發(fā)生的事情很復(fù)雜,最好用下面的冗長(zhǎng)代碼塊來(lái)解釋,該代碼塊與另一個(gè)包進(jìn)行比較。librosapython_speech_featurestorchaudio

  • 首先,請(qǐng)注意torchaudio的實(shí)現(xiàn)有一個(gè)參數(shù),其默認(rèn)值(False)模仿librosa實(shí)現(xiàn),但如果設(shè)置為True將模仿python_speech_features。在這兩種情況下,結(jié)果仍然不準(zhǔn)確,但相似之處是顯而易見(jiàn)的。log_mels

  • 其次,如果你深入研究torchaudio實(shí)現(xiàn)的代碼,你會(huì)看到一個(gè)注釋,即默認(rèn)值不是“教科書實(shí)現(xiàn)”(torchaudio的話,但我信任他們),而是為L(zhǎng)ibrosa兼容性而提供的;火炬音頻中從一個(gè)切換到另一個(gè)的關(guān)鍵操作是:

 mel_specgram = self.MelSpectrogram(waveform)

    if self.log_mels:

        log_offset = 1e-6

        mel_specgram = torch.log(mel_specgram + log_offset)

    else:

        mel_specgram = self.amplitude_to_DB(mel_specgram)

  • 第三,你會(huì)非常合理地想知道你是否可以強(qiáng)迫librosa正確行動(dòng)。答案是肯定的(或者至少是“它看起來(lái)像它”),直接獲取mel頻譜圖,取它的基本對(duì)數(shù),并使用它,而不是原始樣本,作為librosa mfcc函數(shù)的輸入。有關(guān)詳細(xì)信息,請(qǐng)參閱下面的代碼。

  • 最后,要小心,如果您使用此代碼,請(qǐng)檢查查看不同功能時(shí)發(fā)生的情況。第 0 個(gè)特征仍然具有嚴(yán)重的無(wú)法解釋的偏移,并且較高的特征往往會(huì)彼此遠(yuǎn)離。這可能很簡(jiǎn)單,比如引擎蓋下的不同實(shí)現(xiàn)或略有不同的數(shù)字穩(wěn)定性常數(shù),或者它可能是可以通過(guò)微調(diào)來(lái)修復(fù)的東西,比如選擇填充,或者可能是某個(gè)地方的分貝轉(zhuǎn)換中的引用。我真的不知道。

下面是一些示例代碼:

import librosa

import python_speech_features

import matplotlib.pyplot as plt

from scipy.signal.windows import hann

import torchaudio.transforms

import torch


n_mfcc = 13

n_mels = 40

n_fft = 512 

hop_length = 160

fmin = 0

fmax = None

sr = 16000


melkwargs={"n_fft" : n_fft, "n_mels" : n_mels, "hop_length":hop_length, "f_min" : fmin, "f_max" : fmax}


y, sr = librosa.load(librosa.util.example_audio_file(), sr=sr, duration=5,offset=30)


# Default librosa with db mel scale 

mfcc_lib_db = librosa.feature.mfcc(y=y, sr=sr, n_fft=n_fft,

                                    n_mfcc=n_mfcc, n_mels=n_mels,

                                    hop_length=hop_length,

                                    fmin=fmin, fmax=fmax, htk=False)


# Nearly identical to above

# mfcc_lib_db = librosa.feature.mfcc(S=librosa.power_to_db(S), n_mfcc=n_mfcc, htk=False)


# Modified librosa with log mel scale (helper)

S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=n_mels, fmin=fmin, 

                                    fmax=fmax, hop_length=hop_length)


# Modified librosa with log mel scale

mfcc_lib_log = librosa.feature.mfcc(S=np.log(S+1e-6), n_mfcc=n_mfcc, htk=False)


# Python_speech_features 

mfcc_speech = python_speech_features.mfcc(signal=y, samplerate=sr, winlen=n_fft / sr, winstep=hop_length / sr,

                                          numcep=n_mfcc, nfilt=n_mels, nfft=n_fft, lowfreq=fmin, highfreq=fmax,

                                          preemph=0.0, ceplifter=0, appendEnergy=False, winfunc=hann)


# Torchaudio 'textbook' log mel scale 

mfcc_torch_log = torchaudio.transforms.MFCC(sample_rate=sr, n_mfcc=n_mfcc, 

                                            dct_type=2, norm='ortho', log_mels=True, 

                                            melkwargs=melkwargs)(torch.from_numpy(y))


# Torchaudio 'librosa compatible' default dB mel scale 

mfcc_torch_db = torchaudio.transforms.MFCC(sample_rate=sr, n_mfcc=n_mfcc, 

                                           dct_type=2, norm='ortho', log_mels=False, 

                                           melkwargs=melkwargs)(torch.from_numpy(y))


feature = 1 # <-------- Play with this!!

plt.subplot(2, 1, 1)


plt.plot(mfcc_lib_log.T[:,feature], 'k')

plt.plot(mfcc_lib_db.T[:,feature], 'b')

plt.plot(mfcc_speech[:,feature], 'r')

plt.plot(mfcc_torch_log.T[:,feature], 'c')

plt.plot(mfcc_torch_db.T[:,feature], 'g')

plt.grid()


plt.subplot(2, 2, 3)

plt.plot(mfcc_lib_log.T[:,feature], 'k')

plt.plot(mfcc_torch_log.T[:,feature], 'c')

plt.plot(mfcc_speech[:,feature], 'r')

plt.grid()


plt.subplot(2, 2, 4)

plt.plot(mfcc_lib_db.T[:,feature], 'b')

plt.plot(mfcc_torch_db.T[:,feature], 'g')

plt.grid()

老實(shí)說(shuō),這些實(shí)現(xiàn)都沒(méi)有令人滿意:

  • Python_speech_features采取了一種莫名其妙的奇怪方法,用能量替換第0個(gè)特征,而不是用它來(lái)增強(qiáng),并且沒(méi)有常用的delta實(shí)現(xiàn)。

  • 默認(rèn)情況下,Librosa是非標(biāo)準(zhǔn)的,沒(méi)有警告,并且缺乏一種明顯的方法來(lái)增加能量,但在圖書館的其他地方具有高度勝任的delta函數(shù)。

  • Torchaudio將模擬兩者,也具有多功能的delta功能,但仍然沒(méi)有干凈,明顯的能量獲取方式。

http://img1.sycdn.imooc.com//62fb50d70001fce206350372.jpg

查看完整回答
反對(duì) 回復(fù) 2022-08-16
  • 2 回答
  • 0 關(guān)注
  • 291 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)