macos 以编程方式获取 Mac 文本转语音列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1489800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:26:23  来源:igfitidea点击:

Getting list of Mac text-to-speech voices programmatically?

macostext-to-speech

提问by Mark Harrison

The mac command saycan specify the voice used with the -vflag.

mac 命令say可以指定与-v标志一起使用的语音。

say -v Alex "compile completed, put your swords down."

The available voices can be seen in System Preferences/Speech/Text to Speech. How can I get this list programmatically?

可以在系统偏好设置/语音/文本到语音中看到可用的语音。如何以编程方式获取此列表?

回答by Igor Shubovych

This is the list of available voices:

这是可用声音的列表:

say -v '?'

回答by nroose

for voice in `say -v '?' | awk '{print }'`; do say -v "$voice" "Hello, my name is $voice."; done

回答by Mark Harrison

Python Version, courtesy of Barry Wark:

Python 版本,由Barry Wark 提供

from AppKit import NSSpeechSynthesizer
print NSSpeechSynthesizer.availableVoices()

回答by Mark Harrison

Shell Version, no hack too cheap!

Shell 版,没有 hack 太便宜了!

(Don't actually use this, use the python version instead.)

(实际上不要使用它,而是使用 python 版本。)

ls /System/Library/Speech/Voices | sed 's/.SpeechVoice$//'

Agnes
Albert
Alex
BadNews
Bahh
Bells
Boing
...

回答by Karsten Johansson

It is worth going through several of the voices before deciding on one. There is a huge variation in quality.

在决定一个声音之前,值得先了解几种声音。质量存在巨大差异。

For example, Tom sounds a bit impatient, but way more realistic than Alex. And some of the British voices are great.

例如,汤姆听起来有点不耐烦,但比亚历克斯更现实。一些英国人的声音很棒。

Using say -v '?' gives you a list of the installed voices plus some sample sentences that give you an idea what to expect of the voice. You have to go through preferences to install most of the really good voices, but they come with a Compact voice file that lets you hear what each voice sounds like before you actually download them.

使用 say -v '?' 为您提供已安装语音的列表以及一些示例句子,让您了解对语音的期望。您必须通过首选项来安装大多数真正好的声音,但它们带有一个紧凑的语音文件,可以让您在实际下载之前听到每个声音的声音。

回答by Luis Davim

You can use the following to sample all the available voices:

您可以使用以下命令对所有可用语音进行采样:

say -v '?' | awk '{==""; printf "-v %s", ; =""; print " \"" ##代码## "\""}'| xargs -L1 say