-- Ecoute Announcer
-- by Aaron Harnly
-- Feel free to modify and/or distribute this script
property Announce_verbally : true
-- if true, the script will speak out loud the name, artist,
-- and album of each new song as it plays in Ecoute.
property idle_time : 5
-- idle_time determines how often, in seconds,
-- the script will check for a new track being played.
-- Shorter intervals will place the announcement closer
-- to the start of songs, but incur a heavier load on the system.
property quot : the ASCII character 34 -- Use "& to add a quotation mark.
-- ***********************************
-- *** Verbal Announcement Settings ***
property verbal_announcement_name : "Now playing [NAME] "
property verbal_announcement_artist : "by [ARTIST], "
property verbal_announcement_album : "from the album [ALBUM]."
-- The verbal announcement is broken into three parts;
-- the track name is always announced, while the artist
-- and album are announced only if they have changed
-- from the previous song.
property volume_fade_step : 3
-- volume_fade step determines how quickly volume fades up & down.
-- if you want the volume to fade up & down faster or slower,
-- adjust this.
property volume_during_announcement : 25
-- volume_during_announcement sets the volume, from 0 to 100,
-- of the music during the spoken announcement.
-- Louder feels more continuous, but makes it harder to
-- understand the voice.
-- ***********************************
global previous_track
global previous_artist
global previous_album
global current_track
global track_name
global track_artist
global track_album
global track_comments
on VerbalAnnounce()
set the_announcement to my parseAnnouncement(verbal_announcement_name)
-- always announce the new track name.
if (track_artist is not equal to previous_artist) then
set the_announcement to the_announcement ¬
& my parseAnnouncement(verbal_announcement_artist)
-- iff the artist has changed, announce the artist
end if
if (track_album is not equal to previous_album) then
set the_announcement to the_announcement ¬
& my parseAnnouncement(verbal_announcement_album)
-- iff the album has changed, announce the album
end if
set the old_volume to my fade_volume(volume_during_announcement)
-- this fades down the volume
-- and simultaneously saves the previous volume.
say the_announcement
-- This it! Finally! We say something!
set the old_volume to my fade_volume(old_volume)
-- now we fade the volume back up to the previous setting.
end VerbalAnnounce
on run
-- The first moment we run the app, do an announcement & update.
-- This will launch Ecoute if it isn't already open,
-- but not start it playing.
-- After that, we loop & check for Ecoute to play a new song.
tell application "Ecoute"
set previous_track to "" -- the current track
set previous_artist to "" -- set to null so that we'll announce it.
set previous_album to "" -- set to null so that we'll announce it.
end tell
my doAnnounce()
end run
on idle
-- this idle handler gets called every few seconds.
-- We want to check if the current song has changed.
-- Note that if Ecoute isn't running, we don't do anything.
set EcouteOpen to false
tell application "Finder"
if (get name of every process) contains "Ecoute" then set EcouteOpen to true
end tell
if (EcouteOpen) then
-- Only check with Ecoute if it is currently running
tell application "Ecoute"
if (the player state is playing) then
if (the previous_track is not equal to the current track) then
my doAnnounce()
end if
end if
end tell
end if
return idle_time
end idle
on doAnnounce()
my update()
if (Announce_verbally) then
my VerbalAnnounce()
end if
my finishupdate()
end doAnnounce
on update()
tell application "Ecoute"
set current_track to the current track
set track_name to the name of the current_track as text
set track_artist to the artist of the current_track as text
set track_album to the album of the current_track as text
set track_comments to the comment of the current_track as text
end tell
if (the track_artist is "Various" or the track_artist is "Various Artists") then
-- on a compilation CD, the artist will be "Various Artists" or "Various"
-- We look to see if the artist of this track might be in the track's comment.
-- If so, we'll report the Comment as the artist.
if (the track_comments is not "") then
set the track_artist to the track_comments
set the track_comments to ""
else
set the track_artist to "Various Artists"
end if
end if
if (the track_album is "") then
set the track_album to "unknown"
end if
if (the track_artist is "") then
set the track_artist to "an unknown artist"
end if
end update
on finishupdate()
set previous_track to current_track
-- We keep track of the last track we announced,
-- so that while idling we can check to see if
-- Ecoute has started playing a new track.
-- We also keep track of the previous artist and album,
-- so we don't repeat those needlessly next time.
set previous_artist to the track_artist
set previous_album to the track_album
end finishupdate
on parseAnnouncement(the_text)
set oldDelims to AppleScript's text item delimiters
-- NAME
set AppleScript's text item delimiters to "[NAME]"
set replaced_text to text items of the_text
set AppleScript's text item delimiters to the track_name
set replaced_text to replaced_text as text
-- ARTIST
set AppleScript's text item delimiters to "[ARTIST]"
set replaced_text to text items of replaced_text
set AppleScript's text item delimiters to the track_artist
set replaced_text to replaced_text as text
--ALBUM
set AppleScript's text item delimiters to "[ALBUM]"
set replaced_text to text items of replaced_text
set AppleScript's text item delimiters to the track_album
set replaced_text to replaced_text as text
set AppleScript's text item delimiters to oldDelims
return replaced_text
end parseAnnouncement
on fade_volume(final_volume)
tell application "Ecoute"
set old_volume to the sound volume -- remember previous volume
set theVol to old_volume
if (final_volume < theVol) then
-- we need to step down the volume to the destination
repeat while (final_volume < theVol)
set sound volume to theVol
set theVol to theVol - volume_fade_step
end repeat
else
-- we need to step up the volume to the destination
repeat while (final_volume > theVol)
set sound volume to theVol
set theVol to theVol + volume_fade_step
end repeat
end if
set sound volume to final_volume -- make it exactly right
end tell
return old_volume -- send back the previous volume
end fade_volume
Connect With Us