Skip to content

Commit 47b230d

Browse files
conversion of text to speech using gtts python module (Logan1x#102)
1 parent ffedcdf commit 47b230d

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

bin/Text-to-audio/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Text To Audio
2+
3+
### We are using gtts module for conversion
4+
5+
Requirements: pip install gtts
6+
7+
#### Flow
8+
9+
gtts(Google Text To Speech)
10+
11+
1. Initialise the variable for your text ("mytext" line 6 in main.py)
12+
2. Initialise the variable for language ("language" line 9 in main.py)
13+
3. Create an instance of gTTS class ("myobj" line 12 in main.py)
14+
4. Call the method save() and pass the filename that you want as a parameter (line 15 in main.py)
15+
5. Play the audio file (line 19 in main.py)
16+
17+
#### NOTE
18+
If you make any changes main.py, please mention it in README.md (this file). A better documentation makes the process of development faster.
19+
20+
---
21+
Author - Saumitra Jagdale
22+
23+
24+
25+
26+

bin/Text-to-audio/hello_world.mp3

17.3 KB
Binary file not shown.

bin/Text-to-audio/text-to-audio.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
from gtts import gTTS
3+
import os
4+
5+
# Enter the text in string format which you want to convert to audio
6+
mytext = "Hello World!, this audio is created using GTTS module."
7+
8+
# Specify the language in which you want your audio
9+
language = 'en'
10+
11+
# Create an instance of gTTS class
12+
myobj = gTTS(text=mytext, lang=language, slow=False)
13+
14+
# Method to create your audio file in mp3 format
15+
myobj.save("hello_world.mp3")
16+
print("Audio Saved")
17+
18+
# This will play your audio file
19+
os.system("mpg321 welcome.mp3")

0 commit comments

Comments
 (0)