PySoundFile and Python 3.4 on Ubuntu 14.04

In a previous post, Installing PySoundFile on Ubuntu 14.04, I went over installing PySoundFile on Ubuntu 14.04 using the default version of Python– that’s version 2.7.6. In this post I’ll cover the use of Python 3.4 in a virtual environment– the goal here, at least in the long run, is to write audio processing (dsp) code in Python that is version 2- and 3-compatible.

Dependencies

To start, the previous post should be consulted to make sure that the Ubuntu-specific requirements are fulfilled. If you’ve already setup PySoundFile for Python 2.7.6 as described in that post you are off to a good start, if not read through all of the sudo apt-get install commands to see if you need to install any libraries, compilers or other packages. Also, make sure that you have python3-dev installed using

$ sudo apt-get install python3-dev

virtualenv

When setting up PySoundFile for Python 2.7.6, we called the virtual environment sounds, so let’s call this environment sounds3. To setup the environment use:

$ mkvirtualenv sounds3 -p /usr/bin/python3

This should create the environment, reflected by a change in prompt to something similar to (sounds3)$. Try the following to make sure that the basics are setup:

(sounds3)$ python --version
Python 3.4.0
(sounds3)$ pip list
pip (1.5.6)
setuptools (3.6)

PySoundFile

Next, we install PySoundFile using pip (this will download a fair number of packages and do lots of compiling–mainly numpy– so, be patient):

(sounds3)$ pip install PySoundFile

Now, if we list the packages in our virtual environment we get:

(sounds3)$ pip list
cffi (1.1.2)
numpy (1.9.2)
pip (1.5.6)
pycparser (2.14)
PySoundFile (0.7.0)
setuptools (3.6)

Finally, let’s do the same test we did for the Python 2.7.6 install. First, test the import and version

from __future__ import print_function
import soundfile as sf

print("PySoundFile version: {}".format(sf.__version__))
PySoundFile version: 0.7.0

then, print out the supported audio formats:

for key, val in sf.available_formats().items():
    print("{:5s} -- desc: {}".format(key, val))
IRCAM -- desc: SF (Berkeley/IRCAM/CARL)
WAV   -- desc: WAV (Microsoft)
AU    -- desc: AU (Sun/NeXT)
W64   -- desc: W64 (SoundFoundry WAVE 64)
CAF   -- desc: CAF (Apple Core Audio File)
SD2   -- desc: SD2 (Sound Designer II)
WVE   -- desc: WVE (Psion Series 3)
AVR   -- desc: AVR (Audio Visual Research)
SDS   -- desc: SDS (Midi Sample Dump Standard)
RAW   -- desc: RAW (header-less)
WAVEX -- desc: WAVEX (Microsoft)
HTK   -- desc: HTK (HMM Tool Kit)
RF64  -- desc: RF64 (RIFF 64)
SVX   -- desc: IFF (Amiga IFF/SVX8/SV16)
MPC2K -- desc: MPC (Akai MPC 2k)
MAT5  -- desc: MAT5 (GNU Octave 2.1 / Matlab 5.0)
FLAC  -- desc: FLAC (FLAC Lossless Audio Codec)
NIST  -- desc: WAV (NIST Sphere)
OGG   -- desc: OGG (OGG Container format)
MAT4  -- desc: MAT4 (GNU Octave 2.0 / Matlab 4.2)
VOC   -- desc: VOC (Creative Labs)
PAF   -- desc: PAF (Ensoniq PARIS)
PVF   -- desc: PVF (Portable Voice Format)
AIFF  -- desc: AIFF (Apple/SGI)
XI    -- desc: XI (FastTracker 2)

Okay, that’s it. For more information checkout:

As always questions, comments, and corrections are welcome.

Tags

api [1]   arduino [1]   audio [2]   audio features [1]   babel [1]   Bayesian [7]   Beta [1]   blog setup [1]   bootstrap [1]   bottleneck [1]   c++ [1]   caret [1]   cmpy [1]   conditional probability [6]   coursera [1]   coursera intro to data science [3]   css [1]   cython [1]   d3 [2]   decision trees [2]   diy [1]   dropbox [1]   dsp [1]   e1071 [1]   essentia [1]   garmin [1]   geojson [1]   ggplot2 [1]   gis [2]   git [1]   gnuplot [1]   graphs [1]   html5 [1]   igraph [1]   ipython [1]   javascript [7]   joint probability [6]   json [1]   LaTeX [2]   LDA [1]   Lea [2]   machine learning [3]   marginal probability [6]   matplotlib [1]   meteor [2]   mir [1]   MongoDB [3]   music [2]   my python setup [5]   my ubuntu setup [10]   mysql [3]   networks [1]   networkx [1]   nodejs [5]   npm [3]   numexpr [1]   numpy [1]   octave [1]   Open Oakland [2]   openpyxl [1]   pandas [3]   patsy [1]   pip [2]   pweave [1]   pygraphviz [1]   pymc [1]   PySoundFile [2]   python [15]   Python [1]   python 2.7 [5]   python 3.4 [2]   pyyaml [1]   qgis [1]   R [1]   randomForest [1]   restview [1]   resume [1]   rpart [1]   running [1]   scikit-learn [3]   scipy [1]   screen [1]   server setup [1]   shapefile [1]   social networks [1]   Socrata [1]   sound [2]   sphinx [1]   sql [4]   sqlite3 [1]   ssh [1]   ssh keys [1]   statsmodels [1]   supervised learning [2]   sympy [1]   tableau [1]   tinkerer [2]   topic models [1]   tree [1]   ubuntu 14.04 [13]   Ubuntu 14.04 [3]   ubuntu 16.04 [4]   vim [2]   virtualbox [1]   virtualenv [4]   virtualenvwrapper [3]   VPS [1]   vundle [1]   webpack [1]   yaml [1]