Follow

PAL Script - Spoken Time

This script will speak the time at the time interval required either from the included but commented out options or by including your own option.  The default option plays the time signal every 5 tracks played and if the time is the top of the hour, this is announced with a different message.

The PAL Script is available below to download.

 

{*****************************************

 PAL Script to speak the time through AUX1
 
******************************************}

PAL.loop := true;                   // Loop the script

var Player1 : TPlayer;              // Declare an instance of TPlayer and assign it DeckA
var Player2 : TPlayer = Aux1;       // Declare an instance of TPlayer and assign it Aux1
var ActiveVol, AuxVol1 : integer;   // Declare containers for the current volume levels
var LowVol : integer = 20;          // Set the lower volume limit here
var HighVol : integer = 330;        // Set the high volume level here

var Announcement : TSongInfo;
var FileName : string;              // String variable for the soundbyte file location and name
var SoundByte, SpokenPart : string;
var AMPM : string;                  // Adds the AM or PM section to the soundbyte

var MyTime : DateTime;
var MyHour, MyMin, MySec, MyMSec, MyNow : Integer;
var MyHourStr, MyMinStr, MySecStr, MyMSecStr, MyNowStr : String;

var SBLength : integer;             // Length of the audio soundbyte track in miliseconds
var WaitTime : string;              // Formatted string for the variable wait required

Announcement := TSongInfo.Create;
FileName := 'c:\SpeakTime.mp3';     // Assign the track name and location
Announcement['xfade'] := '&fie=0&foe=0&xf=0';
AMPM := '. A M';                    // Sets AMPM to AM by default

// Select the option you wish to use by removing the '//' from the start of the line required
// Or add your own condition

PAL.WaitForPlayCount(5);            // Wait for (x) number of tracks to play (Default option)
//PAL.WaitForTime('XX:59:55');      // Wait for 5 seconds before the hour
//PAL.WaitForTime('XX:15:00');      // Wait for 15 minutes past the hour
//PAL.WaitForTime('XX:30:00');      // Wait for the bottom of the hour
//PAL.WaitForTime('XX:45:00');      // Wait for 15 minutes to the hour

PAL.LockExecution;                  // Speed up the Script processing

Player1 := ActivePlayer;            // Assigns the Active Player as Player1

if Player1.Status <> 0 then         // Checks the active player status
  Begin
  Player1 := DeckB;
  End;

ActiveVol := Player1.Volume;        // Record the current Active Player Volume
AuxVol1 := Player2.GetVolume;       // Record the Aux1 Player Volume

MyTime := Now;                      // Assigns the current time to MyTime

DecodeTime(MyTime, MyHour, MyMin, MySec, MymSec); //Decodes MyTime into the respective parts

Announcement['filename'] := FileName; // Assigns the spoken audio file location to a song container property

if MyHour > 12 then                 // Converts a 24 hour clock hour to a 12 hour clock hour
  begin
  AMPM := '. P M';                  // Sets AMPM to PM if the hour is greater than 12
  MyHour := MyHour - 12;            // Removes 12 from the hour of the 24-Hour clock
  end;

MyHourStr :=FloatToStr(MyHour);     // Converts the result from a DateTime to String format
MyMinStr :=FloatToStr(MyMin);       // Converts the result from a DateTime to String format

if Length(MyMinStr) = 1 then
  MyMinStr :='0'+MyMinStr;          // Checks for a single digit minute and adds a zero prefix

if MyMin = 0 then
  SoundByte := 'It is. '+MyHourStr+' o clock. precisely'   // Concatenate the sound byte segments
  else
  SoundByte := 'It is precisely. '+MyHourStr+' '+MyMinStr+' '+AMPM;   // Concatenate the sound byte segments

SpokenPart := URLEncode(SoundByte);
WebToFile(FileName,'http://translate.google.com/translate_tts?tl=en&q='+SpokenPart);

if FileExists(FileName) And MyMin <> 0 then  // Checks for the existence of the audio file
  Begin
  Player1.Volume := LowVol;         // Lower the volume of the Active Player
  Player2.QueueSong(Announcement);  // Queue the audio time message
  Player2.Volume := HighVol;        // Raise the volume of the Aux Player (with extra gain)
  Player2.Play;                     // Play the audio time message

  SBLength := player2.duration;
  SBLength := ((SBLength / 1000) + 1);    // Convert the length from miliseconds to seconds
  WaitTime := '+00:00:0'+FloatToStr(SBLength);    // Convert the time to a string
  Delete(WaitTime,10,5);            // Remove the decimal point and remainder
end;

if FileExists(FileName) And MyMin = 0 then   // Checks for the existence of the audio file
  Begin
  Player1.Volume := LowVol;         // Lower the volume of the Active Player
  Player2.QueueSong(Announcement);  // Queue the audio time message
  Player2.Volume := HighVol;        // Raise the volume of the Aux Player (with extra gain)
  Player2.Play;                     // Play the audio time message

  SBLength := player2.duration;
  SBLength := ((SBLength / 1000) + 1);    // Convert the length from miliseconds to seconds
  WaitTime := '+00:00:0'+FloatToStr(SBLength);    // Convert the time to a string
  Delete(WaitTime,10,5);            // Remove the decimal point and remainder
end;

PAL.WaitForTime(WaitTime);          // Wait for the duration of the track to pass
Player1.Volume := ActiveVol;        // Restore the Active Player Volume to the previous level
Player2.Volume := AuxVol1;          // Restore the Aux1 Player Volume to the previous level
DeleteFile(FileName);               // Delete the file

PAL.UnlockExecution;                // Return PAL Script processing to normal speed

Announcement.Free;                  // Release the memory

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

Comments