From: David C. <da...@ar...> - 2006-10-27 09:54:32
|
Hi, I announce the first release of pyaudio, a module to make noise from numpy arrays (read, write and play audio files with numpy arrays). * WHAT FOR ?: The Goal is to give to a numpy/scipy environmenet some basic audio IO facilities (ala sound, wavread, wavwrite of matlab). With pyaudio, you should be able to read and write most common audio files from and to numpy arrays. The underlying IO operations are done using libsndfile from Erik Castro Lopo (http://www.mega-nerd.com/libsndfile/), so he is the one who did the hard work. As libsndfile has support for a vast number of audio files (including wav, aiff, but also htk, ircam, and flac, an open source lossless codec), pyaudio enables the import from and export to a fairly large number of file formats. There is also a really crude player, which uses tempfile to play audio, and which only works for linux-alsa anyway. I intend to add better support at least for linux, and for other platforms if this does not involve too much hassle. So basically, if you are lucky enough to use a recent linux system, pyaudio already gives you the equivalent of wavread, wavwrite and sound. * DOWNLOAD: http://www.ar.media.kyoto-u.ac.jp/members/david/pyaudio.tar.gz * INSTALLATION INSTRUCTIONS: Just untar the package and drop it into scipy/Lib/sandbox, and add the two following lines to scipy/Lib/sandbox/setup.py: # Package to make some noise using numpy config.add_subpackage('pyaudio') (if libsndfile.so is not in /usr/lib, a fortiori if you are a windows user, you should also change set the right location for libsndfile in pyaudio/pysndfile.py, at the line _snd.cdll.LoadLibrary('/usr/lib/libsndfile.so') ) * EXAMPLE USAGE == Reading example == # Reading from '/home/david/blop.flac' from scipy.sandbox.pyaudio import sndfile a = sndfile('/home/david/blop.flac') print a tmp = a.read_frames_float(1024) --> Prints: File : /home/david/blop.flac Sample rate : 44100 Channels : 2 Frames : 9979776 Format : 0x00170002 Sections : 1 Seekable : True Duration : 00:03:46.298 And put into tmp the 1024 first frames (a frame is the equivalent of a sample, but taking into account the number of channels: so 1024 frames gives you 2048 samples here). == Writing example == # Writing to a wavfile: from scipy.sandbox.pyaudio import sndfile import numpy as N noise = N.random.randn((44100)) a = sndfile('/home/david/blop.flac', sfm['SFM_WRITE'], sf_format['SF_FORMAT_WAV'] | sf_format['SF_FORMAT_PCM16'], 1, 44100) a.write_frames(noise, 44100) a.close() -> should gives you a lossless compressed white noise ! This is really a first release, not really tested, not much documentation, I can just say it works for me. I haven't found a good way to emulate enumerations, which libsndfile uses a lot, so I am using dictionaries generated from the library C header to get a relation enum label <=> value. If someone has a better idea, I am open to suggestions ! Cheers, David |
From: David L. G. <Dav...@no...> - 2006-10-27 17:33:46
|
I'm sure some others _might_ regard this as frivolous, so let me just say: "Way Cool"! Thanks! DG David Cournapeau wrote: > Hi, > I announce the first release of pyaudio, a module to make noise from > numpy arrays (read, write and play audio files with numpy arrays). > > * WHAT FOR ?: > > The Goal is to give to a numpy/scipy environmenet some basic audio IO > facilities (ala sound, wavread, wavwrite of matlab). > > With pyaudio, you should be able to read and write most common audio > files from and to numpy arrays. The underlying IO operations are done > using libsndfile from Erik Castro Lopo > (http://www.mega-nerd.com/libsndfile/), so he is the one who did the > hard work. As libsndfile has support for a vast number of audio files > (including wav, aiff, but also htk, ircam, and flac, an open source > lossless codec), pyaudio enables the import from and export to a fairly > large number of file formats. > There is also a really crude player, which uses tempfile to play > audio, and which only works for linux-alsa anyway. I intend to add > better support at least for linux, and for other platforms if this does > not involve too much hassle. > > So basically, if you are lucky enough to use a recent linux system, > pyaudio already gives you the equivalent of wavread, wavwrite and sound. > > * DOWNLOAD: > > http://www.ar.media.kyoto-u.ac.jp/members/david/pyaudio.tar.gz > > * INSTALLATION INSTRUCTIONS: > > Just untar the package and drop it into scipy/Lib/sandbox, and add > the two following lines to scipy/Lib/sandbox/setup.py: > > # Package to make some noise using numpy > config.add_subpackage('pyaudio') > > (if libsndfile.so is not in /usr/lib, a fortiori if you are a windows > user, you should also change set the right location for libsndfile in > pyaudio/pysndfile.py, at the line > _snd.cdll.LoadLibrary('/usr/lib/libsndfile.so') ) > > * EXAMPLE USAGE > > == Reading example == > > # Reading from '/home/david/blop.flac' > from scipy.sandbox.pyaudio import sndfile > > a = sndfile('/home/david/blop.flac') > print a > > tmp = a.read_frames_float(1024) > > --> Prints: > > File : /home/david/blop.flac > Sample rate : 44100 > Channels : 2 > Frames : 9979776 > Format : 0x00170002 > Sections : 1 > Seekable : True > Duration : 00:03:46.298 > > And put into tmp the 1024 first frames (a frame is the equivalent of > a sample, but taking into account the number of channels: so 1024 frames > gives you 2048 samples here). > > == Writing example == > # Writing to a wavfile: > from scipy.sandbox.pyaudio import sndfile > import numpy as N > > noise = N.random.randn((44100)) > a = sndfile('/home/david/blop.flac', sfm['SFM_WRITE'], > sf_format['SF_FORMAT_WAV'] | sf_format['SF_FORMAT_PCM16'], > 1, 44100) > > a.write_frames(noise, 44100) > a.close() > > -> should gives you a lossless compressed white noise ! > > This is really a first release, not really tested, not much > documentation, I can just say it works for me. I haven't found a good > way to emulate enumerations, which libsndfile uses a lot, so I am using > dictionaries generated from the library C header to get a relation enum > label <=> value. If someone has a better idea, I am open to suggestions ! > > Cheers, > > David > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |
From: Fernando P. <fpe...@gm...> - 2006-10-27 18:17:18
|
On 10/27/06, David L. Goldsmith <Dav...@no...> wrote: > I'm sure some others _might_ regard this as frivolous, so let me just > say: "Way Cool"! Thanks! +1, and not frivolous at all. It's /really/ neat to be able to pull in data from standard image formats (say jpeg) into arrays to quickly do numerics on images. Adding similar capabilities to audio signals is, IMHO, a great contribution. So I heartily join the congratulation. Cheers, f |
From: Travis O. <oli...@ie...> - 2006-10-27 18:31:32
|
David Cournapeau wrote: > Hi, > I announce the first release of pyaudio, a module to make noise from > numpy arrays (read, write and play audio files with numpy arrays). > Very nice. Thank you. I'd like to see exactly this kind of thing for video files too. We can get a lot of mileage out of ctypes. By the way. I noticed your setup.py file is missing a .todict() to convert the configuration object into a dictionary that setup(** ) can handle. if __name__ == "__main__": from numpy.distutils.core import setup setup(**configuration(top_path='').todict()) You might also check to see if libsndfile can be imported during the setup phase and then warn the user before installing that they need it. |
From: <pe...@ce...> - 2006-10-27 18:57:28
|
On Fri, 27 Oct 2006, Travis Oliphant wrote: > David Cournapeau wrote: > > Hi, > > I announce the first release of pyaudio, a module to make noise from > > numpy arrays (read, write and play audio files with numpy arrays). > > > > Very nice. Thank you. I'd like to see exactly this kind of thing for > video files too. We can get a lot of mileage out of ctypes. > > By the way. I noticed your setup.py file is missing a .todict() to > convert the configuration object into a dictionary that setup(** ) can > handle. > > if __name__ == "__main__": > from numpy.distutils.core import setup > setup(**configuration(top_path='').todict()) Actually, one should use here setup(configuration=configuration) Pearu |
From: Christopher B. <Chr...@no...> - 2006-10-27 19:11:24
|
> David Cournapeau wrote: >> Hi, >> I announce the first release of pyaudio, a module to make noise from >> numpy arrays (read, write and play audio files with numpy arrays). Does this have anything to do with this pyaudio? http://people.csail.mit.edu/hubert/pyaudio/ -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
From: David C. <da...@ar...> - 2006-10-29 05:01:33
|
Christopher Barker wrote: > > Does this have anything to do with this pyaudio? > > http://people.csail.mit.edu/hubert/pyaudio/ > > -Chris > Not at all. I should have looked for pyaudio as a name on google :) Before coding my small package, I looked at other python bindings for audio, but either they were not cross platform, or not uptodate, or depended on too much external code. I didn't find this one, though. I think using something like portaudio just to be able to play or record data is a bit overkill: those libraries are supposed to be used for audio applications, with all the constraints: real time capabilities, mixing capabilities, being able to list soundcards, etc... My scope is really much simpler: I just want to be able to import audio files as numpy arrays, process them, and to listen to the result; it really just intend to be an equivalent of wavread, wavwrite and sound/soundsc of matlab. libsndfile is the defacto standard on linux (almost all audio applications on linux with IO needs use it), is really high quality, and is available on linux, windows and mac OSX. cheers, David |