#!/usr/bin/perl -w use strict; use Audio::Play::MPG123; use MP3::Info; use Term::ReadKey; use Getopt::Long; my $shuffle; GetOptions( "shuffle" => \$shuffle ); my $DEBUG = 1; my $max_vol = 100; my $VOLUME = 70; my $speech_speed = 3; #a single digit between 0 and 9 my @playlist; if( @ARGV ) { @playlist = @ARGV; } else { say_error( "No playlist given. Please select some songs for me to p +lay!" ); } if( $shuffle ) #Shuffle songs in playlist { #fisher-yates shuffle from Perl Cookbook my $array = \@playlist; my $i; for( $i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i==$j; @$array[$i,$j] = @$array[$j,$i]; } } my $key; my( $this_artist, $last_artist ); my( $this_album, $last_album ); my( $this_song, $last_song ); my( $this_year, $last_year ); ReadMode 3; # Turn off controls keys for( @playlist ) { print "Starting song '$_'\n" if $DEBUG; my $song = MP3::Info->new( $_ ); my $this_artist = $song->artist; my $this_album = $song->album; my $this_song = $song->title; my $this_year = $song->year; my $prev_vol = $VOLUME; set_vol( $max_vol ); print "Doing DJ routine\n" if $DEBUG; open( VOICE, "| festival --pipe" ) or die "$!"; print VOICE "(voice_rab_diphone)"; print VOICE "(Parameter.set 'Duration_Stretch 1.$speech_speed)"; if( $last_song ){ print VOICE "(SayText \"That was $last_artist with the song $last_ +song\")"; my $the_time = get_time(); print VOICE "(SayText \"The time is now $the_time\")"; } print VOICE "(SayText \"Here is $this_song played by $this_artist\ +")"; close VOICE; $last_artist = $this_artist; $last_album = $this_album; $last_song = $this_song; $last_year = $this_year; set_vol( $prev_vol ); print "Running player for this song\n" if $DEBUG; my $player = new Audio::Play::MPG123; $player->load( $_ ); my $stopper = 0; until( $player->state == 0 or $stopper) { unless (not defined ($key = ReadKey(-1))) { if( $key =~ /^\d$/ ) { $key = 10 unless $key; set_vol( $key * 10 ); } elsif( $key eq '.' ) { set_vol( $VOLUME + 1 ); } elsif( $key eq ',' ) { set_vol( $VOLUME - 1 ); } elsif( $key eq ' ' ) { print "Skipping to next song\n" if $DEBUG; $player->stop; $stopper = 1; next; } } $player->poll(1); } } ReadMode 0; # Reset tty mode before exiting sub say_error { my $err_msg = shift or die "No error given: $!"; my $prev_vol = $VOLUME; set_vol( $max_vol ); open( VOICE, "| festival --pipe" ) or die "$!"; print VOICE "(voice_rab_diphone)"; print VOICE "(Parameter.set 'Duration_Stretch 1.$speech_speed)"; print VOICE "(SayText \"$err_msg\")"; close VOICE; set_vol( $prev_vol ); } sub get_time { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime +(time); my $time; if( $min == 0 && $hour == 0 ) { $time = "midnight"; } elsif( $min == 0 && $hour == 12 ) { $time = "noon"; } elsif( $hour < 12 && $min <= 30) { $time = "$min minutes after $hour in the morning"; } elsif( $hour < 12 && $min > 30) { my $bmin = 60 - $min; $hour++; $time = "$bmin minutes before $hour in the morning"; } elsif( $hour == 12 && $min <= 30) { $time = "$min minutes after $hour in the afternoon"; } elsif( $hour == 12 && $min > 30) { my $bmin = 60 - $min; $hour++; $time = "$bmin minutes before $hour in the afternoon"; } elsif( $hour > 12 && $min <= 30) { $hour -= 12; $time = "$min minutes after $hour in the morning"; } elsif( $hour > 12 && $min > 30) { $hour -= 12; my $bmin = 60 - $min; $hour++; $time = "$bmin minutes before $hour in the morning"; } else { $time = "I have no idea what time it is!"; } return $time } sub set_vol { $VOLUME = shift || return; $VOLUME = 100 if $VOLUME >= 100; $VOLUME = 0 if $VOLUME < 0; system( "aumix -v $VOLUME" ); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Compu Kasem (a Cyber-DJ)
by mcstayinskool (Acolyte) on May 10, 2002 at 13:57 UTC | |
Re: Compu Kasem (a Cyber-DJ)
by elwarren (Priest) on May 08, 2002 at 21:10 UTC | |
Re: Compu Kasem (a Cyber-DJ)
by belden (Friar) on May 09, 2002 at 19:49 UTC | |
by elwarren (Priest) on May 09, 2002 at 21:06 UTC | |
Re: Compu Kasem (a Cyber-DJ)
by otterfish (Initiate) on May 15, 2002 at 06:53 UTC | |
by Anonymous Monk on May 30, 2002 at 17:46 UTC | |
by Anonymous Monk on May 30, 2002 at 20:34 UTC | |
by ichimunki (Priest) on May 16, 2002 at 17:26 UTC |