In [37]:
from __future__ import print_function

# We'll need numpy for some mathematical operations
import numpy as np
import scipy

# matplotlib for displaying the output
import matplotlib.pyplot as plt
import matplotlib.style as ms
ms.use('seaborn-muted')
%matplotlib inline


# and IPython.display for audio output
import IPython.display


# Librosa for audio
import librosa
# And the display module for visualization
import librosa.display

audio_path = "/Users/lineplus/Desktop/project/MusicAnalyzer/audio/Drum1.mp3"
audio_path2 = "/Users/lineplus/Desktop/project/MusicAnalyzer/audio/Odesza_Above_The_Middle.mp3"
y, sr = librosa.load( audio_path, sr=44100 )
y2, sr2 = librosa.load( audio_path2, sr=44100 )

#IPython.display.Audio(data=y, rate=sr)
print( y )
print( len( y ) )
print( len( y2 ) )

print( sr )
print( sr2 )

print( scipy.spatial.distance.cosine( y, y2[0:171648] ) )


[ 0.  0.  0. ...,  0.  0.  0.]
171648
8083008
44100
44100
1.00176480616

In [5]:
# 3. Run the default beat tracker
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

# 4. Convert the frame indices of beat events into timestamps
beat_times = librosa.frames_to_time(beat_frames, sr=sr)

print('Saving output to beat_times.csv')
librosa.output.times_csv('/Users/lineplus/Desktop/project/MusicAnalyzer/audio/result.csv', beat_times)


Estimated tempo: 99.38 beats per minute
Saving output to beat_times.csv

In [8]:
print( tempo )
print( beat_frames )
print( beat_times )


99.3840144231
[ 12  38  64  95 121]
[ 0.27863946  0.88235828  1.4860771   2.20589569  2.80961451]

In [21]:
{frame_arr = librosa.util.frame(y, frame_length=2048, hop_length=512)
frame_arr2 = librosa.util.frame(y2, frame_length=2048, hop_length=512)
print( frame_arr )
print( frame_arr2 )

print( len( frame_arr[0] ) )
print( len( frame_arr2[0] ) )

print( len( frame_arr ) )
print( len( frame_arr2 ) )}


[[ 0.         -0.90861386  0.00773705 ..., -0.14220695  0.24075744
  -0.08692633]
 [ 0.         -0.87283039  0.0442284  ..., -0.10004218  0.23656647
  -0.09058234]
 [ 0.         -0.89167589  0.04157569 ..., -0.09503061  0.22459549
  -0.11358088]
 ..., 
 [-0.02395119  0.002145   -0.00423921 ..., -0.04312833  0.01478363  0.        ]
 [-0.0163303   0.00313669 -0.01180221 ..., -0.03618175  0.00881893  0.        ]
 [-0.0230791   0.00459595 -0.00822684 ..., -0.05059324  0.00875308  0.        ]]
[[  5.89917436e-05  -1.78596703e-04   9.54093132e-03 ...,   7.08066409e-06
   -2.89536711e-05   2.69479500e-07]
 [ -4.36029695e-05  -9.25666303e-04  -4.81339113e-04 ...,   1.13831420e-05
   -3.22506967e-05  -5.60235307e-08]
 [ -4.41918382e-05   1.10449665e-03  -6.86202710e-03 ...,  -1.06570906e-06
   -2.60917532e-05   1.07385965e-07]
 ..., 
 [  3.12932934e-05  -7.87355006e-03   1.27840792e-06 ...,   9.56925983e-10
   -4.10827766e-07   5.62528800e-12]
 [ -4.36971197e-03  -1.99687518e-02   3.79914860e-03 ...,  -1.44044754e-09
    2.90951931e-07  -2.46683468e-12]
 [ -5.51284105e-03  -1.95681173e-02   2.98191258e-03 ...,   2.01454164e-09
   -2.11024556e-07   9.38451573e-13]]
164
7890
2048
2048

In [17]:
librosa.display.waveplot( y )


Out[17]:
<matplotlib.collections.PolyCollection at 0x10e2bf9e8>

In [20]:
librosa.display.waveplot( y2 )


Out[20]:
<matplotlib.collections.PolyCollection at 0x1115cd9b0>

In [ ]:
sim = scipy.spatial.distance.cosine( frame_arr[0], frame_arr2[0] )
print( sim )