diff 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
line wrap: on
line diff
--- a/modules-and-plug-ins/python-module/example.py	Sat Jun 18 10:50:06 2016 +0100
+++ b/modules-and-plug-ins/python-module/example.py	Fri Aug 18 20:07:33 2023 +0200
@@ -1,6 +1,9 @@
 # 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
 
@@ -8,21 +11,21 @@
 audioFilePath = "/path/to/your/audioFile.wav"
 
 # read the audio file
-audioData, fs, enc = wavread(audioFilePath)     # extract audio from 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"
-    data = np.average(data,axis=1)
+    audioData = np.average (audioData, axis = 1)
 
 # ==========================================    
 # Usage A: track beats from audio            
-beats = btrack.trackBeats(audioData)    
+beats = btrack.trackBeats (audioData)    
 
 # ==========================================
 # Usage B: extract the onset detection function
-onsetDF = btrack.calculateOnsetDF(audioData)         
+onsetDF = btrack.calculateOnsetDF (audioData)         
 
 # ==========================================
 # Usage C: track beats from the onset detection function (calculated in Usage B)
-ODFbeats = btrack.trackBeatsFromOnsetDF(onsetDF)
+ODFbeats = btrack.trackBeatsFromOnsetDF (onsetDF)