Skip to content

Reverse Voice and Sound Messages using Telegram Messenger Bot

License

Notifications You must be signed in to change notification settings

cryophyte/barax_bot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Barax bot

Smiley face

A Telegram Voice/Sound Reverse Bot

A simple telegram bot written in python to reverse voice messages it recieves.

Test:

You can use this link to test the bot.

Installation and Usage:

Before anything you can clone the repository using:

git clone https://github.com/pharzan/barax_bot.git

Get a Token:

  1. Using the bot father create a Telegram bot to obtain a Token explained here. The bot father will chat with you through the process of obtaining a token. Then replace the obtained token in the source code. The token should look something like this:
123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ

Install required packages

  1. Install Telepot for Python to use the Telegram API in python.
pip install telepot
pip install telepot --upgrade  # UPGRADE

Or using Easy install:

easy_install telepot
easy_install --upgrade telepot  # UPGRADE
  1. Use python to run the script.
python barax_bot.py

How it works:

The bot uses subprocesses in python to execute a ffmpeg, handy Linux utility for audio and video.

The bot listens to any messages that are recieved.

    def on_chat_message(self, msg):
        content_type, chat_type, chat_id, msg_date, msg_id = telepot.glance(msg,flavor='chat',long=True)

If the recieved message is a voice message and the duration is less than 30 seconds it downloads the file.

file_name = msg['voice']['file_id']
bot.download_file(msg['voice']['file_id'],"{0}.ogg".format(file_name))

Finally it executes ffmpeg in the shell to simply reverses the ogg file and creates an MP3 to send to the user.

shell_cmd = "yes y | ffmpeg -i {0} -vf reverse -af areverse -f mp3 {1}.mp3".format(my_file,file_name)
p = subprocess.Popen(shell_cmd, shell=True,stdout=subprocess.PIPE)
....
bot.sendVoice(chat_id,open(file_name+'.mp3', 'rb'))

Notice: The chat ID is a unique ID created by Telegram which is an identifier between the bot and user chat.

About

Reverse Voice and Sound Messages using Telegram Messenger Bot

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%