File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Speech to test
2
+
3
+ ## Subprocess and say
4
+
5
+ Using ` say ` which is builtin on macOS. But robotic and limited.
6
+
7
+ ``` python
8
+ import subprocess
9
+
10
+
11
+ text_to_speak = " Hello, world!"
12
+ subprocess.run([" say" , text_to_speak])
13
+ ```
14
+
15
+
16
+ ## Using pyttsx3
17
+
18
+ A free library for generating text to speech locally.
19
+
20
+ Allows custom rate as below but still robotic.
21
+
22
+ ``` sh
23
+ pip install pyttsx3
24
+ ```
25
+
26
+ ``` python
27
+ import pyttsx3
28
+
29
+
30
+ print (" init" )
31
+ engine = pyttsx3.init()
32
+ print (" say" )
33
+ engine.say(" I will speak this text" )
34
+ print (" run" )
35
+ engine.runAndWait()
36
+
37
+
38
+ rate = engine.getProperty(" rate" )
39
+ print (rate)
40
+ # 200.0
41
+ engine.setProperty(" rate" , 150 )
42
+
43
+ engine.say(" I will speak this text slower" )
44
+ engine.runAndWait()
45
+ ```
You can’t perform that action at this time.
0 commit comments