Skip to content

Commit 9e73fd8

Browse files
committed
Add further details for using the project
1 parent fdeae4e commit 9e73fd8

File tree

1 file changed

+85
-19
lines changed

1 file changed

+85
-19
lines changed

README.md

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,73 @@ pip install -r requirements/requirements.txt
3636

3737
Feature options :
3838
You can choose between features `mfcc`, `gfcc`, `spectral`, `chroma` or a comma separated combination of those, example `gfcc,mfcc,spectral,chroma`, to extract from your audio files.
39+
3940
Classifier options :
4041
You can choose between `svm`, `svm_rbf`, `randomforest`, `logisticregression`, `knn`, `gradientboosting` and `extratrees`.
42+
4143
Hyperparameter tuning is included in the code for each using grid search.
4244

45+
### Training and Testing Data structuring
46+
47+
Let's say you have 2 classes that you have training data for (music and speech), and you want to use pyAudioProcessing to train a model using available feature options. Save each class as a directory and all the training audio .wav files under the respective class directories. Example:
48+
49+
```bash
50+
.
51+
├── training_data
52+
├── music
53+
│   ├── music_sample1.wav
54+
│   ├── music_sample2.wav
55+
│   ├── music_sample3.wav
56+
│   ├── music_sample4.wav
57+
├── speech
58+
│   ├── speech_sample1.wav
59+
│   ├── speech_sample2.wav
60+
│   ├── speech_sample3.wav
61+
│   ├── speech_sample4.wav
62+
```
63+
64+
Similarly, for any test data (with known labels) you want to pass through the classifier, structure it similarly as
65+
66+
```bash
67+
.
68+
├── testing_data
69+
├── music
70+
│   ├── music_sample5.wav
71+
│   ├── music_sample6.wav
72+
├── speech
73+
│   ├── speech_sample5.wav
74+
│   ├── speech_sample6.wav
75+
```
76+
If you want to classify audio samples without any known labels, structure the data similarly as
77+
Similarly, for any test data (with known labels) you want to pass through the classifier, structure it as
78+
79+
```bash
80+
.
81+
├── data
82+
├── unknown
83+
│   ├── sample1.wav
84+
│   ├── sample2.wav
85+
```
4386

4487
### Examples
4588

46-
Command line example of using `gfcc,spectral,chroma` feature and `svm` classifier.
89+
Code example of using `gfcc,spectral,chroma` feature and `svm` classifier. Sample data can be found [here](https://github.com/jsingh811/pyAudioProcessing/tree/master/data_samples).
90+
```
91+
from pyAudioProcessing.run_classification import train_and_classify
92+
# Training
93+
train_and_classify("data_samples/training", "train", ["gfcc", "spectral", "chroma"], "svm", "svm_clf")
94+
```
95+
The above logs files analyzed, hyperparameter tuning results for recall, precision and F1 score, along with the final confusion matrix.
96+
97+
To classify audio samples with the classifier you created above,
98+
```
99+
# Classify data
100+
train_and_classify("data_samples/testing", "classify", ["gfcc", "spectral", "chroma"], "svm", "svm_clf")
101+
```
102+
The above logs the filename where the classification results are saved along with the details about testing files and the classifier used.
103+
104+
105+
If you cloned the project via git, the following command line example of doing training and classification with `gfcc,spectral,chroma` features and `svm` classifier can be used as well. Sample data can be found [here](https://github.com/jsingh811/pyAudioProcessing/tree/master/data_samples).
47106

48107
Training:
49108
```
@@ -57,40 +116,47 @@ python pyAudioProcessing/run_classification.py -f "data_samples/testing" -clf "s
57116
Classification results get saved in `classifier_results.json`.
58117

59118

60-
Code example of using `gfcc,spectral,chroma` feature and `svm` classifier.
61-
```
62-
from pyAudioProcessing.run_classification import train_and_classify
63-
# Training
64-
train_and_classify("data_samples/training", "train", ["gfcc", "spectral", "chroma"], "svm", "svm_clf")
65-
# Classify data
66-
train_and_classify("data_samples/testing", "classify", ["gfcc", "spectral", "chroma"], "svm", "svm_clf")
67-
```
119+
68120

69121
## Extracting features from audios
70122

71-
This feature lets the user extract data features calculated on audio files.
123+
This feature lets the user extract aggregated data features calculated per audio file.
72124

73125
### Choices
74126

75127
Feature options :
76-
You can choose between features `mfcc`, `gfcc`, `spectral`, `chroma` or a comma separated combination of those, example `gfcc,mfcc,spectral,chroma`, to extract from your audio files.
77-
To use your own audio files for feature extraction and pass in the directory containing .wav files as the `-d` argument. Please refer to the format of directory `data_samples/testing`.
128+
You can choose between features `mfcc`, `gfcc`, `spectral`, `chroma` or any combination of those to extract from your audio files.
78129

79130
### Examples
80131

81-
Command line example of for `gfcc` and `mfcc` feature extractions.
82-
83-
```
84-
python pyAudioProcessing/extract_features.py -f "data_samples/testing" -feats "gfcc,mfcc"
85-
```
86-
Features extracted get saved in `audio_features.json`.
132+
Code example for performing `gfcc` and `mfcc` feature extraction can be found below. To use your own audio data for feature extraction, pass the path to `get_features` in place of `data_samples/testing`. Please refer to the format of directory `data_samples/testing`.
87133

88-
Code example of performing `gfcc` and `mfcc` feature extraction.
89134
```
90135
from pyAudioProcessing.extract_features import get_features
91136
# Feature extraction
92137
features = get_features("data_samples/testing", ["gfcc", "mfcc"])
138+
# features is a dictionary that will hold data of the following format
139+
"""
140+
{
141+
subdir1_name: {file1_path: {"features": <list>, "feature_names": list}, ...},
142+
subdir2_name: {file1_path: {"features": <list>, "feature_names": list}, ...},
143+
...
144+
}
145+
"""
146+
```
147+
To save features in a json file,
148+
```
149+
from pyAudioProcessing import utils
150+
utils.write_to_json("audio_features.json",features)
151+
```
152+
153+
If you cloned the project via git, the following command line example of for `gfcc` and `mfcc` feature extractions can be used as well. The features argument should be a comma separated string, example `gfcc,mfcc`.
154+
To use your own audio files for feature extraction and pass in the directory containing .wav files as the `-d` argument. Please refer to the format of directory `data_samples/testing`.
155+
156+
```
157+
python pyAudioProcessing/extract_features.py -f "data_samples/testing" -feats "gfcc,mfcc"
93158
```
159+
Features extracted get saved in `audio_features.json`.
94160

95161

96162
## Author

0 commit comments

Comments
 (0)