-
-
Save SatyakiDe2019/33591d0ea1f1a8197f361011d2f98fc1 to your computer and use it in GitHub Desktop.
Main class converting text to voice using third-party API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################### | |
#### Written By: SATYAKI DE #### | |
#### Written On: 27-Oct-2019 #### | |
#### Modified On 28-Jan-2023 #### | |
#### #### | |
#### Objective: Main class converting #### | |
#### text to voice using third-party API. #### | |
############################################### | |
import pyttsx3 | |
from clsConfigClient import clsConfigClient as cf | |
class clsText2Voice: | |
def __init__(self): | |
self.speedSpeech = cf.conf['speedSpeech'] | |
self.speedPitch = cf.conf['speedPitch'] | |
def getAudio(self, srcString): | |
try: | |
speedSpeech = self.speedSpeech | |
speedPitch = self.speedPitch | |
engine = pyttsx3.init() | |
# Set the speed of the speech (in words per minute) | |
engine.setProperty('rate', speedSpeech) | |
# Set the pitch of the speech (1.0 is default) | |
engine.setProperty('pitch', speedPitch) | |
# Converting to MP3 | |
engine.say(srcString) | |
engine.runAndWait() | |
return 0 | |
except Exception as e: | |
x = str(e) | |
print('Error: ', x) | |
return 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment