Applescript:用于保存WAV格式的“说”命令的shell脚本

问题描述:

我试图做一个非常简单的applescript,但是我遇到了一个问题,无法从这里前进。Applescript:用于保存WAV格式的“说”命令的shell脚本

我的程序应该做的很简单。它读取一个文本文件,将其内容分割成一个数组,然后执行shell脚本来利用mac终端的say命令来读取文本并将其保存到.wav文件中。

在终端上,我可以用这个保存为WAV格式的文件: say -o "hello.wav" [email protected] "hello world"

我试图模仿我的AppleScript代码无济于事,这里是代码:

set theFile to (choose file with prompt "Select a file to read:" of type {"TXT"}) 
open for access theFile 
set fileContents to (read theFile) 
close access theFile 

set everyLine to every paragraph of fileContents 

repeat with theLine in everyLine 
    set thisOne to split(theLine, ";") 
    set fileName to item 1 of thisOne 

    do shell script "say -o" & item 1 of thisOne & ".wav [email protected] " & item 3 of thisOne 

end repeat 

to split(someText, delimiter) 
    set AppleScript's text item delimiters to delimiter 
    set someText to someText's text items 
    set AppleScript's text item delimiters to {""} --> restore delimiters to default value 
    return someText 
end split 

运行此代码导致Opening output file failed: -43

即使是一个简单的do shell script "say -o hello.aiff hello也会返回相同的错误。 我非常感谢任何帮助,包括告诉我,我根本无法做到这一点,我应该学习适当的编程语言:)

该脚本没有权限将文件保存在根目录下。您可以使用管理员权限运行脚本,也可以将文件保存到其他位置,例如主目录。

do shell script "say -o $HOME/hello.aiff hello"

+0

非常感谢你,它就这么简单! –