Recorder: a simple Java tool with built-in timer for capturing audio streams


Author: Dmitry Nizhegorodov (dmitrynizh@hotmail.com). My other projects and articles



1.   Abstract

Recorder is a simple Java tool that uses Java's sound streaming facilities (Java 1.3+) and is capable of capturing continuous streams of audio in PCM 44.1K, 16Bit, stereo format.

2.   Introduction

I always wanted to capture my favorite audio programs for re-play. One example is KCSM's "Crazy about the Blues" which is a 3hr-long program aired on Friday at 9pm, and I'm not always free to listen or tape it. Most commercial & shareware stream capturing tools have menu-driven interfaces with start & stop buttons; instead I want a tool that I can invoke as a timer. Also, most existing tools do not record very long programs or if they do, it is awkward afterwards, when copying temp files to user selected "Save As" files, which takes excessive time on Windows* platforms when captured stream is 1G byte and more. How hard is to write a tool from scratch? Doing that using low-level sound APIs on Windows* did not appeal to me; luckily, Java 1.3+ offers all necessary ingredients and the demos that Sun provides are a good starting point to come up with a quick homebrew solution.

3.   Downloading it

The tool is distributed in a jar file recorder.jar that you can find here. For those not familiar with Java: jar is a zip file that contains a textual manifest that tells Java runtime about its entry point and other details, and can be easily executed as java -jar <myjar>.

4.   Usage

The tool expects 3 command line arguments - (1) a WAVE file name, (2) time to wait before recording starts, (3) duration of the recording. The arguments are required, I did not bother with defaults. the file is updated on the fly and closed after recording finishes, and thus can be arbitrarily long. When I record 3hrs of stereo, the size of the file is ~ 2G. I discovered some problems closing all the associated resources at the end - stopping the 'lines' and the threads and exiting may cause file corruption; the solution is to wait a few seconds before exiting from the main thread is a hack but it does the job. If you know a better solution, please send me an email.

The format of file name is platform-specific. The time format is HH:MM:SS or HH-MM-SS. I prefer the latter simply because it is emacs-completion-friendly. Never mind if you're not an emacs-user.

Here is an example. Let's capture the input in file test.wav after waiting 10 sec before starting, and then stopping after 20 sec:

 $ java -jar recorder.jar test.wav 00-00-10 00-00-20
 Recording will start on: Sat Dec 06 16:54:33 PST 2003
               finish on: Sat Dec 06 16:54:53 PST 2003
          Temp file name: test.wav
 Recording...

 Stopping...
 Recording stopped.
 Finishing... 5... 4... 3... 2... 1
  
Another example: wait for 3min and then record for 3hrs 5min:

 $ java -jar recorder.jar blues.wav 00-03-00 03-05-00
 Recording will start on: Fri Dec 05 20:58:35 PST 2003
               finish on: Sat Dec 06 00:03:35 PST 2003
          Temp file name: Fri_Dec__5_20-55-35_PST_2003.wav

 Recording...

 ...........................................................
 ...........................................................
 ...........................................................
 ....
 Stopping...
 Recording stopped.
 Finishing... 5... 4... 3... 2... 1
  
The dots on the next line after Recording... represent elapsed 1-min intervals; after 60 mins elapsed a new line is started.

5.   Discussion

Initially, I planned to use exact calendar time as a "start" argument. However, this appeared not very convenient and even error-prone, and hence I use a HH-MM-SS interval instead. Still I may add this capability in the future.

It is possible to specify more than 99hrs of wait or recording time, but watch that the dates printed by the recorder when it starts are correct.

Comments, suggestions, contributions are welcomed!

6.   Sources are free

The tool is distributed freely and "as is". the sources are included in in the jar.


Author: Dmitry Nizhegorodov (dmitrynizh@hotmail.com). My other projects and articles