def build(ttsp, lang='en'): # Build the string text = ttsp[0] + " . call from . " + ttsp[ 1] + ". Building type is " + ttsp[2] + " . " + ttsp[3] # Initiate translator and mixer, create temp file translator = Translator() mixer.init() tf = TemporaryFile() # Add abbreviations to read gtts.tokenizer.symbols.SUB_PAIRS.append(('s.', 'south.')) gtts.tokenizer.symbols.SUB_PAIRS.append(('w.', 'west.')) gtts.tokenizer.symbols.SUB_PAIRS.append(('e.', 'east.')) gtts.tokenizer.symbols.SUB_PAIRS.append(('n.', 'north.')) pre_processors.word_sub(text) # Create the text to speech object tts = gTTS(text=translator.translate(text, dest=lang).text, lang=lang) # Write to a temp file, then read and play tts.write_to_fp(tf) tf.seek(0) playsound(os.path.dirname(os.path.realpath(__file__)) + "/audio/tone.mp3") time.sleep(.35) mixer.music.load(tf) mixer.music.play()
def print_to_stdout(clipboard_content): print("Found text: %s" % str(clipboard_content)) text = str(clipboard_content.split("$$talk$$")[1]) print("Stripped command: %s" % text) subbed = pre_processors.word_sub(text) print("Subbed: {}".format(subbed)) tts = gTTS(subbed, 'en') tts.save("tts.mp3") explosion = pyglet.media.load("tts.mp3", streaming=False) explosion.play()
def talk(text): # we preprocess the word to change the words new_text = pre_processors.word_sub(text) # Language in which you want to convert language = 'fr' # Passing the text and language to the engine, # here we have marked slow=False. Which tells # the module that the converted audio should # have a high speed my_obj = gTTS(text=new_text, lang=language, slow=False) # Saving the converted audio in a mp3 file named # welcome my_obj.save("audio/cmd.mp3") # Playing the converted file os.system("afplay audio/cmd.mp3")
def test_word_sub(self): _in = "M. Bacon" _out = "Monsieur Bacon" self.assertEqual(word_sub(_in), _out)
def test_word_sub(self): _in = "Esq. Bacon" _out = "Esquire Bacon" self.assertEqual(word_sub(_in), _out)
token = 'bearer ' + d['access_token'] base_url = 'https://oauth.reddit.com' headers = {'Authorization': token, 'User-Agent': 'VideoBot by Supleezy'} response = requests.get(base_url + '/api/v1/me', headers=headers) payload = {'t': 'hour', 'limit': 5} r = requests.get(base_url + '/r/' + subreddit + '/top', headers=headers, params=payload) js = r.json() # durationText = '' # mp3List = '' # # gtts.tokenizer.symbols.SUB_PAIRS.append(('&', 'and')) for i in range(js['data']['dist']): print('Starting post ' + str(i+1)) title = js['data']['children'][i]['data']['title'] title = pre_processors.word_sub(title) thumbnail = js['data']['children'][i]['data']['url'] if("imgur" in thumbnail): break print('Downloading Image 👨💻') local_image_filename = wget.download(thumbnail) print('Creating Image 🖼') postImage = Image.open(local_image_filename) img_w, img_h = postImage.size if (img_w > 1500) or (img_h > 1500): print('img_w: ' + str(img_w) + ' --- img_h: ' + str(img_h)) postImage.thumbnail((1500, 1500)) postImage.save(local_image_filename) print('new size: ' + str(postImage.size)) img_w, img_h = (postImage.size)