comparison modules-and-plug-ins/python-module/example.py @ 117:ca2d83d29814 tip master

Merge branch 'release/1.0.5'
author Adam Stark <adamstark.uk@gmail.com>
date Fri, 18 Aug 2023 20:07:33 +0200
parents edb071c0cd1f
children
comparison
equal deleted inserted replaced
96:c58f01834337 117:ca2d83d29814
1 # need scikits audiolab for reading audio files 1 # need scikits audiolab for reading audio files
2 from scikits.audiolab import wavread 2 from scikits.audiolab import wavread
3
4 # import numpy (needed to convert stereo audio to mono)
5 import numpy as np
3 6
4 # need to import btrack, our beat tracker 7 # need to import btrack, our beat tracker
5 import btrack 8 import btrack
6 9
7 # set the path to an audio file on your machine 10 # set the path to an audio file on your machine
8 audioFilePath = "/path/to/your/audioFile.wav" 11 audioFilePath = "/path/to/your/audioFile.wav"
9 12
10 # read the audio file 13 # read the audio file
11 audioData, fs, enc = wavread(audioFilePath) # extract audio from file 14 audioData, fs, enc = wavread (audioFilePath) # extract audio from file
12 15
13 # convert to mono if need be 16 # convert to mono if need be
14 if (audioData[0].size == 2): 17 if (audioData[0].size == 2):
15 print "converting to mono" 18 print "converting to mono"
16 data = np.average(data,axis=1) 19 audioData = np.average (audioData, axis = 1)
17 20
18 # ========================================== 21 # ==========================================
19 # Usage A: track beats from audio 22 # Usage A: track beats from audio
20 beats = btrack.trackBeats(audioData) 23 beats = btrack.trackBeats (audioData)
21 24
22 # ========================================== 25 # ==========================================
23 # Usage B: extract the onset detection function 26 # Usage B: extract the onset detection function
24 onsetDF = btrack.calculateOnsetDF(audioData) 27 onsetDF = btrack.calculateOnsetDF (audioData)
25 28
26 # ========================================== 29 # ==========================================
27 # Usage C: track beats from the onset detection function (calculated in Usage B) 30 # Usage C: track beats from the onset detection function (calculated in Usage B)
28 ODFbeats = btrack.trackBeatsFromOnsetDF(onsetDF) 31 ODFbeats = btrack.trackBeatsFromOnsetDF (onsetDF)