7

Is there a mature library that could enable audio input and output and work within Haskell? (A nice wrapper is fine, of course.)

I'm looking for something that can easily capture microphone input and, perhaps, play various audio files as well.

genpfault
  • 51,148
  • 11
  • 85
  • 139
new guy
  • 73
  • 3
  • 1
    I have an unreleased pipes-based wrapper for PortAudio (a cross-platform audio library) that I could finish up, polish and release. If the suggestions given by others leave you with the feeling that something like this is needed in the ecosystem, let me know, and I'll try to get that done soon. – gspr Nov 21 '14 at 11:15
  • Oh, heh, I only now realized this question is really old and that it just resurfaced due to some guy adding a new answer. – gspr Nov 21 '14 at 16:43

4 Answers4

5

easily capture microphone input and, perhaps, play various audio files as well..

It will strongly depend on your OS platform: there are standard C libraries for this functionality on each OS, and you'll be looking for Haskell bindings to them (e.g. PulseAudio, etc). Look in the Sound category on Hackage:

E.g. HSndFile for audio file writing, http://hackage.haskell.org/package/HSoundFile

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
4

the module pulse-simple exposes bindings to capture sound from the microphone, see the second example at the top of the page;
https://hackage.haskell.org/package/pulse-simple-0.1.13/docs/Sound-Pulse-Simple.html
pulse audio libraries required by cabal are obtainable via cygwin (search "pulse" in the cygwin installer).

there is a also binding to sox, which looks promising. https://hackage.haskell.org/package/sox

im sure there are other api wrappers to be found in hackage sound category.

for linux there is a binding to jack, has "unix" as a dependency, it WILL NOT build on windows...

error
  • 519
  • 4
  • 5
  • audacity is built on wxWindows and ffmpeg, both of these are ported to haskell; haskell.org/haskellwiki/WxHaskell, hackage.haskell.org/package/ffmpeg-light – error Nov 22 '14 at 19:54
  • The usefulness of `sox` never seizes to amaze me! – Vorac Feb 25 '17 at 12:41
1

Just in case you're not familiar with hackage: http://hackage.haskell.org/packages/archive/pkg-list.html

It looks like there is some audio-related stuff there. Not sure if there is anything that will meet your needs. But most "mature" haskell libraries will be there.

jberryman
  • 16,334
  • 5
  • 42
  • 83
1

You can do it with OpenAL and ALUT. I managed to install both on Windows 8, although it wasn't exactly effortless; ALUT requires the underlying C library to be compiled manually into a DLL.

Installing OpenAL - on the other hand - is as simple as downloading the SDK and typing cabal install OpenAL in the command prompt.

With ALUT, you can create OpenAL buffers from audio files (including WAV) and memory views.

I found an example of recording and audio playback here. It should be fairly straightforward to adapt the code to your needs.

Let me know if I left something out and I'll try to elaborate.

SwiftsNamesake
  • 1,540
  • 2
  • 11
  • 25