Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
64f62dc
naive Sphinx documentation
bastibe Sep 21, 2014
c48c48a
fix ReST conversion error
bastibe Sep 27, 2014
a02aab4
converted docstrings to numpy style ReST format
bastibe Sep 27, 2014
c32de91
added documentation for class members
bastibe Sep 27, 2014
f0e8ad3
removed incorrect information from README
bastibe Sep 27, 2014
4c1b28d
a few small changes suggested by mgeier
bastibe Oct 16, 2014
38dc864
Move module docstring to the top of the file
mgeier Oct 21, 2014
c75d39a
Move documentation to doc/ subdirectory
mgeier Oct 21, 2014
8c19b5b
Remove superfluous toctree directive
mgeier Oct 21, 2014
2050c27
Change to automodule and use source order
mgeier Oct 21, 2014
705f058
Move property documentation from __init__() to the properties
mgeier Oct 21, 2014
cf11d27
Change display of return type
mgeier Oct 21, 2014
e20c471
Shorter summary of endian-ness
mgeier Oct 21, 2014
2e717a9
Remove names of return values from docs
mgeier Oct 21, 2014
9b52339
Kill open()
mgeier Oct 22, 2014
39f6d87
Re-order functions
mgeier Oct 22, 2014
47a6085
Re-order methods within SoundFile
mgeier Oct 22, 2014
861606c
Use the __init__() docstring as class documentation
mgeier Oct 22, 2014
b557e0a
Add requirements file for Sphinx
mgeier Oct 23, 2014
a89b0b9
Add mock modules to avoid full installation for Sphinx
mgeier Oct 23, 2014
87bed95
Add current and parent path to Sphinx search path
mgeier Oct 23, 2014
e17a018
Remove duplicate parameter documentation
mgeier Oct 24, 2014
9c91a19
Use short form of function/method/class links
mgeier Oct 24, 2014
53aae5a
Change argument order
mgeier Oct 24, 2014
d1c1555
Create docstrings for underscore-prefixed functions
mgeier Oct 24, 2014
0214fb8
Changes to most of the docstrings
mgeier Oct 26, 2014
9f646e1
Use README.rst as long_description in setup.py
mgeier Oct 26, 2014
82596e6
Remove module index and search page
mgeier Oct 27, 2014
855d6cb
Add AIFF to available_formats() example
mgeier Nov 11, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 0 additions & 147 deletions README.md

This file was deleted.

112 changes: 112 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
PySoundFile
===========

PySoundFile is an audio library based on libsndfile, CFFI and Numpy

PySoundFile can read and write sound files. File reading/writing is
supported through `libsndfile <http://www.mega-nerd.com/libsndfile/>`__,
which is a free, cross-platform, open-source library for reading and
writing many different sampled sound file formats that runs on many
platforms including Windows, OS X, and Unix. It is accessed through
`CFFI <http://cffi.readthedocs.org/>`__, which is a foreign function
interface for Python calling C code. CFFI is supported for CPython 2.6+,
3.x and PyPy 2.0+. PySoundFile represents audio data as NumPy arrays.

| PySoundFile is BSD licensed.
| (c) 2013, Bastian Bechtold

Installation
------------

On the Python side, you need to have CFFI and Numpy in order to use
PySoundFile. Additionally, You need the library libsndfile installed on
your computer. On Unix, use your package manager to install libsndfile.
Then just install PySoundFile using pip or ``python setup.py install``.

If you are running Windows, I recommend using
`WinPython <https://code.google.com/p/winpython/>`__ or some similar
distribution. This should set you up with Numpy. However, you also need
CFFI and it's dependency, PyCParser. A good place to get these are the
`Unofficial Windows Binaries for
Python <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`__. Having installed
those, you can download the Windows installers for PySoundFile:

| `PySoundFile-0.5.0.win-amd64-py2.7 <https://github.com/bastibe/PySoundFile/releases/download/0.5.0/PySoundFile-0.5.0.win-amd64-py2.7.exe>`__
| `PySoundFile-0.5.0.win-amd64-py3.3 <https://github.com/bastibe/PySoundFile/releases/download/0.5.0/PySoundFile-0.5.0.win-amd64-py3.3.exe>`__
| `PySoundFile-0.5.0.win32-py2.7 <https://github.com/bastibe/PySoundFile/releases/download/0.5.0/PySoundFile-0.5.0.win32-py2.7.exe>`__
| `PySoundFile-0.5.0.win32-py3.3 <https://github.com/bastibe/PySoundFile/releases/download/0.5.0/PySoundFile-0.5.0.win32-py3.3.exe>`__

Usage
-----

Each SoundFile can either open a sound file on the disk, or a file-like
object (using ``libsndfile``'s `virtual file
interface <http://www.mega-nerd.com/libsndfile/api.html#open_virtual>`__).
Every sound file has a specific samplerate, data format and a set number
of channels.

You can read and write any file that
`libsndfile <http://www.mega-nerd.com/libsndfile/#Features>`__ can
open. This includes Microsoft WAV, OGG, FLAC and Matlab MAT files.

If a file on disk is opened, it is kept open for as long as the
SoundFile object exists and closes automatically when it goes out of
scope. Alternatively, the SoundFile object can be used as a context
manager, which closes the file when it exits.

All data access uses frames as index. A frame is one discrete time-step
in the sound file. Every frame contains as many samples as there are
channels in the file.

Read/Write Functions
~~~~~~~~~~~~~~~~~~~~

Data can be written to the file using ``write()``, or read from the
file using ``read()``.

Here is an example for a program that reads a wave file and copies it
into an ogg-vorbis file:

.. code:: python

import pysoundfile as sf

data, samplerate = sf.read('existing_file.wav')
sf.write(data, 'new_file.ogg', samplerate=samplerate)

Virtual IO
~~~~~~~~~~

If you have an open file-like object, you can use something similar to
this to decode it:

.. code:: python

from pysoundfile import SoundFile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be import pysoundfile as sf

with SoundFile('filename.flac', 'rb') as fObj:
data, samplerate = sf.read(fObj)

Here is an example using an HTTP request:

.. code:: python

from io import BytesIO
import pysoundfile as sf
import requests

fObj = BytesIO()
response = requests.get('http://www.example.com/my.flac', stream=True)
for data in response.iter_content(4096):
if data:
fObj.write(data)
fObj.seek(0)
data, samplerate = sf.read(fObj)

Accessing Text Data
~~~~~~~~~~~~~~~~~~~

In addition to audio data, there are a number of text fields in every
sound file. In particular, you can set a title, a copyright notice, a
software description, the artist name, a comment, a date, the album
name, a license, a tracknumber and a genre. Note however, that not all
of these fields are supported for every file format.
Loading