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! :)
精彩评论