首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Applescript:从txt文件中说出单词,每个单词都有新的(随机)语音

Applescript:从txt文件中说出单词,每个单词都有新的(随机)语音
EN

Stack Overflow用户
提问于 2010-09-04 22:40:46
回答 1查看 5.9K关注 0票数 1

我需要做一个脚本,从一个txt文件中挑选一个随机句子,并说每个单词在一个随机的声音,使用一组声音,语速调制和音高。

例如:从txt文件中随机选择一句话:“铺床:仔细听:读一本书”,{ "make ","a","bed"}是通过随机声音逐字朗读的:

代码语言:javascript
复制
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,感觉有点卡住了。这就是我所得到的:

代码语言:javascript
复制
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

提前感谢:-)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-09-06 04:00:08

试试这个。

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3642712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档