-
Notifications
You must be signed in to change notification settings - Fork 39
Using pre trained audio classification models available with this library
There are three models that have been pre-trained and provided in this project under the /models directory. They are as follows.
music genre
: Contains SVM classifier to classify audio into 10 music genres - blues, classical, country, disco, hiphop, jazz, metal, pop, reggae, rock. This classifier was trained using mfcc, gfcc, spectral and chroma features. In order to classify your audio files using this classifier, please follow the audio files structuring guidelines. The following commands in Python can be used to classify your data.
musicVSspeech
: Contains SVM classifier that classifying audio into two possible classes - music and speech. This classifier was trained using mfcc, spectral and chroma features.
musicVSspeechVSbirds
: Contains SVM classifier that classifying audio into three possible classes - music, speech and birds. This classifier was trained using mfcc, spectral and chroma features.
There are three ways to specify the data you want to classify.
- Classifying a single audio file specified by input
file
.
from pyAudioProcessing.run_classification import classify_ms, classify_msb, classify_genre
# musicVSspeech classification
results_music_speech = classify_ms(file="/Users/xyz/Documents/audio.wav")
# musicVSspeechVSbirds classification
results_music_speech_birds = classify_msb(file="/Users/xyz/Documents/audio.wav")
# music genre classification
results_music_genre = classify_genre(file="/Users/xyz/Documents/audio.wav")
- Using
file_names
specifying locations of audios as follows.
# {"audios_1" : [<path to audio>, <path to audio>, ...], "audios_2": [<path to audio>, ...],}
# Examples.
file_names = {
"music" : ["/Users/abc/Documents/opera.wav", "/Users/abc/Downloads/song.wav"],
"birds": [ "/Users/abc/Documents/b1.wav", "/Users/abc/Documents/b2.wav", "/Users/abc/Desktop/birdsound.wav"]
}
file_names = {
"audios" : ["/Users/abc/Documents/opera.wav", "/Users/abc/Downloads/song.wav", "/Users/abc/Documents/b1.wav", "/Users/abc/Documents/b2.wav", "/Users/abc/Desktop/birdsound.wav"]
}
The following commands in Python can be used to classify your data.
from pyAudioProcessing.run_classification import classify_ms, classify_msb, classify_genre
# musicVSspeech classification
results_music_speech = classify_ms(file_names=file_names)
# musicVSspeechVSbirds classification
results_music_speech_birds = classify_msb(file_names=file_names)
# music genre classification
results_music_genre = classify_genre(file_names=file_names)
- Using data structured as specified in structuring guidelines and passing the parent folder path as
folder_path
input.
The following commands in Python can be used to classify your data.
from pyAudioProcessing.run_classification import classify_ms, classify_msb, classify_genre
# musicVSspeech classification
results_music_speech = classify_ms(folder_path="../data")
# musicVSspeechVSbirds classification
results_music_speech_birds = classify_msb(folder_path="../data")
# music genre classification
results_music_genre = classify_genre(folder_path="../data")
Sample results look like
{'../data/music': {'beatles.wav': {'probabilities': [0.8899067858599712, 0.011922234412695229, 0.0981709797273336], 'classes': ['music', 'speech', 'birds']}, ...}