async def handler(event): try: chat = await event.get_chat() await event.delete() async with client.action(chat, 'record-voice'): origin_text = event.message.text.replace('!d ', '') voicename, _duration = speech.demon(origin_text) chat = await event.get_chat() wafe_form = speech.get_waveform(0, 31, 100) await client.send_file(chat, voicename, reply_to=event.message.reply_to_msg_id, attributes=[ types.DocumentAttributeAudio( duration=_duration, voice=True, waveform=utils.encode_waveform( bytes(wafe_form))) ]) # 2**5 because 5-bit speech.try_delete(voicename) except Exception as e: print(e)
async def voice(event): if environ.get("isSuspended") == "True" or environ.get( "BG_DEFAULT") == 0 or environ.get( "BG_DEFAULT") == '0' or environ.get("BG_DEFAULT") == None: return is_enabled = environ.get("enabled", "True") if is_enabled == "True": if event.forward: return if event.voice: chat = await event.get_chat() await event.delete() async with event.client.action(chat, 'record-voice'): path_to_voice = await event.download_media() voicename, _duration = speech.megre_sounds( path_to_voice, environ["BG_DEFAULT"]) chat = await event.get_chat() wafe_form = speech.get_waveform(0, 31, 100) await event.client.send_file( chat, voicename, reply_to=event.message.reply_to_msg_id, attributes=[ types.DocumentAttributeAudio( duration=_duration, voice=True, waveform=utils.encode_waveform(bytes(wafe_form))) ]) # 2**5 because 5-bit speech.try_delete(voicename)
async def voice_note(event): if environ.get("isSuspended") == "True": return try: chat = await event.get_chat() await event.delete() async with event.client.action(chat, 'record-voice'): origin_text = event.message.text.replace('.a ', '') voicename, _duration = speech.syntese(origin_text, background=True) chat = await event.get_chat() wafe_form = speech.get_waveform(0, 31, 100) await event.client.send_file( chat, voicename, reply_to=event.message.reply_to_msg_id, attributes=[ types.DocumentAttributeAudio( duration=_duration, voice=True, waveform=utils.encode_waveform(bytes(wafe_form))) ]) # 2**5 because 5-bit speech.try_delete(voicename) except Exception as e: print(e)
async def handler(event): if event.voice: chat = await event.get_chat() await event.delete() async with client.action(chat, 'record-voice'): path_to_voice = await event.download_media() voicename, _duration = speech.megre_sounds(path_to_voice) chat = await event.get_chat() wafe_form = speech.get_waveform(0, 31, 100) await client.send_file(chat, voicename, reply_to=event.message.reply_to_msg_id, attributes=[ types.DocumentAttributeAudio( duration=_duration, voice=True, waveform=utils.encode_waveform( bytes(wafe_form))) ]) # 2**5 because 5-bit speech.try_delete(voicename)
async def bruh(event): if environ.get("isSuspended") == "True": return await event.delete() wafe_form = speech.get_waveform(0, 31, 100) duration_ = int(os.popen("ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 'media/bruh.ogg'").read().split('.')[0]) await event.client.send_file(event.chat_id, 'media/bruh.ogg', reply_to = event.message.reply_to_msg_id, attributes=[types.DocumentAttributeAudio(duration=duration_, voice=True, waveform=utils.encode_waveform(bytes(wafe_form)))]) # 2**5 because 5-bit
async def handler(event: events.NewMessage.Event): try: chat = await event.get_chat() await event.delete() async with client.action(chat, 'record-voice'): origin_text = event.message.text.replace('!a', '').strip() if event.message.is_reply and origin_text == '': msg = await event.message.get_reply_message() origin_text = msg.text voicename, _duration = speech.syntese(origin_text, background = True) chat = await event.get_chat() wafe_form = speech.get_waveform(0, 31, 100) await client.send_file(chat, voicename, reply_to = event.message.reply_to_msg_id, attributes=[types.DocumentAttributeAudio(duration=_duration, voice=True, waveform=utils.encode_waveform(bytes(wafe_form)))]) # 2**5 because 5-bit speech.try_delete(voicename) except Exception as e: print(e)