-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathexample.py
84 lines (59 loc) · 2.35 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
# ================================
# import the gist module
import gist
# ====================== Setting up ===================
# Commented out for now
# Get the sampling frequency
#fs = gist.getSamplingFrequency()
# Set the sampling frequency
#gist.setSamplingFrequency (48000)
# Set the audio frame size that the module expects
#gist.setAudioFrameSize (512)
# ====================== Extracting Features ===================
# This example shows how to get features from a single audio frame
# Create an arbitrary sin wave as an audio frame
audioFrame = np.sin (np.arange((512.)) * np.pi / 180. * 4 )
# Process the audio frame
gist.processFrame (audioFrame)
# Now we extract features and print them out...
# ====================== Core Time Domain Features ===================
print("")
print("--- CORE TIME DOMAIN FEATURES ---")
print("")
print("RMS:", gist.rms())
print("Peak Energy:", gist.peakEnergy())
print("Zero Crossing Rate:", gist.zeroCrossingRate())
print("")
# ====================== Core Frequency Domain Features ===================
print("--- CORE FREQUENCY DOMAIN FEATURES ---")
print("")
print("Spectral Centroid: ", gist.spectralCentroid())
print("Spectral Crest:", gist.spectralCrest())
print("Spectral Flatness:", gist.spectralFlatness())
print("Spectral Rolloff:", gist.spectralRolloff())
print("Spectral Kurtosis:", gist.spectralKurtosis())
print("")
# ========================= Onset Detection Functions =======================
print("--- ONSET DETECTION FUNCTIONS ---")
print("")
print("Energy Difference:", gist.energyDifference())
print("Spectral Difference:", gist.spectralDifference())
print("Spectral Difference (half-wave rectified):", gist.spectralDifferenceHWR())
print("Complex Spectral Difference:", gist.complexSpectralDifference())
print("High Frequency Content:", gist.highFrequencyContent())
print("")
# ========================= Pitch =======================
print("--- PITCH ---")
print("")
print("Pitch:", gist.pitch())
print("")
# ======================= Spectra ========================
print("--- SPECTRA ---")
print("")
magnitudeSpectrum = gist.magnitudeSpectrum()
print("Magnitude Spectrum has", magnitudeSpectrum.size, "samples")
melFrequencySpectrum = gist.melFrequencySpectrum()
print("Mel-Frequency Spectrum has", melFrequencySpectrum.size, "samples")
mfccs = gist.mfccs()
print("MFCCs has", mfccs.size, "samples")