Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Command line audio players for Mac OS X

For information on how to install MacPorts see here and here.
# qtplay & mpg123

export PATH="/opt/local/bin:/opt/local/lib:/opt/local/include:/opt/local/man:${PATH}"
alias port=/opt/local/bin/port

port list | grep -i audio

port info qtplay 
port info mpg123

/usr/bin/sudo port -c install qtplay
/usr/bin/sudo port -c install mpg123

mpg123 file.MP3

qtplay file.MP3
qtplay 'http://file.mp3'
qtplay 'http://file.mov'     # http://www.apple.com/trailers/


#-----------------------------------------


# play, http://www.hieper.nl/html/play.html

export PATH="/usr/local/bin:${PATH}"

# create /usr/local/bin
/usr/bin/sudo /bin/mkdir -p /usr/local/bin
/usr/bin/sudo /usr/sbin/chown root:wheel /usr/local /usr/local/bin
/usr/bin/sudo /bin/chmod 0755 /usr/local /usr/local/bin

cd ~/Desktop
curl -L -O http://www.hieper.nl/downloads/play.dmg
hdiutil mount ~/Desktop/play.dmg
open -a Safari '/Volumes/play 1.3/readme.html'
/usr/bin/sudo /bin/cp -i '/Volumes/play 1.3/play' /usr/local/bin
ls -l /usr/local/bin/play
hdiutil unmount '/Volumes/play 1.3'

play ~/Music/Winterreise/Gute\ Nacht.mp3

# listen to the first 10 seconds of each Schubert song on your computer
mdfind "kMDItemComposer == Schubert" | play -vt 10


#-------------------------------------------------------------


# afplay
# compile & install afplay and related command line audio tools (Mac OS X 10.4.11)
# requires Xcode, http://developer.apple.com/tools/xcode/index.html

ls -1 /usr/bin/af*     # Mac OS X 10.5
ls -1 /usr/bin/au* 

# Mac OS X 10.4
open /Developer/Examples/CoreAudio/Services/AudioFileTools/AudioFileTools.xcodeproj
# ... then just press "Build"

ls -l /Developer/Examples/CoreAudio/Services/AudioFileTools/build/Development-Panther/* | nl
ls -1 /Developer/Examples/CoreAudio/Services/AudioFileTools/build/Development-Panther/* | nl


#/usr/bin/find /Developer/Examples/CoreAudio/Services/AudioFileTools/build/Development-Panther -mindepth 1 | \
#     /usr/bin/xargs -I '{}' /usr/bin/sudo /bin/cp -i '{}' /usr/local/bin

/bin/ls -1 /Developer/Examples/CoreAudio/Services/AudioFileTools/build/Development-Panther/* | \
     /usr/bin/xargs -I '{}' /usr/bin/sudo /bin/cp -i '{}' /usr/local/bin

ls -l /usr/local/bin/af*
ls -l /usr/local/bin/au*

afconvert
afinfo
afinterleave
afplay
afrecord
auprocess
auprofile


# background music
# cf. http://codesnippets.joyent.com/posts/show/1508
/usr/bin/screen -d -m afplay "/path/to/file.MP3"

kill -HUP $$
kill -HUP $PPID
killall -HUP Terminal


apropos audio
apropos sound

# set global Mac OS X sound output volume
# see http://osxutils.sourceforge.net
man setvolume   
setvolume 50

Changing the bell sound of Terminal.app

# you may also copy your own *.aiff file to /System/Library/Sounds ...
locate *.aif
locate *.aiff
open -a Finder /System/Library/Sounds

# select a file in ...
locate *Sound.prefPane
open /System/Library/PreferencePanes/Sound.prefPane

Play sound for certain events in IRSSI

Perl script to allow sounds to be played for different events in IRSSI

Just keep adding handlers to IRSSI's pools pointing to different functions for different events or whatever you want.

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
        authors     => 'Chrelad',
        contact     => 'blah@blah.blah',
        name        => 'alert',
        description => 'Play sounds for different events in IRSSI.',
        url         => 'http://google.com',
        license     => 'GNU General Public License',
        changed     => '$Date: 2007-02-07 12:00:00 +0100 (Thu, 7 Feb 2008) $'
);

#--------------------------------------------------------------------
# Created by Chrelad
# Feb 7, 2008
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# The sound playing function for public message
#--------------------------------------------------------------------

sub pub_msg {
        my ($server,$msg,$nick,$address,$target) = @_;
        `mplayer -quiet ~/file.mp3 > /dev/null`;
}

#--------------------------------------------------------------------
# Irssi::signal_add_last / Irssi::command_bind
#--------------------------------------------------------------------

Irssi::signal_add_last("message public", "pub_msg");
#- end