-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.py
41 lines (31 loc) · 906 Bytes
/
audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import math
import pyttsx3
from gtts import gTTS
import soundfile as sf
class GTTS:
def generate(self, text, filePath):
try:
audioFile = gTTS(text=text, lang='en', slow=False)
audioFile.save(filePath)
return True
except:
return False
class PyTTSX3:
def generate(self, text, filePath):
try:
engine = pyttsx3.init()
engine.save_to_file(text, filePath)
engine.runAndWait()
return True
except:
return False
class AudioUtils:
@staticmethod
def calculateDuration(audioFilePath: str):
f = sf.SoundFile(audioFilePath)
return math.ceil(len(f)/f.samplerate)
class TTS:
def __init__(self, generator):
self.generator = generator
def generate(self, text, filePath):
return self.generator.generate(text, filePath)