Skip to content

Commit

Permalink
Feature extraction loop for audio processing
Browse files Browse the repository at this point in the history
  • Loading branch information
AnanthVivekanand committed Oct 30, 2020
1 parent d3cf258 commit 210d9d3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions audio_preprocessing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@
"features = np.load(\"features.npy\", allow_pickle=True)\n",
"labels = np.load(\"labels.npy\", allow_pickle=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# DONT RUN THIS IF YOU ALREADY LOADED THE NUMPY ARRAYS ^^^^\n",
"\n",
"metadata = pd.read_csv('./UrbanSound8k/metadata/UrbanSound8K.csv')\n",
"features = []\n",
"labels = []\n",
"i = 0\n",
"\n",
"# Iterate through each sound file and extract the features \n",
"for index, row in metadata.iterrows():\n",
" \n",
" i = i +1\n",
" file_name = os.path.join(os.path.abspath('UrbanSound8k/audio/'),'fold'+str(row[\"fold\"])+'/',str(row[\"slice_file_name\"]))\n",
" \n",
" class_label = row[\"class\"]\n",
" print(f'{i}: Processing {file_name}')\n",
" data = extract_features(file_name)\n",
" \n",
" features.append(data)\n",
" labels.append(class_label)\n",
"\n",
"# Convert into a Panda dataframe \n",
"#featuresdf = pd.DataFrame(features, columns=['feature','class_label'])\n",
"#np.save('features.npy', features)\n",
"\n",
"print('Finished feature extraction from ', len(features), ' files')\n",
"\n",
"np.save('features.npy', features)\n",
"np.save('labels.npy', labels)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 210d9d3

Please sign in to comment.