6

Would someone kindly recommend a command line utility that can play any section of an audio file specified in milliseconds e.g.

player -start-time=0.1234 end-time=5.6789 audio.wav

None of the audio players that I've come across seem to have this functionality. vlc supports start and end times but in seconds only, while Audacity does not appear to have much in the way of command line options.

Olumide
  • 5,397
  • 10
  • 55
  • 104

1 Answers1

11

sox

You can use sox play with the trim effect:

play audio.wav trim START =END

Which in your case would become:

play audio.wav trim 0.1234 =5.6789

Note that the end can also be specified as a length:

play audio.wav trim 0.1234 2

Which starts playing at 0.1234 and plays 2 seconds of the file.

Also note that the offsets can be specified as number of samples by appending an s to the number.

mplayer

mplayer also supports this:

mplayer -ss START -endpos END audio.wav

ffplay from ffmpeg

ffplay uses similar input parameters but doesn't support absolute end times, so some minor arithmetic is needed:

ffplay -ss START -t $(( END - START )) audio.wav
Thor
  • 45,082
  • 11
  • 119
  • 130
  • Thanks. Two quick questions. First, none of the commands you use `sox`. Second, is `play` another program, if so where can I get it? My installation of `sox` does not come with an executable called `play`. PS: if it matters, I'm running WindowsXP. PPS: got it, http://linux.die.net/man/1/sox – Olumide Aug 25 '12 at 14:51
  • `play` is `sox` just under a different name. Command line arguments are treated a little different. To get the equivalent effect call `sox` like this: `sox audio.wav -d trim START =END`. `-d` means the default output device. – Thor Aug 25 '12 at 14:58