• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Noob help! syntax error :(

jhp0510

New Coder
Hi I am new to python and i am trying to write a program that would classify an audio file.
My data set is in google drive and I am writing my code in google colab.
All of the audio files (.wav) which I want to analyze or stored in my google drive under folder name "wavdata"

Python:
from google.colab import drive
drive.mount("/content/drive")
Python:
DATA_DIR = '/content/drive/My Drive.wavdata/'

Python:
for fname in os.listdir(DATA_DIR):
    try:
        if '.wav' not in fname or 'dima' in fname:
            continue
        struct = fname.split('_')
        digit = struct[0]
        patient = struct[1]
        wav, sr = librosa.load(DATA_DIR + fname)
        padded_x = pad1d(wav, 30000)
        spectrogram = np.abs(librosa.stft(wav))

        mel_spectrogram = librosa.feature.melspectrogram(wav)

        mfcc = librosa.feature.mfcc(wav)
    
        if patient == test_patient:
          test_x.append(padded_x)
          test_spectrograms.append(spectrogram)
          test_mel_spectrograms.append(mel_spectrogram)
          test_mfccs.append(mfcc)
          test_y.append(digit)
        else:
          train_x.append(padded_x)
          train_spectrograms.append(spectrogram)
          train_mel_spectrograms.append(mel_spectrogram)
          train_mfccs.append(mfcc)
          train_y.append(digit)   
    except Exception as e:
        print(fname,e)
        raise


1) The first problem i have is :
for fname in os.listdir(DATA_DIR):
-- this keeps getting me error.

2) Second problem i have is:
try : --> syntax error.

Could someone please help me?

Thank you!
 
Hi @jhp0510

I'm not a Python expert, but maybe I could generally help. What is the specific text of the error you are facing? And at what line?

For what I can tell right away is that os.listdir(DATA_DIR) has to be an array, otherwise it should report an error.
 
Last edited:
Top Bottom