Applescript:为每个单词使用新的(随机)语音说出 txt 文件中的单词

发布于 2024-09-17 00:51:34 字数 743 浏览 6 评论 0原文

我需要制作一个脚本,从 txt 文件中选择一个随机句子,并使用一系列语音、语速调制和音调以随机语音说出每个单词。

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

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

提前致谢:-)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2024-09-24 00:51:34

试试这个...

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文