Voice Chapterisation
I was reading about Speakable Items and QuickTime and made this script
It will allow you to chapterise (add chapters to) the front Movie in QuickTime Player - by voice. Simply move the play head to the appropriate points and say “Chapter” - then when the last chapter has been added say “Finish”.
Requires Panther and QuickTime Pro.
you can get the script into Script Editor by clicking Here
global blurb, targetBlurb, sourceMovie, sourceMovieDuration, sourceMovieName, sourceMovieWidth, sourceMovieHeight, chapterTrackText, sourceMovieWidth, sourceMovieHeight, numChaps, lastChapTime
on run
my chapterise()
end run
to chapterise()
set lastChapTime to 0
– Quit if QT Pro is not installed
if not my checkForQTPro() then
return
end if
– pre-check for a front movie
my movieIsForemostPreCheck()
tell application “QuickTime Player”
– Show Info Dialog — explains what the script does.
set the blurb to “This script will add chapters to a QuickTime Movie. Make sure that the movie you want is foremost in QuickTime Player.
” & targetBlurb
display dialog blurb buttons {”OK”} default button 1 giving up after 5
– Now we’re off and ready to go…
– Get the info for the movie we want to chapterise
if not my getFrontMovieInfo() then
activate
display dialog “There is no front movie to chapterise.” buttons {”Whoops!”} default button 1 giving up after 5
return
end if
display dialog “Initial Chapter Title:” default answer (”Start”) buttons {”OK”, “cancel”} default button 1
copy the result as list to {text_returned, button_pressed}
if button_pressed is “OK” then
set initalChapterName to text_returned
else
return
end if
set chapterTrackText to “{QTtext}{font:Geneva}{plain}{size:12}{textColor: 65535, 65535, 65535}{backColor: 0, 0, 0}{justify:center}{timeScale:30}{width:” & sourceMovieWidth & “}{height:” & sourceMovieHeight & “}{timeStamps:absolute}{language:0}{textEncoding:0}
[00:00:00.00]
{textBox: 0, 0, 50, 160}” & initalChapterName & “
“
– Get the chapters
set numChaps to 0
set another to true
repeat while another is true
set commandSpoken to my listenForChapterCommand()
if commandSpoken is “chapter” then
my addMarker()
else if commandSpoken is “finish” then
my finishChapterise()
set another to false
else if commandSpoken is “debug” then
log (”debug command used”)
else
set another to false
end if
log commandSpoken
end repeat
end tell
end chapterise
– Script subRoutines
to checkForQTPro()
tell application “QuickTime Player”
if QuickTime Pro installed is false then
display dialog “QT Pro is required for this script” buttons {”OK”} default button 1
return false
end if
end tell
return true
end checkForQTPro
to finishChapterise()
set chapterTrackText to chapterTrackText & “[" & my explodeTime(sourceMovieDuration) & "]“
set chapterFile to my writeOut(chapterTrackText)
tell application “QuickTime Player”
activate
tell sourceMovie to rewind
make new track at sourceMovie with data alias chapterFile
end tell
tell application “Finder” to move file chapterFile to trash
my attachChapterTrackToVideo()
end finishChapterise
to attachChapterTrackToVideo()
tell application “QuickTime Player”
tell sourceMovie
set textTracks to every track whose name is “Text Track”
set chapTrack to first item of textTracks
set videoTracks to every track whose name is “video Track”
set videoTrack to first item of videoTracks
tell videoTrack
set chapterlist to chapTrack
end tell
tell chapTrack
set enabled to false
end tell
end tell
end tell
end attachChapterTrackToVideo
to writeOut(someData)
activate
set chapFile to ((path to home folder as string) & “tempChapterMovie.txt”)
– set chapFile to choose file name with prompt “where should I save the chapter file?” default name (sourceMovieName & “_chapters.txt”)
set chapFileRef to open for access chapFile with write permission
write someData to chapFileRef
close access chapFileRef
return chapFile
end writeOut
to listenForChapterCommand()
tell application “SpeechRecognitionServer”
set chapteriserLanguageModel to {”chapter”, “marker”, “mark”, “now”}
set finishLanguageModel to {”end”, “finish”, “stop”}
set cancelLanguageModel to {”quit”, “cancel”}
set debugLanguageModel to {”time”}
set thePrompt to “listening…”
try
set theResultstring to listen for chapteriserLanguageModel & finishLanguageModel & cancelLanguageModel & debugLanguageModel with prompt thePrompt
if theResultstring is in finishLanguageModel then
say “finishing up”
return “finish”
else if theResultstring is in cancelLanguageModel then
say “cancelling”
return “cancel”
else if theResultstring is in chapteriserLanguageModel then
say “adding chapter marker”
return “chapter”
else if theResultstring is in debugLanguageModel then
say “debug”
return “debug”
end if
end try
end tell
return “error”
end listenForChapterCommand
to addMarker()
tell application “QuickTime Player”
tell front movie to set currentTime to the current time of sourceMovie
if currentTime is less than lastChapTime then
display dialog “Sorry, you must add chapters in Chronological order.” buttons {”OK”} default button 1
return
else
set lastChapTime to currentTime
end if
set chapTime to my explodeTime(currentTime)
display dialog “Chapter Title:” default answer (”Chapter ” & numChaps + 1) buttons {”OK”, “cancel”} default button 1
copy the result as list to {text_returned, button_pressed}
if button_pressed is “OK” then
–[00:00:19.00]
–{textBox: 0, 0, 50, 160}Chapter Two
set markerText to “[" & chapTime & "]
{textBox: 0, 0, 50, 160}” & text_returned & “
“
set chapterTrackText to chapterTrackText & markerText
set numChaps to numChaps + 1
– log markerText
end if
end tell
end addMarker
to movieIsForemostPreCheck()
tell application “QuickTime Player”
try
set sourceMovie to front movie
tell sourceMovie
set frontMovieName to name
end tell
set targetBlurb to “Current targetted movie: ‘” & frontMovieName & “‘.”
on error theError
set targetBlurb to “There is currently NO movie targetted. Make sure a movie is open before pressing OK in this dialog.”
end try
end tell
end movieIsForemostPreCheck
to getFrontMovieInfo()
tell application “QuickTime Player”
activate
try
set sourceMovie to front movie
tell sourceMovie
rewind
set sourceMovieDuration to duration
set sourceMovieName to name
set dims to (dimensions)
set sourceMovieWidth to first item of dims
set sourceMovieHeight to last item of dims
return true
end tell
on error
return false
end try
end tell
end getFrontMovieInfo
to explodeTime(durationInSeconds)
set secondsLeft to durationInSeconds div 600
set secPerMin to 60
set secPerHour to secPerMin * 60
set numHours to “00″
set numMins to “00″
set numSecs to “00″
if secondsLeft is greater than or equal to secPerHour then
set numHours to secondsLeft div secPerHour
log (”number of hours: ” & numHours)
set excessSeconds to numHours * secPerHour
set secondsLeft to secondsLeft - excessSeconds
if numHours < 10 then
log (”padding hour int”)
set numHours to (”0″ & numHours) as string
end if
end if
if secondsLeft is greater than or equal to secPerMin then
set numMins to secondsLeft div secPerMin
set excessSeconds to numMins * secPerMin
set secondsLeft to secondsLeft - excessSeconds
if numMins < 10 then
set numMins to (”0″ & numMins) as string
end if
end if
set numSecs to secondsLeft
if numSecs < 10 then
set numSecs to (”0″ & numSecs) as string
end if
set output to (numHours & “:” & numMins & “:” & numSecs) as string
return output
end explodeTime