Translate any text to Ukrainian voice speech with telegram bot

I present to you a bot for Telegram, which translate your any language text into Ukrainian voice speech🇺🇦!

Try it now >> @inukrainian <<

The following libraries have been used:

  • aiogram – Async telegram bot framework
  • googletrans – google translator ajax api
  • gtts – voice synthesizer from google translator

There is main function code:

async def command_start(message : types.Message):
    userid = message.chat.id
    user_first_name = str(message.chat.first_name)
    user_last_name = str(message.chat.last_name)
    user_username = str(message.chat.username)
    typed = message.text
    translated = translator.translate(typed, dest='uk')
    print(translated.text)
    strippedtext = translated.text[:200]
    myobj = gTTS(text=strippedtext, lang=language, slow=False)
    myobj.save(f"{userid}welcome.mp3")
    os.system(f'cmd /c ffmpeg -i {userid}welcome.mp3 -c:a libopus -b:a 32k -vbr on -compression_level 10 -frame_duration 60 -application voip -y {userid}message.ogg""')
    await bot.send_voice(message.from_user.id, open(f"{userid}message.ogg", "rb"))
    timenow = datetime.now()
    with open(logfilename, 'a', encoding="utf-8") as file_object:
         file_object.write(f'"{timenow}","{userid}","{user_username}","{user_first_name} {user_last_name}","request","{message.text}"\n')
    os.remove(f"{userid}welcome.mp3")
    os.remove(f"{userid}message.ogg")

 

See also  InstagramSizeBot: Empowering Instagram Posts with Square Photos and Small Frames
Author: admin

1 thought on “Translate any text to Ukrainian voice speech with telegram bot

Leave a Reply

Your email address will not be published. Required fields are marked *