Skip to content

Commit a0c4edc

Browse files
added a script to convert text to audio file
1 parent cb448c2 commit a0c4edc

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
1. **32_stock_scraper.py**: Get stock prices
3535
1. **33_country_code.py**: Convert country code to country name
3636
1. **34_git_all_repos.py**: Clone all repositories from a public user or organization on Github. Usage: `python git_all_repos.py users USER_NAME` or `python git_all_repos.py orgs ORG_NAME`
37+
1. **35_text_to_audio.py**: Convert text to audio file using gtts module

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ PyYAML==3.11
33
requests==2.12.4
44
wheel==0.24.0
55
lxml==3.8.0
6+
gtts==1.1.8

scripts/35_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)