views:

107

answers:

1

I need to make an script that picks a random sentence from a txt-file and says each word in a random voice, using an array of voices, speaking rate modulation and pitch.

For example: A sentence is chosen randomly from the txt file: "make a bed:listen carefully:read a book" and {"make", "a", "bed"} is spoken word-for-word by a random voice:

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

I could use some advice, as I'm new to AppleScript and feel a little stuck. This is as far as I've gotten:

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

Thanks in advance :-)

A: 

Try this...

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
regulus6633
Thanks, that works perfectly!
PHearst
To understand the words, this is a setup based on the range of the human voice: set speakingRate to random number from 180 to 220 set theModulation to random number from 44 to 48 set thePitch to random number from 30 to 65
PHearst