Untitled

mail@pastecode.io avatar
unknown
python
6 days ago
812 B
1
Indexable
Never
from gtts import gTTS
from IPython.display import Audio, display
import os
from pydub import AudioSegment

def generate_speech(text, lang='en', tld='com', slow=False, lang_check=True,name=None):
    tts = gTTS(text=text, lang=lang, tld=tld, slow=slow, lang_check=lang_check,)
    if name is None:
      name = 'output.mp3'
      tts.save(name)
    else:
      name = name+'.mp3'
      tts.save(name)
    sound = AudioSegment.from_mp3(name)
    sound.export("output.wav", format="wav")
    display(Audio("output.wav", autoplay=True))
    os.remove(name)

def activateTTS(text,choose_lang):
  lang = {"hebrew":"iw","english":"en"}
  generate_speech(text,lang=lang[choose_lang], tld='com',slow=False,lang_check=True,name='test')


text = "מה הולך אחי"
activateTTS(text,"hebrew")
Leave a Comment