Blog Archive

Monday, September 28, 2015

Music and Sound- Reading note

1) how to derive float from division of two integer in python?

int(var1)/int(var2) will give integer number

var1/float(var2)     will give float number


2) Necessary module:
python and sound:

reading and writing audio file:
scipy.io.wavfile read, write

ploting:
matplotlib: plot, show

array manipulating:
numpy:   arange, max, abs, sum

3)  How to read audio files:

def readAudio(inputFile):
    """
    Input:
        inputFile: the path to the wav file    
    Output:
        The function should return a numpy array that contains all samples of the audio.
    """    
    from scipy.io import wavfile
    import numpy as np
    INT16_FAC = (2**15)-1
    INT32_FAC = (2**31)-1
    INT64_FAC = (2**63)-1
    norm_fact = {'int16':INT16_FAC, 'int32':INT32_FAC, 'int64':INT64_FAC,'float32':1.0,'float64':1.0}
    fs, x = wavfile.read(inputFile)
    x = np.float32(x)/norm_fact[x.dtype.name]


NOTE:
SciPy (pronounced “Sigh Pie”) is an open source Python library used by scientists, analysts, and engineers doing scientific computing and technical computing.


No comments:

Post a Comment