开发者

Save the contents of a PDF file as spoken audio using AppleScript

I have built a simple script which takes a string and converts it to an audio file:

say "This is only a test." using "Fred" saving to file (((path to desktop) as string) & "audio.aiff"

I'd like to edit the script so that instead of u开发者_如何学JAVAsing the string "This is only a test" it would fetch a PDF document and use the text in the document to create an audio file.


Skim, a free PDF viewer, might be of interest to you. It's scriptable and features an AppleScript command to extract the text from certain PDF pages. Once you've downloaded Skim, you can run this script:

tell application "Skim"
    open (POSIX file "/path/to/PDF/document.pdf")
    set the stuff to (get text for page 1 of document 1) as string --change 'page 1' to whatever page number you need
    --if you want all the pages, just use 'every page'
end tell
say the stuff using "Fred" saving to file (((path to desktop) as string) & "audio.aiff")

Happy coding! :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜