-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathexample.py
More file actions
31 lines (23 loc) · 1 KB
/
example.py
File metadata and controls
31 lines (23 loc) · 1 KB
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
# need scikits audiolab for reading audio files
from scikits.audiolab import wavread
# import numpy (needed to convert stereo audio to mono)
import numpy as np
# need to import btrack, our beat tracker
import btrack
# set the path to an audio file on your machine
audioFilePath = "/path/to/your/audioFile.wav"
# read the audio file
audioData, fs, enc = wavread (audioFilePath) # extract audio from file
# convert to mono if need be
if (audioData[0].size == 2):
print "converting to mono"
audioData = np.average (audioData, axis = 1)
# ==========================================
# Usage A: detect beats from audio
beats = btrack.detect_beats (audioData)
# ==========================================
# Usage B: extract the onset detection function
odf = btrack.calculate_onset_detection_function (audioData)
# ==========================================
# Usage C: detect beats from the onset detection function (calculated in Usage B)
odf_beats = btrack.detect_beats_from_odf (odf)