Changeset 1e4d90f for python/demos


Ignore:
Timestamp:
May 10, 2016, 10:08:06 PM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
0c6e3b0
Parents:
8fb567c
Message:

python/demos/demo_reading_speed.py: disable other packages by default

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_reading_speed.py

    r8fb567c r1e4d90f  
    66Compare the speed of several methods for reading and loading a sound file.
    77
    8 This file depends on the following packages:
     8Optionally, this file can make use of the following packages:
    99
    1010    - audioread     https://github.com/beetbox/audioread
     11    - scipy         https://scipy.org
    1112    - librosa       https://github.com/bmcfee/librosa
    1213    - pydub         https://github.com/jiaaro/pydub
    1314
     15Uncomment the function names below and send us your speed results!
     16
    1417"""
    1518
     19
     20test_functions = [
     21            "read_file_aubio",
     22            "load_file_aubio",
     23            #"load_file_scipy",
     24            #"load_file_scipy_mmap",
     25            #"read_file_audioread",
     26            #"load_file_librosa",
     27            #"read_file_pydub",
     28            #"load_file_pydub",
     29            ]
     30
     31
    1632import numpy as np
    17 import aubio
    18 """
    19 import audioread
    20 import librosa
    21 import scipy.io.wavfile
    22 from pydub import AudioSegment
    23 """
    2433
    2534def read_file_audioread(filename):
     35    import audioread
    2636    # taken from librosa.util.utils
    2737    def convert_buffer_to_float(buf, n_bytes = 2, dtype = np.float32):
     
    4353
    4454def load_file_librosa(filename):
     55    import librosa
    4556    y, sr = librosa.load(filename, sr = None)
    4657    #print y.mean(), y.shape
     
    4859
    4960def load_file_scipy(filename):
     61    import scipy.io.wavfile
    5062    sr, y = scipy.io.wavfile.read(filename)
    5163    y = y.astype('float32') / 32767
     
    5466
    5567def load_file_scipy_mmap(filename):
     68    import scipy.io.wavfile
    5669    sr, y = scipy.io.wavfile.read(filename, mmap = True)
    5770    #print y.mean(), y.shape
     
    5972
    6073def read_file_pydub(filename):
     74    from pydub import AudioSegment
    6175    song = AudioSegment.from_file(filename)
    6276    song.get_array_of_samples()
     
    6478
    6579def load_file_pydub(filename):
     80    from pydub import AudioSegment
    6681    song = AudioSegment.from_file(filename)
    6782    y = np.asarray(song.get_array_of_samples(), dtype = 'float32')
     
    7085
    7186def read_file_aubio(filename):
     87    import aubio
    7288    f = aubio.source(filename, hop_size = 1024)
    7389    total_frames = 0
     
    7995
    8096def load_file_aubio(filename):
     97    import aubio
    8198    f = aubio.source(filename, hop_size = 1024)
    8299    y = np.zeros(f.duration, dtype = aubio.float_type)
     
    95112    for i in range(10):
    96113        start = time.time()
    97         total_frames, samplerate = function(filename)
     114        try:
     115            total_frames, samplerate = function(filename)
     116        except ImportError as e:
     117            print ("error: failed importing {:s}".format(e))
     118            return
    98119        elapsed = time.time() - start
    99120        #print ("{:5f} ".format(elapsed)),
    100121        times.append(elapsed)
     122
    101123    #print
    102124    times = np.array(times)
     
    112134    filename = sys.argv[1]
    113135
    114     functions = [
    115             read_file_aubio,
    116             load_file_aubio,
    117             #load_file_scipy,
    118             #load_file_scipy_mmap,
    119             #read_file_audioread,
    120             #load_file_librosa,
    121             #read_file_pydub,
    122             #load_file_pydub,
    123             ]
    124 
    125     for f in functions:
    126         test_speed(f, filename)
     136    for f in test_functions:
     137        test_speed(eval(f), filename)
Note: See TracChangeset for help on using the changeset viewer.