【问题标题】:FileNotFoundError: [Errno 2] No such file or directory: 'Audio-Classification/wavefiles/b1'FileNotFoundError:[Errno 2] 没有这样的文件或目录:'Audio-Classification/wavefiles/b1'
【发布时间】:2020-07-22 17:21:43
【问题描述】:

我正在使用深度学习进行音频分类,我正在关注一个视频系列并停留在一个阶段。 以下代码是spyder中编写的代码:

import os

from tqdm import tqdm

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

from scipy.io import wavfile

import python_speech_features

from python_speech_features import mfcc,logfbank

import librosa

def plot_signals(signals):

   fig, axes = plt.subplots(nrows=2, ncols=5, sharex=False,
                         aharey=True, figsize=(20,5))
   fig.suptitle('Time Series', size=16)
   i=0
   for x in range(2):
      for y in range(5):
        axes[x,y].set_title(list(signals.keys())[i])
        axes[x.y].plot(list(signals.value())[i])
        axes[x,y].get_xaxis().set_visible(False)
        axes[x,y].get_yaxis().set_visible(False)
        i+=1

def plot_fft(fft):
    fig, axes = plt.subplots(nrows=2, ncols=5, sharex=False,
                         sharey=True, figsize=(20,5))
    fig.suptitle('Fourier Transform', size=16)
    i = 0
    for x in range(2):
       for y in range(5):
          data=list(fft.value())[i]
          Y, freq = data[0], data[1]
          axes[x,y].set_title(list(fft.keys())[i])
          axes[x.y].plot(freq, Y)
          axes[x,y].get_xaxis().set_visible(False)
          axes[x,y].get_yaxis().set_visible(False)
          i+=1

  def plot_fbank(fbank):
     fig, axes = plt.subplots(nrows=2, ncols=5, sharex=False,
                         sharey=True, figsize=(20,5))
     fig.suptitle('Filter Bank Coefficients', size = 16)
     i = 0
     for x in range(2):
        for y in range(5):
          axes[x,y].set_title(list(fbank.keys())[i])
          axes[x.y].imshow(list(fbank.values())[i],
            cmap='hot', interpolation='nearest')
          axes[x,y].get_xaxis().set_visible(False)
          axes[x,y].get_yaxis().set_visible(False)
          i+=1
        
    def plot_mfccs(mfccs):
         fig, axes = plt.subplots(nrows=2, ncols=5, sharex=False,
                         sharey=True, figsize=(20,5))
        fig.suptitle('Mel Frequency Cepstrum Coefficients', size=16)
        i = 0
       for x in range(2):
         for y in range(5):
           axes[x,y].set_title(list(mfcc.keys())[i])
           axes[x.y].imshow(list(mfccs.values())[i],
            cmap='hot', interpolation='nearest')
           axes[x,y].get_xaxis().set_visible(False)
          axes[x,y].get_yaxis().set_visible(False)
           i+=1

  df = pd.read_csv('cry.csv')
  df.set_index('fname', inplace=True)

     for f in df.index:
      samplerate, signal = wavfile.read('Audio-Classification/wavefiles/' + f)
      df.at[f, 'length'] = signal.shape[0]/samplerate

     classes = list(np.unique(df.label))
     class_dist = df.groupby(['label'])['length'].mean()

它显示的错误:

   runfile('C:/Users/atalp/Desktop/Audio-Classification/eda.py', wdir='C:/Users/atalp/Desktop/Audio-Classification')
   Traceback (most recent call last):

  File "<ipython-input-20-0f3a8250d6ff>", line 1, in <module>
   runfile('C:/Users/atalp/Desktop/Audio-Classification/eda.py', wdir='C:/Users/atalp/Desktop/Audio-Classification')

  File "C:\Users\atalp\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

 File "C:\Users\atalp\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
  exec(compile(f.read(), filename, 'exec'), namespace)

 File "C:/Users/atalp/Desktop/Audio-Classification/eda.py", line 71, in <module>
   samplerate, signal = wavfile.read('Audio-Classification/wavefiles/' + f)

File "C:\Users\atalp\Anaconda3\lib\site-packages\scipy\io\wavfile.py", line 233, in read
  fid = open(filename, 'rb')

FileNotFoundError: [Errno 2] No such file or directory: 'Audio-Classification/wavefiles/b1'

【问题讨论】:

标签: python pandas deep-learning


【解决方案1】:

我觉得只是你的文件目录设置不对。

好像是你的wdir = 'C:/Users/atalp/Desktop/Audio-Classification'

所以读取的文件行应该是wavfile.read('wavefiles/' + f) 而不是wavfile.read('Audio-Classification/wavefiles/' + f)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 2021-08-24
    • 2021-03-07
    • 2015-06-09
    • 2021-04-01
    • 2021-10-15
    • 1970-01-01
    相关资源
    最近更新 更多