Exporting text to speech in mp3 form, using python, David and Zira

488 Views Asked by At

I had to use text to speech recently on python. This code worked just fine.

import pyttsx3
converter = pyttsx3.init()
converter.setProperty('rate', 150)
converter.setProperty('volume', 0.7)


# For Zira's voice uncomment this part of code
# voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"

# converter.setProperty('voice', voice_id)

converter.say("Hello I convert text to speech")
converter.say("I am Zira")

Now I want to output whatever text I gave to it in mp3 form i.e. "Hello David" would be saved in mp3 file.

from gtts import gTTS
from playsound import  playsound

mytext="Hello Geek! How are you doing??"
language='en'
myobj=gTTS(text=mytext,lang=language,slow=False)
myobj.save("welcome1.mp3")
playsound("welcome1.mp3")

This code works great excluding the fact the voice used is neither of Zira nor David.

How can I make to export text in voice of David/Zira?

Couldn't find in docs so posted here.

0

There are 0 best solutions below