Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert text to speech in python 3.5 on windows 10?

I tried espeak but didn't succeed and some functionalities only supported in python 2.

like image 208
Pratik Gandhi Avatar asked Jul 23 '16 08:07

Pratik Gandhi


People also ask

Can Windows 10 do text to speech?

Here's how to use this accessibility feature in Windows 10 and Windows 11. Windows has long offered a screen reader and text-to-speech feature called Narrator. This tool can read web pages, text documents, and other files aloud, as well as speak every action you take in Windows.

How do I install text to speech in Python?

There are several APIs available to convert text to speech in Python. One of such APIs is the Google Text to Speech API commonly known as the gTTS API. gTTS is a very easy to use tool which converts the text entered, into audio which can be saved as a mp3 file.


2 Answers

For offline use in Windows, use SAPI directly.

You can use SpVoice.

import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Jumpman Jumpman Jumpman Them boys up to something!")
like image 67
Yugant Hadiyal Avatar answered Sep 30 '22 04:09

Yugant Hadiyal


Have you tried using Google Text-to-Speech via gTTS?

The syntax for using it in Python 3.x is as follows:

from gtts import gTTS
my_tts = "Text you want to process"
tts = gTTS(text=my_tts, lang='en')
tts.save("Absolute/path/to/file.mp3")

Here is the github repo of gTTS.

like image 29
sayan Avatar answered Sep 30 '22 04:09

sayan