Wednesday, May 31, 2017

Text to Speech

From the command prompt, in the below directory where pip exists and install gTTS, os, pygame one by one.

C:\Python27\Scripts> pip install gTTS

after successful completion.

C:\Python27\Scripts> pip install os

after successful completion.

C:\Python27\Scripts> pip install pygame


Below is the script to convert 'Hello World' text to audio. Save it in sayhelloworld.py and run using python.

C:\Python27> python C:\Users\kartheek.dachepalli\Desktop\PYTHON\Texttospeech.py


Texttospeech.py script:

from gtts import gTTS
import os
import pygame

tts = gTTS(text='Hello World', lang='en')
tts.save("hello_World.mp3")
print "saved"
pygame.mixer.init()
pygame.mixer.music.load('hello_World.mp3')
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() :
    pygame.time.Clock().tick(10)


Output:
You will listen Hello World voice along with below output.

No comments:

Post a Comment