PAL Script - Hourly Time Signal (The Pips) With Spoken Time

This PAL Script will play the pips at the top of the hour followed by the spoken hour, e.g. "It is precisely 8 o'clock."  You should download the time signal track at the bottom of this document, add it to SAM Broadcaster in its own 'TimeSignal' playlist or category and run the script.  The PAL Script is also available to download from the bottom of this page.

 Note: This script used Google Translate to generate the audio however, Google have changed the way their system works which means there will be no audio.  This script remains available as a guide to implementing this type of feature and in case anyone finds a comparable service to replace Google Translate.


 PAL Script to play the BBC Time Signal (pips) at 5 seconds to the hour through AUX1
 and follow up with a spoken announcement of the hour through AUX2

PAL.loop := true;                   // Loop the script to ensure the time signal is played at every hour

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 Player3 : TPlayer = Aux2;       // Declare an instance of TPlayer and assign it Aux2
var ActiveVol, AuxVol1, AuxVol2 : integer;    // Declare containers for the current volume levels
var TimeSignal : TSongInfo;         // Create a container for the time signal track
var LowVol : integer = 20;          // Set the lower volume limit here
var SignalVol : integer = 330;      // Set the volume level for the time signal parts

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 milliseconds
var WaitTime : string;              // Formatted string for the variable wait required
Announcement := TSongInfo.Create;
FileName := 'c:\SpokenTime.mp3';
Announcement['xfade'] := '&fie=0&foe=0&xf=0';
AMPM := '. A, M';                   // Sets AMPM to AM by default

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

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

TimeSignal := Cat['TimeSignal'].ChooseSong(smLRP, noRules);   // Assign the time signal to the TimeSignal container

ActiveVol := Player1.Volume;        // Record the current Active Player Volume
AuxVol1 := Player2.GetVolume;       // Record the Aux1 Player Volume
AuxVol2 := Player3.GetVolume;       // Record the Aux2 Player Volume
PAL.WaitForTime('XX:59:55');        // wait for 5 seconds before the hour

PAL.LockExecution;                  // Speed up the Script processing
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
  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

MyHourStr :=FloatToStr(MyHour);     // Converts the result from a DateTime to String format
SoundByte := 'It is precisely. '+MyHourStr+' '+AMPM;    // Concatenate the sound byte segments

SpokenPart := URLEncode(SoundByte);

if TimeSignal <> nil then           // Check to ensure the time signal track is ready
  Player2.QueueSong(TimeSignal);    // Queue the audio time signal
  Player1.Volume := LowVol;         // Lower the volume of the Active Player
  Player2.Volume := SignalVol;      // Raise the volume of the Aux Player (with extra gain)
  Player2.Play;                     // Play the audio time message
  PAL.WaitForTime('+00:00:06');     // Wait for 6 seconds to pass before playing the spoken part

if FileExists(FileName) then        // Checks for the existence of the audio file
  Player3.QueueSong(Announcement);  // Queue the audio time message
  Player3.Volume := SignalVol;      // Raise the volume of the Aux Player (with extra gain)
  Player3.Play;                     // Play the audio time message

  SBLength := player3.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

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
Player3.Volume := AuxVol2;          // Restore the Aux2 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
TimeSignal.Free;                    // Release the memory
Was this article helpful?
1 out of 2 found this helpful
Have more questions? Submit a request