Text-to-Speech Program using Edge TTS
Session 2025โ26
Official certification for the submitted project
Maples Academy Khatauli
This is to certify that Harsh, a bonafide student of
Class XI-A, Roll Number 17 of
Maples Academy Khatauli, has successfully completed
the Computer Science project entitled
"Text-to-Speech Program using Edge TTS"
during the academic session 2025โ26, under the
guidance of Er. Pankaj Sir (PGT Computer Science).
This project has been prepared in accordance with the guidelines
prescribed by the Central Board of Secondary Education (CBSE)
for Class XI practical examination.
Expressing gratitude to those who helped
Understanding what this project does and its significance
This project is a Text-to-Speech (TTS) application built using the Python programming language. It takes text input from the user and converts it into natural-sounding human speech using Microsoft Edge's Neural AI voices.
The program supports multiple languages and voices including Hindi (Male & Female) and English (Male & Female with US & UK accents). Users can type any text โ in Hindi or English โ select their preferred voice, and hear the computer speak it out loud with realistic, human-like pronunciation and natural intonation.
Software, libraries, and services powering this project
The core programming language used for the entire project. Known for its simplicity and vast ecosystem. Version 3.8+ is required.
LANGUAGEA Python library that connects to Microsoft Edge's text-to-speech service. Provides free access to 300+ neural AI voices in 40+ languages.
LIBRARYA multimedia library for Python. Used here specifically to load and play the generated MP3 audio through the computer's speakers.
LIBRARYPython's built-in module for asynchronous operations. Required because Edge TTS communicates with Microsoft's servers over the internet.
MODULEThe Integrated Development Environment (IDE) used for writing, editing, debugging, and testing the Python source code.
IDEThe cloud-based artificial intelligence service that processes text and generates speech using deep neural network models.
CLOUDBefore running the project, install the required libraries using pip:
# Install Edge TTS library pip install edge-tts # Install Pygame for audio playback pip install pygame
| Concept | Where Used | Purpose |
|---|---|---|
| Dictionary | VOICES variable | Store voice names & IDs as key-value pairs |
| Functions | generate_speech(), play_audio(), main() | Modular & reusable code blocks |
| While Loop | Main menu & input validation | Repeat until valid input or user exits |
| For Loop | Displaying voice options | Iterate over dictionary items |
| Conditional (if-elif-else) | Input validation, menu choices | Decision making in program flow |
| String Methods | .strip(), .lower() | Clean and normalize user input |
| Async / Await | generate_speech() function | Handle network communication efficiently |
| File Handling | os.path.exists(), os.remove() | Manage temporary MP3 file |
| Modules & Imports | edge_tts, pygame, asyncio, os, time | Use external functionality in the program |
Step-by-step execution flow of the program
The program starts with a welcome banner and shows 6 voice options: Hindi Male/Female, English US Male/Female, and English UK Male/Female. The user selects by entering a number (1โ6).
The user types any text they want to hear spoken. It can be in Hindi (using Hindi keyboard/typing) or English. The program validates that the input is not empty.
The edge_tts library packages the text and selected voice ID, then sends it to Microsoft's Azure cloud servers over a secure internet connection using asynchronous communication.
Microsoft's deep learning model processes the text, understanding pronunciation, intonation, emphasis, and natural pauses. It generates a high-quality MP3 audio file and sends it back.
The received MP3 file is saved locally as "speech.mp3" and immediately played through the speakers using Pygame's mixer module. The program waits until playback completes.
The user is asked if they want to speak more text. If yes, the loop continues. If no, the temporary MP3 file is automatically deleted and the program exits cleanly.
Complete Python source code of the project
# ========================================== # TEXT-TO-SPEECH PROGRAM (Edge TTS) # CBSE Class 11 - Computer Science Project # Made by: Harsh | Class XI-A | Roll No: 17 # School: Maples Academy Khatauli # Session: 2025-26 # ========================================== import edge_tts import asyncio import pygame import time import os # ---------- AVAILABLE VOICES ---------- VOICES = { "1": ("Hindi Female", "hi-IN-SwaraNeural"), "2": ("Hindi Male", "hi-IN-MadhurNeural"), "3": ("English Female US", "en-US-JennyNeural"), "4": ("English Male US", "en-US-GuyNeural"), "5": ("English Female UK", "en-GB-SoniaNeural"), "6": ("English Male UK", "en-GB-RyanNeural"), } OUTPUT_FILE = "speech.mp3" # ---------- GENERATE SPEECH ---------- async def generate_speech(text, voice): communicate = edge_tts.Communicate(text, voice) await communicate.save(OUTPUT_FILE) # ---------- PLAY AUDIO ---------- def play_audio(): pygame.mixer.init() pygame.mixer.music.load(OUTPUT_FILE) pygame.mixer.music.play() while pygame.mixer.music.get_busy(): time.sleep(0.1) pygame.mixer.music.unload() pygame.mixer.quit() # ---------- MAIN PROGRAM ---------- def main(): print() print(" " + "=" * 40) print(" TEXT TO SPEECH PROGRAM") print(" Powered by Microsoft Edge AI") print(" " + "=" * 40) # Show voice options print("\n Available Voices:") print(" " + "-" * 35) for key, (name, _) in VOICES.items(): print(f" {key}. {name}") print(" " + "-" * 35) while True: # --- Choose Voice --- while True: choice = input("\n Choose voice (1-6): ").strip() if choice in VOICES: break print(" Invalid! Enter 1 to 6.") voice_name, voice_id = VOICES[choice] # --- Enter Text --- text = input(" Enter text to speak: ").strip() if not text: print(" Text cannot be empty!") continue # --- Generate & Play --- print(f"\n Generating speech in [{voice_name}]...") asyncio.run(generate_speech(text, voice_id)) print(" Playing audio... ๐") play_audio() print(" Done! โ ") # --- Play Again? --- again = input("\n Speak again? (y/n): ").lower() if again != "y": break # Cleanup temp file if os.path.exists(OUTPUT_FILE): os.remove(OUTPUT_FILE) print("\n Thanks for using! Goodbye! ๐\n") # --- RUN --- main()
Sample output of the program during execution
========================================
TEXT TO SPEECH PROGRAM
Powered by Microsoft Edge AI
========================================
Available Voices:
-----------------------------------
1. Hindi Female
2. Hindi Male
3. English Female US
4. English Male US
5. English Female UK
6. English Male UK
-----------------------------------
Choose voice (1-6): 1
Enter text to speak: เคจเคฎเคธเฅเคคเฅ, เคฎเฅเค เคนเคฐเฅเคท เคนเฅเค, เคเคเฅเคทเคพ เคเฅเคฏเคพเคฐเคนเคตเฅเค เคเคพ เคเคพเคคเฅเคฐ
Generating speech in [Hindi Female]...
Playing audio... ๐
Done! โ
Speak again? (y/n): y
Choose voice (1-6): 4 Enter text to speak: Hello! This is my Computer Science project for Class 11. Generating speech in [English Male US]... Playing audio... ๐ Done! โ Speak again? (y/n): y Choose voice (1-6): 6 Enter text to speak: Welcome to Maples Academy Khatauli! Generating speech in [English Male UK]... Playing audio... ๐ Done! โ Speak again? (y/n): n Thanks for using! Goodbye! ๐
This Text-to-Speech project has been an enriching and insightful
learning experience. Through this project, I have gained practical
knowledge of Python programming,
including core concepts like functions, dictionaries, loops, conditional
statements, file handling, and working with external libraries.
I also learned about cloud-based AI services
and how modern applications leverage APIs to access powerful capabilities
like neural text-to-speech. The project demonstrates that even a
relatively simple Python program can harness cutting-edge artificial
intelligence technology.
The program is practical and impactful
โ it can assist visually impaired individuals, aid in language learning,
and serve as a solid foundation for more advanced projects like voice
assistants and accessibility tools.
I am sincerely grateful to Er. Pankaj Sir
for his expert guidance throughout this project, and to
Mrs. Garima Singh (Principal) for
fostering an environment of innovation at
Maples Academy Khatauli.
References and resources consulted during the project