Skip to main content

Library connecting python binding for tgcalls and pyrogram

Project description

tgcalls
Voice chats, private incoming and outgoing calls in Telegram for Developers
Examples Channel Chat

Telegram WebRTC (VoIP)

from pyrogram import Client, filters
from pytgcalls import GroupCall

app = Client('pytgcalls')
group_call = GroupCall(app, 'input.raw')


@app.on_message(filters.private & filters.command('join'))
async def join(client, message):
    if len(message.command) < 2:
        await message.reply_text('You forgot to input chat id')
    else:
        chat_id = message.command[1]
        await group_call.start(chat_id)


app.run()

This project consists of two main parts: tgcalls, pytgcalls. The first is a C++ Python extension. The second uses the extension along with Pyrogram. All together, it allows you to create userbots that can record and broadcast in voice chats, make and receive private calls.

Features

  • Python solution.
  • Join to voice chats.
  • Payout from file.
  • Output (recording) to file.
  • Change files at runtime.
  • Speaking status with levels inside and outside of VC.
  • Stop payout/output.
  • Multiply chats.

Requirements

  • Python 3.6 or higher.
  • A Telegram API key.
  • x86_64 platform and Unix system (WSL for Windows).

TODO list

  • Incoming and Outgoing calls (already there and working, but not in release).
  • Video calls (video from/to a file etc).
  • Additional things for working with ffmpeg.
  • Convenient callbacks and methods.
  • Windows and macOS Python wheels and more...

Installing

pip3 install pytgcalls

tgcalls
PyPi Sources

tgcalls

The first part of the project is C++ extensions for Python. Pybind11 was used to write it. Binding occurs to the tgcalls library by Telegram, which is used in all clients. To implement the library, the code of official clients (tdesktop and android) was studied. Changes have been made to the Telegram library. All modified code is available as a subtree in this repository. The main idea of the changes is to add the ability to play from other sources (from a file, for example) and improve the sound quality by making the minimum number of code edits for a simple update. In addition to changes in the Telegram library, a minimal change was made to the WebRTC, also available as a subtree.

How to build

Also you can investigate into manylinux builds.

Documentation

Temporarily, instead of documentation, you can use an example along with MTProto.


pytgcalls
PyPi Sources

pytgcalls

This project is for the most part an example for using tgcalls Python binding together with MTProto. A Pyrogram was chosen as a library for working with MTProto. You can easily write your own implementation to work with Telethon.

Documentation

Temporarily, instead of documentation, you can use an example describing the methods. There are not many of them.

Audio file formats

RAW files are now used. You will have to convert to this format yourself using ffmpeg. This procedure may become easier in the future.

From mp3 to raw (to play in voice chat):

ffmpeg -i input.mp3 -f s16le -ac 2 -ar 48000 -acodec pcm_s16le input.raw

From raw to mp3 (files with recordings):

ffmpeg -f s16le -ac 2 -ar 48000 -acodec pcm_s16le -i output.raw clear_output.mp3

For playout live stream you can use this one:

ffmpeg -y -i http://stream2.cnmns.net/hope-mp3 -f s16le -ac 2 -ar 48000 -acodec pcm_s16le input.raw

For YouTube videos and live streams you can use youtube-dl:

ffmpeg -i "$(youtube-dl -x -g "https://youtu.be/xhXq9BNndhw")" -f s16le -ac 2 -ar 48000 -acodec pcm_s16le input.raw

And set input.raw as input filename.


Getting help

You can get help in several ways:

Contributing

Contributions of all sizes are welcome.

Special thanks to

License

You may copy, distribute and modify the software provided that modifications are described and licensed for free under LGPL-3. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL-3, but applications that use the library don't have to be.

Project details


Release history Release notifications | RSS feed

This version

0.0.8

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pytgcalls-0.0.8-py3-none-any.whl (14.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page