Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit7cc58a0

Browse files
committed
added converting text to speech tutorial
1 parent8124984 commit7cc58a0

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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)
Lines changed: 4 additions & 0 deletions
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`
5.34 KB
Binary file not shown.
4.41 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pyttsx3
2+
gTTS
3+
playsound
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
importgtts
2+
fromplaysoundimportplaysound
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())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
importpyttsx3
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)

[8]ページ先頭

©2009-2025 Movatter.jp