def save_google_tts(local_share, tts_string, tts_language, quota): size = int(get_folder_size(local_share) / 1024 / 1024) if size == 0: size = 1 if quota < size: # since this is a const value, no more files will be written (only this mp3 onetime) tts_language = 'en' tts_string = 'Cannot save file. File size quota exceeded!' tts = gTTS(text=tts_string, lang=tts_language) base64_name = base64.urlsafe_b64encode('{}__{}'.format(tts_language, tts_string).encode('utf-8')).decode('ascii', '') fname = '{}.mp3'.format(base64_name) abs_fname = os.path.join(local_share, fname) # check if file exists, no need to browse google tts if os.path.exists(abs_fname): return fname try: tts.save(abs_fname) return os.path.split(abs_fname)[1] except requests.RequestException as e: raise ("Couldn't obtain TTS from Google.\nError: {}".format(e.errno))
def stream_google_tts(tts_string, tts_language): tts = gTTS(text=tts_string, lang=tts_language) tts.stream()