最近感觉需要一个txt文本转声音的阅读器,帮我阅读单词+翻译,或者有用的句子+翻译,笔记等。先读德语,后读中文。使用场景:做饭的时候,坐火车的时候。利用碎片时间靠声音回顾一下已经学过的东西,感觉很不错。而且随时又可以将已经掌握的内容删掉。
google了好久,都没有一个满足需求的软件,无意中知道了Applescript可以调用mac上的语音,于是看了下语法,自己写了一个脚本。这个脚本可以阅读一个放在桌面的名字为read.txt文档,每一行德语和中文用英文冒号分割:

Applescript代码如下:
set srcFile to ((path to desktop) as text) & "read.txt"
set filetext to paragraphs of (read file srcFile as «class utf8»)
repeat with lineString in filetext
display dialog lineString buttons {"Continue"} giving up after 2
set AppleScript's text item delimiters to ":"
set lineList to every text item of lineString
set j to length of lineList
repeat with i from 1 to j
set theItem to item i of lineList
if i mod 2 = 0 then
say theItem using "Ting-ting"
else
say theItem using "Anna"
end if
end repeat
end repeat
用法:
1.准备一个read.txt文档放在桌面,每一行德语和中文用英文冒号分割。
2.复制代码到macbook上的 script editor,点击上面的那个▶️运行。
以上这段代码还有几个地方可以自己改,如果是学别的语言,英语,法语等等,可以将“Anna”改成别的在系统语言列表里的别的声音。

如果这段代码也正好是满足了你的需求,给你学语言带来了帮助,可以给我赞赏,有时间我会改的更好。
网友评论