使用AppleScript将PDF文件的内容保存为语音

时间:2011-09-27 02:07:21

标签: applescript

我已经构建了一个简单的脚本,它接受一个字符串并将其转换为音频文件:

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

我想编辑脚本,以便不使用字符串“这只是一个测试”,而是获取PDF文档并使用文档中的文本创建音频文件。

1 个答案:

答案 0 :(得分:1)

Skim,一个免费的PDF查看器,您可能会感兴趣。它是可编写脚本的,并具有AppleScript命令以从某些PDF页面中提取文本。一旦您下载了Skim,就可以运行此脚本:

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")

快乐的编码! :)