![](/img/trans.png)
[英]OS Error occurred when reading all the jpeg image files in a folder by using Python language in Jupyter Notebook
[英]Plot spectograms for all .wav files in a folder using python (in jupyter notebook)
我有以下代碼為特定文件創建頻譜圖,非常簡單。 我想發現的是,如果 plot 有一個文件夾內所有文件的頻譜圖,而無需復制粘貼頻譜圖的代碼行並更改每個文件中的音頻文件的名稱(我知道 glob,但我不能在這里應用)。
#import the pyplot and wavfile modules
import matplotlib.pyplot as plt
from scipy.io import wavfile
# Read the wav file (mono)
samplingFrequency, signalData = wavfile.read('sounds/wams20_hat1.wav')
# Plot the signal read from wav file
plt.figure(figsize=(5,5))
plt.title('Spectrogram')
plt.specgram(signalData,Fs=samplingFrequency)
plt.xlabel('Time')
plt.ylabel('Frequency')
plt.show()
在文件夾中的聲音/我有一個 100.wav 文件,所以我試圖找到一種“生態”方式來實現 this.wav 文件的 100 個頻譜圖,並且代碼行數可能更少。 希望這對你來說很清楚
制作一個 function ,它采用要加載的音頻的路徑,並返回一個 matplotlib 圖。 然后為目錄中的每個文件循環調用它(您可以使用glob.glob
或os.listdir
獲得)。
function 應該使用fig, ax = plt.subplots(1, figsize=(10,10))
明確地創建 matplotlib 圖和軸。 然后將頻譜圖渲染到其中。 使用librosa.load
獲取音頻和librosa.display.specshow(ax=ax)
比直接使用 scipy/matplotlib 好一點。 librosa 網頁
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.