@staticmethod
    def open(filename, sampleRate=44100):
        _, ext = os.path.splitext(filename)


        if ext.endswith('mp3') or ext.endswith('m4a'):

            ffmpeg = Popen([
                "ffmpeg",
                "-i", filename,
                "-vn", "-acodec", "pcm_s16le",  # Little Endian 16 bit PCM
                "-ac", "1", "-ar", str(sampleRate),  # -ac = audio channels (1)
                "-f", "s16le", "-"],  # -f wav for WAV file
                stdin=PIPE, stdout=PIPE, stderr=open(os.devnull, "w"))

            rawData = ffmpeg.stdout

            mp3Array = numpy.fromstring(rawData.read(), numpy.int16)
            mp3Array = mp3Array.astype('float32') / 32767.0
            audioFile = mp3Array.view(AudioFile)

            audioFile.sampleRate = sampleRate
            audioFile.channels = 1
            audioFile.format = pyaudio.paFloat32

            return audioFile

        elif ext.endswith('wav'):
            sampleRate, samples = scipy.io.wavfile.read(filename)

            # Convert to float
            samples = samples.astype('float32') / 32767.0

            # Get left channel
            if len(samples.shape) > 1:
                samples = samples[:, 0]

            audioFile = samples.view(AudioFile)
            audioFile.sampleRate = sampleRate
            audioFile.channels = 1
            audioFile.format = pyaudio.paFloat32

            return audioFile
Open a file (WAV or MP3), return instance of this class with data loaded in
dataset/ETHPy150Open jsawruk/pymir/pymir/AudioFile.py/AudioFile.open