Skip to content

Commit 94fbdbd

Browse files
committed
add text to speech
1 parent f0106f9 commit 94fbdbd

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

Text-to-speech-coverter/Readme.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Certainly! Here's an example of a README file that you can use to document the code:
2+
3+
pgsql
4+
Copy
5+
# Text-to-Speech Conversion
6+
7+
This Python program converts text input into speech using the Google Text-to-Speech (gTTS) library and plays the generated audio using the `playsound` library.
8+
9+
## Requirements
10+
11+
- Python 3.x
12+
- `gTTS` library (`pip install gTTS`)
13+
- `playsound` library (`pip install playsound`)
14+
15+
## Usage
16+
17+
1. Install the required libraries by running the following commands:
18+
pip install gTTS
19+
pip install playsound
20+
21+
Copy
22+
23+
2. Run the `text_to_speech.py` script:
24+
```
25+
python text_to_speech.py
26+
Enter the desired text when prompted.
27+
28+
The program will convert the entered text to speech and save it as an MP3 file named output.mp3.
29+
30+
The generated speech will be played automatically using the default audio player on your system.
31+
32+
Customization
33+
You can modify the code to change the language or adjust the speech synthesis options by referring to the gTTS documentation.
34+
35+
To change the output filename, modify the filename variable in the code.
36+
37+
Feel free to incorporate the text-to-speech functionality into your own projects by importing the text_to_speech function.

Text-to-speech-coverter/output.mp3

7.88 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from gtts import gTTS
2+
from playsound import playsound
3+
4+
# Function to convert text to speech
5+
def text_to_speech(text, filename):
6+
tts = gTTS(text=text, lang='en')
7+
tts.save(filename)
8+
9+
# Take input from the user
10+
text = input("Enter your text: ")
11+
12+
# Specify the output filename
13+
filename = "output.mp3"
14+
15+
# Convert text to speech
16+
text_to_speech(text, filename)
17+
18+
# Play the generated speech
19+
playsound(filename)

0 commit comments

Comments
 (0)