Python 3 Microsoft Edge TTS Engine to Export Text to Speech as an MP3 Audio File

 

Exporting Text to Speech as an MP3 Audio File Using Python 3 and Microsoft Edge TTS Engine

 

Text-to-speech (TTS) technology is a powerful way to convert written text into spoken words, and Python makes it easy to work with TTS engines. In this guide, we’ll show you how to use Python 3 with the Microsoft Edge TTS engine to export text as an MP3 audio file.

 

Prerequisites

 

Before we dive into the steps, ensure you have the following:

  1. Python 3 Installed: Download and install Python 3 from python.org.
  2. Microsoft Edge Installed: The Edge browser comes pre-installed on most modern Windows systems.
  3. Edge TTS Library: Install the edge-tts package to interact with the Microsoft Edge TTS engine.

 

Step 1: Install Required Python Libraries

 

Open a terminal or command prompt and run the following command to install the edge-tts library:

 

 

This library enables you to utilize Microsoft Edge’s TTS capabilities from Python.

Step 2: Write the Python Script

 

Create a Python script file, e.g., export_tts.py, and add the following code:

 

  1. Change the Text: Replace the input_text variable with your desired text.
  2. Choose a Voice: The voice parameter in the Communicate function specifies the TTS voice. You can find available voices in the Microsoft Edge TTS documentation.
  3. Set the Output File Path: Modify output_mp3 to define where the MP3 file will be saved.

 

Step 4: Run the Script

 

Execute the script in your terminal or command prompt:

 

 

Step 5: Verify the MP3 File

 

Locate the output.mp3 file in your specified directory and play it using any media player to ensure the TTS conversion worked as expected.

 

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *