
Re: Spoken messages that vary in length
I don't think there's any way of detecting how long a spoken message lasts when using IndigoServer as the source of spoken text. The only way I can think of to get this information would be to use the AppleScript (or command-line) "say" function to create an audio file containing the text to be spoken, then using the command-line "mdls" command to gather the file's metadata information and extract the playback duration from that. This, however, would require you to re-engineer all of your spoken messages. In any case, here's some AppleScript code that will generate the audio file and return the duration in seconds.
- Code: Select all
tell application "Finder"
-- Create the sound file with the spoken text.
say "This is just a test." saving to "/Users/nsheldon/test.aif"
-- Delay a bit to allow the system to populate the metadata for the new file.
delay 0.7
-- Get the metadata information on the file.
set theResult to do shell script "mdls /Users/nsheldon/test.aif"
-- Look through all the lines in the output.
repeat with theText in the paragraphs of theResult
-- Convert the line of data to text.
set theText to text of theText
-- Look for the file duration information.
if theText starts with "kMDItemDurationSeconds" then
-- Remove the parameter name from the information.
set AppleScript's text item delimiters to "= "
set theDuration to text item 2 of theText
set AppleScript's text item delimiters to {""}
end if
end repeat
-- Return the result as a number (instead of text).
return theDuration as number
end tell
EDIT: I composed this before seeing Jay's response. I think the indigo.server.say option is a better way to go, but the above code may still be useful for you.