pyttsx3的所有函数以及用法参数示例
时间: 2023-12-10 18:02:46 浏览: 35
pyttsx3是Python的一个文本到语音转换库。以下是pyttsx3的主要函数及其用法参数示例:
1. `pyttsx3.init()`:初始化pyttsx3引擎。
```python
import pyttsx3
engine = pyttsx3.init()
```
2. `engine.say(text)`:将文本转换为语音。
```python
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.runAndWait()
```
3. `engine.setProperty(key, value)`:设置引擎属性。
```python
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('rate', 150) # 设置语速为150
engine.say("Hello World!")
engine.runAndWait()
```
4. `engine.runAndWait()`:等待语音播放完毕。
```python
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.runAndWait()
```
5. `engine.runAndWait()`:等待语音播放完毕。
```python
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.runAndWait()
```
6. `engine.stop()`:停止语音播放。
```python
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.stop() # 停止语音播放
```
7. `engine.save_to_file(text, filename)`:将语音保存为文件。
```python
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.save_to_file('Hello World!', 'hello.mp3') # 将语音保存为hello.mp3文件
engine.runAndWait()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)