async def text_to_speech(message: Message): req_file_name = "gtts.mp3" inp_text = message.input_str if ("|" not in inp_text) or not inp_text: await message.edit("Pathetic") return await message.edit("Processing.") def_lang = "en" def_lang, text = inp_text.split("|") try: await message.edit("Processing..") speeched = gTTS(text, lang=def_lang.strip()) speeched.save(req_file_name) await message.edit("Processing...") meta = XMan(CPR(req_file_name)) a_len = 0 a_title = "Text To Speech" a_perf = "Google" a_cap = f"Language Code: {def_lang}" if meta and meta.has("duration"): a_len = meta.get("duration").seconds await message.edit("Uploading...") await message.reply_audio( audio=req_file_name, caption=a_cap, duration=a_len, performer=a_perf, title=a_title ) os.remove(req_file_name) await message.delete() except Exception as err: await message.edit(err)
async def ss_gen(message: Message): replied = message.reply_to_message vid_loc = "" ss_c = 5 should_clean = False await message.edit("Checking you Input?🧐🤔😳") if message.input_str: if "|" in message.input_str: ss_c, vid_loc = message.input_str.split("|") elif len(message.input_str.split()) == 1: try: ss_c = int(message.input_str) except ValueError: vid_loc = message.input_str should_clean = False if not vid_loc and replied: if not (replied.video or replied.animation): await message.edit("I doubt it is a video") return await message.edit("Downloading Video to my Local") vid = await message.client.download_media( message=replied, file_name=Config.DOWN_PATH, progress=progress, progress_args=(message, "Downloading🧐? W8 plox"), ) vid_loc = os.path.join(Config.DOWN_PATH, os.path.basename(vid)) should_clean = True await message.edit("Compiling Resources") meta = XMan(CPR(vid_loc)) if meta and meta.has("duration"): vid_len = meta.get("duration").seconds else: await message.edit("Something went wrong, Not able to gather metadata") return await message.edit("Done, Generating Screen Shots and uploading") try: for frames in random.sample(range(vid_len), int(ss_c)): capture = await take_screen_shot(vid_loc, int(frames), "ss_cap.jpeg") await message.client.send_photo(chat_id=message.chat.id, photo=capture) os.remove(capture) await message.edit("Uploaded") except Exception as e: await message.edit(e) if should_clean: os.remove(vid_loc) await asyncio.sleep(0.5) await message.delete()
async def text_to_speech(message: Message): req_file_name = "gtts.mp3" reply = message.reply_to_message input_str = message.input_str def_lang = "en" text = "" if input_str: input_str = input_str.strip() if reply: if ((reply.text or reply.caption) and len(input_str.split()) == 1 and input_str.startswith("-")): def_lang = input_str[1:] text = reply.text or reply.caption else: i_split = input_str.split(None, 1) if len(i_split) == 2 and i_split[0].startswith("-"): def_lang = i_split[0][1:] text = i_split[1] else: text = input_str elif reply and (reply.text or reply.caption): text = reply.text or reply.caption if not text: await message.err( ":: Input Not Found ::\nProvide text to convert to voice !", del_in=7) return try: await message.edit("Processing..") speeched = gTTS(text, lang=def_lang) speeched.save(req_file_name) meta = XMan(CPR(req_file_name)) a_len = 0 a_cap = f"Language Code: **{def_lang.upper()}**" if meta and meta.has("duration"): a_len = meta.get("duration").seconds await message.edit("Uploading...") await message.client.send_voice( chat_id=message.chat.id, voice=req_file_name, caption=a_cap, duration=a_len, reply_to_message_id=reply.message_id if reply else None, ) os.remove(req_file_name) await message.delete() except Exception as err: await message.err(str(err))
async def text_to_speech(message: Message): req_file_name = "gtts.mp3" replied = message.reply_to_message def_lang = "en" if replied and replied.text: text = replied.text if message.input_str: def_lang = message.input_str elif message.input_str: if '|' in message.input_str: def_lang, text = message.input_str.split("|", maxsplit=1) else: text = message.input_str else: return await message.err("Input not found!") await message.edit("Processing.") try: await message.edit("Processing..") speeched = gTTS(text.strip(), lang=def_lang.strip()) speeched.save(req_file_name) await message.edit("Processing...") meta = XMan(CPR(req_file_name)) a_len = 0 a_title = "Text To Speech" a_perf = "Google" a_cap = f"Language Code: {def_lang}" if meta and meta.has("duration"): a_len = meta.get("duration").seconds await message.edit("Uploading...") await message.reply_audio(audio=req_file_name, caption=a_cap, duration=a_len, performer=a_perf, title=a_title) os.remove(req_file_name) await message.delete() except Exception as err: await message.edit(err)