Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have audio being feed to the line in jack for my iMic USB Audio device. I have LAME & Vorbis OGG Tools installed using MacPorts. How do I directly record the line in jack using command line software? I know in Linux there is the program arecord, but what do I use in Mac OS X 10.6 to accomplish this? Is there a way with LAME or OGGENC using raw options?

I'm trying to put together a BASH script to record then forward the audio file and I just need to know how to grab the line in audio to save to a file so I can use another program to auto forward it.

share|improve this question

The problem turns out to be alot harder than it should be.

Normally I would recommend SOX, but I ran into an issue getting it to record audio: http://stackoverflow.com/questions/5845286/sox-recording-on-osx-not-working

It's pretty easy to come up with a simple python script, but due to a bug in the wave module it can't be used in a pipe: http://www.mail-archive.com/python-bugs-list@python.org/msg43196.html

Ecasound is another common program I have used on Linux/FreeBSD, but it doesn't support coreaudio on OSX and can't be used for recording.

At the end of the day the best I have found is a 2 stage process where I record the audio with one script and then convert to mp3 with lame.

Here's a simple python script. Adjust the INDEX to be the appropriate device index from the system preferences list:

    #!/usr/bin/env python2.5

    import sys
    import pyaudio
    import wave

    FILENAME = 'recording.wav'
    INDEX = 0
    FORMAT = pyaudio.paInt16
    CHANNELS = 2
    RATE = 48000
    INPUT_BLOCK_TIME = 0.05
    INPUT_FRAMES_PER_BLOCK = int(RATE*INPUT_BLOCK_TIME)
    CHUNK = 1024

    p = pyaudio.PyAudio()
    stream = p.open(
        format = FORMAT,
        channels = CHANNELS,
        rate = RATE,
        input = True,
        frames_per_buffer = CHUNK,
        input_device_index = INDEX)

    wf = wave.open(FILENAME, 'wb')
    wf.setnchannels(CHANNELS)
    wf.setsampwidth(p.get_sample_size(FORMAT))
    wf.setframerate(RATE)
    sys.stdout.flush()

    while True:
        try:
            wf.writeframes(stream.read(CHUNK))
            sys.stderr.write("#")
            # sys.stdout.flush()
        except IOError:
            sys.stderr.write('X')

    f.close()
    stream.close()
    p.terminate()
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .