Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript say command sometimes produces a file with no data

Problem


AppleScript produces an aiff file with no sound and zero (0) bytes. I am looping through many lists of text and using three different voices. When I run my script I get many files with no sound. There does not appear t be any common reason for the failure. I've tried using:


  • delay n
  • stopping with current voice
  • wating for completion


Nothing has fixed the problem. Some of the files simply have no sound but if I say the text via my automator service then I do hear the output . So it seems that something is off in my repeat loop. Any thoughts on how to fix this (timing issue?) using AppleScript?


setalistto {}

set input to every paragraph of (readFile("textFileWithChineseWords"))


repeat with nextLine in input

if first character of nextLine is not "#" then


--^.*\s(.*)\s\[(.*)\]\s


--^.*\s(.*)\s\[

set output to (find text "^.*\\s(.*)\\s\\[(.*)\\]" in nextLine with regexp and string result)

set pinyin to (find text "\\[(.*)\\]" in nextLine with regexp and string result)

set pinyin to change "[" into "" in pinyin

set pinyin to change "]" into "" in pinyin

set pinyin to change space into "" in pinyin

set pinyin to change "," into "" in pinyin


--set pinyin to change "," into "" in pinyin


set alist to (split(output, space))

set simple to item 2 of alist


logsimple



saveAIFFFile(simple, pinyin)



--log simple


--log alist


--log pinyin

delay 0.3

end if

end repeat



on readFile(unixPath)

set foo to (open for access (POSIX file unixPath))

set txt to (read foo for (get eof foo) as «class utf8»)

close accessfoo

return txt

end readFile


on fileIsGood(filename)


set theItem to quoted form of POSIX path of filename

set output to false


--logtheItem


if exists (theItem) then

set fileSize to word 1 of (do shell script "du -sk " & theItem)


--log fileSize

if (fileSize is equal to 0) then return false

else

return false

end if


return output


end fileIsGood



on saveAIFFFile(msg, filename)


set cnfilname to ("/tmp" & filename & ".aiff") -- quoted form of POSIX path of


delay 4

set msg to change "" into ", " in msg

saymsgusing "Ting-Ting" saving toPOSIX filecnfilname with stopping current speech and waiting until completion

--say "" with stopping current speech


if (not fileIsGood(cnfilname)) then

repeat until (fileIsGood(cnfilname))


--delay 4

set msg to change "" into ", " in msg


saymsgusing "Ting-Ting" saving tocnfilname with stopping current speech and waiting until completion

end repeat

end if



end saveAIFFFile


to split(input, delimiter)

set AppleScript'stext item delimiters to delimiter

set someText to (every text item in input) as list

set AppleScript'stext item delimiters to {""} --> restore delimiters to default value

return someText

end split

MacBook Air (13-inch Mid 2012), Mac OS X (10.7.5), Love the mac (OSX 10.9+)

Posted on Mar 27, 2014 10:02 AM

Reply
Question marked as Best reply

Posted on Mar 27, 2014 10:46 AM

I thought I'd share the solution for this problem with the community.


Changing my AppleScript line that was performing the say command to the shell script results in much faster execution and no loss of audio on the output. It appears that AppleScript was likely sending the same commands under the hood and the timing was thrown off as a result (delay between sig and ack).


do shell script "say '" & msg & "' -o '" & cnfilname & "' -v 'Ting-Ting'"


looping in this way I was able to remove the delays and I'm on to the next problem.


Hope this helps someone else.

1 reply
Question marked as Best reply

Mar 27, 2014 10:46 AM in response to mingsai

I thought I'd share the solution for this problem with the community.


Changing my AppleScript line that was performing the say command to the shell script results in much faster execution and no loss of audio on the output. It appears that AppleScript was likely sending the same commands under the hood and the timing was thrown off as a result (delay between sig and ack).


do shell script "say '" & msg & "' -o '" & cnfilname & "' -v 'Ting-Ting'"


looping in this way I was able to remove the delays and I'm on to the next problem.


Hope this helps someone else.

AppleScript say command sometimes produces a file with no data

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.