2010-09-04 27 views
1

我需要制作一个脚本,它从txt文件中选取一个随机语句,并使用一组声音以随机语音说出每个单词,讲话速率调制和音调。AppleScript:用每个单词的新(随机)语音说出来自txt文件的单词

例如: 一个句子从txt文件随机选择:“铺床:你仔细听:读一本书” 和{“使”,“一”,“床”}是口头的词对 - 随机语音:

say "make" using "Fred" speaking rate 43 modulation 40 pitch 11 
say "a" using "Bruce" speaking rate 101 modulation 50 pitch 91 
say "bed" using "Kathy" speaking rate 138 modulation 18 pitch 31 

我可以使用一些建议,因为我是AppleScript的新手,感觉有点卡住了。 这是据我已经得到了:

try 
set myWordFile to (choose file with prompt "Select a file to read:" of type {"txt"}) 
open for access myWordFile 
set wordContents to (read myWordFile) 
close access myWordFile 

set AppleScript's text item delimiters to ":" 
set txtvar10 to words of wordContents 
return txtvar10 
end try 

在此先感谢:-)

回答

3

尝试......

set theVoices to {"Alex", "Bruce", "Fred", "Kathy", "Vicki", "Victoria"} 

set myWordFile to (choose file with prompt "Select a file to read:" of type {"txt"}) 
open for access myWordFile 
set wordContents to (read myWordFile) 
close access myWordFile 

set AppleScript's text item delimiters to ":" 
set theSentences to text items of wordContents 
set AppleScript's text item delimiters to "" 

set theSentence to some item of theSentences 
set theWords to words of theSentence 
repeat with aWord in theWords 
    set speakingRate to random number from 1 to 100 
    set theModulation to random number from 1 to 100 
    set thePitch to random number from 1 to 100 

    say aWord using (some item of theVoices) speaking rate speakingRate modulation theModulation pitch thePitch 
end repeat 
+0

谢谢,完美的作品! – PHearst 2010-09-06 06:17:48

+1

为了理解这些单词,这是基于人类语音范围的设置:将讲话速率设置为从180到220的随机数,将调制设置为从44到48的随机数,将该间距设置为从30到65的随机数 – PHearst 2010-09-06 06:19:08

相关问题