Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cc58a0

Browse filesBrowse files
committed
added converting text to speech tutorial
1 parent 8124984 commit 7cc58a0
Copy full SHA for 7cc58a0

File tree

Expand file treeCollapse file tree

7 files changed

+57
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+57
-0
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
4646
- [How to Convert Speech to Text in Python](https://www.thepythoncode.com/article/using-speech-recognition-to-convert-speech-to-text-python). ([code](machine-learning/speech-recognition))
4747
- [Top 8 Python Libraries For Data Scientists and Machine Learning Engineers](https://www.thepythoncode.com/article/top-python-libraries-for-data-scientists).
4848
- [How to Predict Stock Prices in Python using TensorFlow 2 and Keras](https://www.thepythoncode.com/article/stock-price-prediction-in-python-using-tensorflow-2-and-keras). ([code](machine-learning/stock-prediction))
49+
- [How to Convert Text to Speech in Python](https://www.thepythoncode.com/article/convert-text-to-speech-in-python). ([code](machine-learning/text-to-speech))
4950

5051

5152
- ### [General Python Topics](https://www.thepythoncode.com/topic/general-python-topics)
Collapse file
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# [How to Convert Text to Speech in Python](https://www.thepythoncode.com/article/convert-text-to-speech-in-python)
2+
- `pip3 install -r requirements.txt`
3+
- To convert text to speech online using Google API, use `tts_google.py`
4+
- To use offline engines in your platform, consider using `tts_pyttsx3.py`
Collapse file
5.34 KB
Binary file not shown.
Collapse file
4.41 KB
Binary file not shown.
Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pyttsx3
2+
gTTS
3+
playsound
Collapse file
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import gtts
2+
from playsound import playsound
3+
4+
# make request to google to get synthesis
5+
tts = gtts.gTTS("Hello world")
6+
# save the audio file
7+
tts.save("hello.mp3")
8+
# play the audio file
9+
playsound("hello.mp3")
10+
11+
# in spanish
12+
tts = gtts.gTTS("Hola Mundo", lang="es")
13+
tts.save("hola.mp3")
14+
playsound("hola.mp3")
15+
16+
# all available languages along with their IETF tag
17+
print(gtts.lang.tts_langs())
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pyttsx3
2+
3+
# initialize Text-to-speech engine
4+
engine = pyttsx3.init()
5+
6+
# convert this text to speech
7+
text = "Python is a great programming language"
8+
engine.say(text)
9+
# play the speech
10+
engine.runAndWait()
11+
12+
# get details of speaking rate
13+
rate = engine.getProperty("rate")
14+
print(rate)
15+
16+
# setting new voice rate (faster)
17+
engine.setProperty("rate", 300)
18+
engine.say(text)
19+
engine.runAndWait()
20+
21+
# slower
22+
engine.setProperty("rate", 100)
23+
engine.say(text)
24+
engine.runAndWait()
25+
26+
# get details of all voices available
27+
voices = engine.getProperty("voices")
28+
print(voices)
29+
# set another voice
30+
engine.setProperty("voice", voices[1].id)
31+
engine.say(text)
32+
engine.runAndWait()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.