Git Product home page Git Product logo

minimp3py's Introduction

minimp3py

Python bindings for minimp3.

Installation

CFLAGS='-O3 -march=native' pip install https://github.com/f0k/minimp3py/archive/master.zip

The CFLAGS are important to compile with SSE/NEON support if your CPU has it.

Usage

import minimp3py

# query file information
length, channels, sample_rate = minimp3py.probe('somefile.mp3')

# read a full file as a float32 numpy array
wav, sample_rate = minimp3py.read('somefile.mp3')

# read the eleventh second of a 48 kHz stereo file into an existing numpy array
import numpy as np
wav = np.empty((48000, 2), dtype=np.float32)
wav, sample_rate = minimp3py.read('somefile.mp3', start=48000 * 10,
                                  length=48000, out=wav)

# read the eleventh second of the same 48 kHz stereo file from memory
with open('somefile.mp3', 'rb') as f:
    data = f.read()
wav, sample_rate = minimp3py.read(data, start=48000 * 10, length=48000)

# data can be any bytes-like, such as a memory map of an uncompressed .zip file
import zipfile
with zipfile.ZipFile('huge_dataset.zip') as f:
    items = f.NameToInfo
zmap = np.memmap('huge_dataset.zip', mode='r')
zinfo = items['somefile.mp3']
data = zmap[zinfo.header_offset + len(zinfo.FileHeader()):][:zinfo.file_size]
wav, sample_rate = minimp3py.read(data, start=48000 * 10, length=48000)

Status

This is just a quick stab at it, but it is already useable and 2-5 times faster than ffmpeg. In the long run I'd like to add support for reading from a file-like Python object, and an open() call to open an mp3 with seek() and read() methods for streaming in arbitrary-sized chunks.

Why

The existing Python bindings pyminimp3 and pyfastmp3decoder do not work correctly and do not support seeking, respectively.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.