为你的 Fedora 系统增添发音功能
语音 TTS
![](/data/attachment/album/201801/04/211655ejjrnhljormc4jz1.png)


Fedora 工作站默认带有一个小软件，叫做 espeak。它是一个声音合成器 —— 也就是转换文本为声音的软件。


在当今这个世界，发音设备已经非常普遍了。在智能电话、Amazon Alexa，甚至火车站的公告栏中都有声音合成器。而且，现在合成声音已经跟人类的声音很类似了。我们生活在 80bandaid 的科幻电影里！


与前面提到的这些工具相比，espeak 的发音听起来有一点原始。但最终 espeak 可以产生不错的发音效果。而且不管你觉得它有没有用，至少它可以给你带来一些乐趣。


### 运行 espeak


你可以在命令行为 espeak 设置各种参数。包括：


* 振幅（`-a`）
* 音高调整 （`-p`）
* 读句子的速度 （`-s`）
* 单词间的停顿时间 （`-g`）


每个选项都能产生不同的效果，你可以通过调整它们来让发音更加清晰。


你也可以通过命令行选项来选择不同的变音。比如，`-ven+m3` 表示另一种英式男音，而 `-ven+f1` 表示英式女音。你也可以尝试其他语言的发音。运行下面命令可以查看支持的语言列表：



```
espeak --voices

```

要注意，很多非英语的语言发音现在还处于实验阶段。


若要创建相应的 WAV 文件而不是真的讲出来，则可以使用 `-w` 选项：



```
espeak -w out.wav "Audio file test"

```

espeak 还能读出文件的内容。



```
espeak -f plaintextfile

```

你也可以通过标准输入传递要发音的文本。举个简单的例子，通过这种方式，你可以创建一个发音盒子，当事件发生时使用声音通知你。你的备份完成了？将下面命令添加到脚本的最后试试效果：



```
echo "Backup completed" | espeak -s 160 -a 100 -g 4

```

假如有日志文件中出现错误了：



```
tail -1F /your/log/file | grep --line-buffered 'ERROR' | espeak

```

或者你也可以创建一个报时钟表，每分钟报一次时：



```
while true; do date +%S | grep '00' && date +%H：%M | espeak; sleep 1; done

```

你会发现，espeak 的使用场景仅仅受你的想象所限制。享受你这会发音的 Fedora 系统吧！




---


via: <https://fedoramagazine.org/add-speech-fedora-system/>


作者：[Alessio Ciregia](http://alciregi.id.fedoraproject.org/) 译者：[lujun9972](https://github.com/lujun9972) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
By default, Fedora Workstation ships a small package called *espeak*. It adds a speech synthesizer — that is, text-to-speech software.

In today’s world, talking devices are nothing impressive as they’re very common. You can find speech synthesizers even in your smartphone, a product like Amazon Alexa, or in the announcements at the train station. In addition, synthesized voices are nowadays more or less similar to human speech. We live in a 1980s science fiction movie!

The voice produced by *espeak* may sound a bit primitive compared to the aforementioned tools. But at the end of the day *espeak* produces good quality speech. And whether you find it useful or not, at least it can provide some amusement.

## Running espeak

In *espeak* you can set various parameters using command line options. Examples include:

- amplitude (
*-a*) - pitch adjustment (
*-p*) - speed of sentences (
*-s*) - gap between words (
*-g*)

Each of these options produces various effects and may help you achieve a cleaner voice.

You can also select different voice variants with command line options. For example, try *-ven+m3* for a different English male voice, and *-ven+f1* for a female one. You can also use different languages. For a list, run this command:

espeak --voices

Note that many languages other than English are experimental attempts.

To create a WAV file instead of actually speaking something, use the *-w* option:

espeak -w out.wav "Audio file test"

The *espeak* utility also reads the content of a file for you.

espeak -fplaintextfile

Or you can pass the text to speech from the standard input. In this way, as a simple example, you can build a talking box that alerts you to an event using a voice. Your backup is completed? Add this command to the end of your script:

echo "Backup completed" | espeak -s 160 -a 100 -g 4

Suppose an error shows up in a log file:

tail -1F /your/log/file | grep --line-buffered 'ERROR' | espeak

Or perhaps you want a speaking clock telling you every minute what time it is:

while true; do date +%S | grep '00' && date +%H:%M | espeak; sleep 1; done

## mianosm

Feel free to continue the fun:

bottles=100;

while [ $bottles -gt 0 ];

do espeak “$bottles bottles of beer on the wall, $bottles bottles of beer, take one down pass it around”; (( bottles -= 1 )); espeak “$bottles bottles of beer on the wall”;

done

….I don’t know why that is my first thought of what needs to be done with espeak.

## Pedro Doria Meunier

brilliant! 😀

## Logan Byrd

Excellent! This didn’t work for me as is, though. I had to echo it and pipe it into espeak as in the article, or espeak would ignore everything after the first word (the space terminated the espeak command despite the quotes).

Updated version for others who ran into this and still want to have a laugh:

bottles=100;

while [ $bottles -gt 0 ];

do echo “$bottles bottles of beer on the wall, $bottles bottles of beer, take one down pass it around” | espeak; (( bottles -= 1 )); eecho “$bottles bottles of beer on the wall” | espeak;

done

## Mehdi

This is super cool! I did not know of speech in Fedora

## VfioGaming

that was very funny 🙂

i love you guys !!!

p.s. the man voice is a bit scary . i change it with : espeak -v female5

## Maimela

i’m looking for support for a kensington verimark (finger print scanner app for linux, it only works for windows hello but i believe someone out there knows how to use it in linux)

## arthur

Is there any software that does the opposite in that it takes speech and converts it into text?

## Paul W. Frields

@arthur: You might be interested in OpenSTT although it’s not ready yet if I understand correctly. There are other projects like Kaldi but these are oriented toward building tools as opposed to end-users.