Library connecting python binding for tgcalls and pyrogram
Project description
Voice chats, private incoming and outgoing calls in Telegram for Developers
Examples
•
Documentation
•
Channel
•
Chat
Telegram WebRTC (VoIP)
from pyrogram import Client, filters
from pyrogram.utils import MAX_CHANNEL_ID
from pytgcalls import GroupCall
app = Client('pytgcalls')
group_call = GroupCall(app, 'input.raw')
@group_call.on_network_status_changed
async def on_network_changed(gc: GroupCall, is_connected: bool):
chat_id = MAX_CHANNEL_ID - gc.full_chat.id
if is_connected:
await app.send_message(chat_id, 'Successfully joined!')
else:
await app.send_message(chat_id, 'Disconnected from voice chat..')
@app.on_message(filters.outgoing & filters.command('join'))
async def join(_, message):
await group_call.start(message.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.
- Work with voice chats in channels and chats.
- Multiply voice chats (example).
- System of custom handlers on events.
- Join as channels or chats.
- Join using invite (speaker) links.
- Speaking status with audio levels inside and outside of voice chat.
- Mute/unmute, pause/resume, stop/play, volume control and more...
Available sources of input/output data transfers
- File (
GroupCall
, playout example, recording example) — to use any audio files including named pipe (FIFO). - Device (
GroupCallDevice
, example) — to use microphone, headphones, etc. - Raw (
GroupCallRaw
, example of restreaming) — to send and receive data inbytes
directly from Python.
Note: All audio data is transmitted in PCM 16 bit, 48k. [Example how to convert files using FFmpeg](All audio information is transmitted in psm 16 bit).
Requirements
- Python 3.6 or higher.
- A Telegram API key.
- x86_64/arm64 platform and Unix system (use WSL for Windows).
TODO list
- Incoming and Outgoing calls (already there and working, but not in release).
- Private and group video calls.
- Python binary wheels for Windows and more...
Installing
pip3 install pytgcalls -U
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
Short answer for linux:
git clone git@github.com:MarshalX/tgcalls.git --recursive
cd tgcalls
For x86_64:
docker-compose up tgcalls_x86_64
For AArch64 (ARM64):
docker-compose up tgcalls_aarch64
Python wheels will be available in dist
folder in root of tgcalls
.
More info:
Also you can investigate into manylinux GitHub Actions builds.
Documentation
Temporarily, instead of documentation, you can use an example along with MTProto.
Documentation
•
PyPi
•
Sources
pytgcalls
This project is implementation of using tgcalls Python binding together with MTProto. A Pyrogram was chosen as a library for working with Telegram Mobile Protocol. You can write your own implementation to work with Telethon or other libraries.
Learning by example
Visit this page to discover the official examples.
Documentation
pytgcalls
's documentation lives at tgcalls.org.
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:
- We have a community of developers helping each other in our Telegram group.
- Report bugs, request new features or ask questions by creating an issue or a discussion.
Contributing
Contributions of all sizes are welcome.
Special thanks to
- @FrayxRulez for amazing code of Unigram.
- @john-preston for Telegram Desktop and tgcalls.
- @bakatrouble for help and inspiration by pytgvoip.
- @delivrance for Pyrogram.
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for pytgcalls-0.0.23-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a7a16f853c8112ec77f90fa6687cc4836688ad93b5eba4d4e95338a1deb913b |
|
MD5 | aea01ffc891748d7784fb8090cf14119 |
|
BLAKE2b-256 | ddbae818b001aaf63dda0c8d2fd851d52e1a0d8835a810668594bc7740a12746 |