Skip to content

Commit

Permalink
add examples;
Browse files Browse the repository at this point in the history
write a readme;
add logo;
improve setup files;
add LICENSE to packages;
use QEMU only for aarch64 builds;
run workflows only on main branch;
remove the need for a running pyrogram client to create a GroupCall;
add lfs;
bump version to 0.0.2.
  • Loading branch information
MarshalX committed Mar 1, 2021
1 parent c9a7d20 commit 97b95e9
Show file tree
Hide file tree
Showing 21 changed files with 634 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.raw filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions .github/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions .github/images/pytgcalls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions .github/images/tgcalls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build and publish wheels for Linux and many Python versions
on:
push:
branches:
- main
paths:
- '.github/workflows/build_and_publish_python_wheels_for_many_versions.yaml'
- 'setup.py'
Expand All @@ -17,30 +19,15 @@ jobs:
submodules: recursive
- name: Build for x86_64
run: |
# Enable docker daemon support for --platform parameter
echo '{"experimental": true}' | sudo tee /etc/docker/daemon.json > /dev/null
sudo systemctl restart docker
# Configure qemu-user-static
docker run --rm --tty \
--security-opt apparmor:unconfined \
--cap-add SYS_ADMIN \
multiarch/qemu-user-static --reset -p yes
docker run --rm \
--security-opt apparmor:unconfined \
--cap-add SYS_ADMIN \
--device /dev/fuse \
--volume /sys \
--volume /sys/fs/cgroup:/sys/fs/cgroup:ro \
--volume $GITHUB_WORKSPACE:/github/workspace \
--workdir $GITHUB_WORKSPACE \
--platform "linux/amd64" \
ghcr.io/marshalx/tgcalls/manylinux2014_x86_64-webrtc-entrypoint:latest \
"cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39" \
"manylinux2014_x86_64" \
${{ secrets.PYPI_USERNAME }} \
${{ secrets.PYPI_PASSWORD }}
docker run --rm \
--volume "${GITHUB_WORKSPACE}":/github/workspace:rw \
--workdir=/github/workspace \
-e GITHUB_WORKSPACE=/github/workspace \
ghcr.io/marshalx/tgcalls/manylinux2014_x86_64-webrtc-entrypoint:latest
"cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39" \
"manylinux2014_x86_64" \
${{ secrets.PYPI_USERNAME }} \
${{ secrets.PYPI_PASSWORD }}
- name: Build for aarch64
run: |
# Enable docker daemon support for --platform parameter
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build_and_push_manylinux_images.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build manylinux with dependencies and deploy images to GitHub Packages
on:
push:
branches:
- main
paths:
- '.github/workflows/build_and_push_manylinux_images.yaml'
- 'build/manylinux/Dockerfile'
Expand All @@ -20,6 +22,7 @@ jobs:
with:
submodules: recursive
- name: Set up QEMU
if: matrix.manylinux_tag == 'manylinux2014_aarch64'
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build manylinux with dependencies, WebRTC and entrypoint. Deploy images to GitHub Packages
on:
push:
branches:
- main
paths:
- '.github/workflows/build_and_push_manylinux_webrtc_entrypoint_images.yaml'
- 'build/manylinux/Dockerfile'
Expand All @@ -24,6 +26,7 @@ jobs:
with:
submodules: recursive
- name: Set up QEMU
if: matrix.manylinux_tag == 'manylinux2014_aarch64'
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build_and_push_manylinux_webrtc_images.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Build manylinux with dependencies and WebRTC. Deploy images to GitHub Packages
on:
push:
branches:
- main
paths:
- '.github/workflows/build_and_push_manylinux_images.yaml'
- 'build/manylinux/Dockerfile'
Expand All @@ -22,6 +24,7 @@ jobs:
with:
submodules: recursive
- name: Set up QEMU
if: matrix.manylinux_tag == 'manylinux2014_aarch64'
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE
212 changes: 182 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,200 @@
# Telegram WebRTC (VoIP)
<p align="center">
<a href="https://github.com/MarshalX/tgcalls">
<img src=".github/images/logo.png" alt="tgcalls">
</a>
<br>
<b>Voice chats, private incoming and outgoing calls in Telegram for Developers</b>
<br>
<a href="https://github.com/MarshalX/tgcalls/tree/main/examples">
Examples
</a>
<a href="https://t.me/tgcallslib">
Channel
</a>
<a href="https://t.me/tgcallschat">
Chat
</a>
</p>

Incoming, outgoing and video calls, voice chats in Telegram for developers
and their projects (user bots).
## Telegram WebRTC (VoIP)

![Python 3.6+](https://img.shields.io/badge/python-3.6+-blue.svg)
![License LGPLv3](https://img.shields.io/badge/license-LGPLv3-lightgrey.svg)
```python
from pyrogram import Client, filters
from pytgcalls import GroupCall

**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 chat
app = Client('pytgcalls')
group_call = GroupCall(app, 'input.raw')

**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
- macOS Python wheels

## Table of contents
- [tgcalls](#tgcalls)
- [pytgcalls](#pytgcalls)
- [Getting help](#getting-help)
- [License](#license)
@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)

## tgcalls ![tgcalls pypi](https://img.shields.io/pypi/v/tgcalls.svg)

## pytgcalls ![pytgcalls pypi](https://img.shields.io/pypi/v/pytgcalls.svg)
app.run()

## Getting help
```

This project consists of two main parts: [tgcalls](#tgcalls), [pytgcalls](#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](https://docs.pyrogram.org/intro/setup#api-keys).
- 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...](https://github.com/MarshalX/tgcalls/issues)

### Installing

``` bash
pip3 install pytgcalls
```

<hr>
<p align="center">
<a href="https://github.com/MarshalX/tgcalls">
<img src=".github/images/tgcalls.png" alt="tgcalls">
</a>
<br>
<a href="https://pypi.org/project/tgcalls/">
PyPi
</a>
<a href="https://github.com/MarshalX/tgcalls/tree/main/tgcalls">
Sources
</a>
</p>

## tgcalls

The first part of the project is C++ extensions for Python. [Pybind11](https://github.com/pybind/pybind11)
was used to write it. Binding occurs to the [tgcalls](https://github.com/TelegramMessenger/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](https://github.com/MarshalX/tgcalls/tree/main/tgcalls/third_party/lib_tgcalls)
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](https://github.com/MarshalX/tgcalls/tree/main/tgcalls/third_party/webrtc).

### How to build

- [Linux](build/ubuntu).
- [macOS](build/macos).
- [Windows](build/windows).

Also you can investigate into [manylinux builds](build/manylinux).

### Documentation

Temporarily, instead of documentation, you can use [an example](pytgcalls/pytgcalls)
along with MTProto.

<hr>
<p align="center">
<a href="https://github.com/MarshalX/tgcalls">
<img src=".github/images/pytgcalls.png" alt="tgcalls">
</a>
<br>
<a href="https://pypi.org/project/pytgcalls/">
PyPi
</a>
<a href="https://github.com/MarshalX/tgcalls/tree/main/pytgcalls">
Sources
</a>
</p>

## pytgcalls

This project is for the most part an example for using [tgcalls](#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](examples/playout.py)
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](https://github.com/MarshalX/tgcalls/issues/15).

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](https://t.me/tgcallschat). Join us!
[Telegram group](https://t.me/tgcallschat).
- Report bugs, request new features or ask questions by creating
[an issue](https://github.com/MarshalX/tgcalls/issues/new) or
[a discussion](https://github.com/MarshalX/tgcalls/discussions/new).

## License
### Contributing

Contributions of all sizes are welcome.

### Special thanks to

- [@FrayxRulez](https://github.com/FrayxRulez) for amazing code of [Unigram](https://github.com/UnigramDev/Unigram).
- [@john-preston](https://github.com/john-preston) for [Telegram Desktop](https://github.com/telegramdesktop/tdesktop) and [tgcalls](https://github.com/TelegramMessenger/tgcalls).
- [@bakatrouble](https://github.com/bakatrouble/) for help and inspiration by [pytgvoip](https://github.com/bakatrouble/pytgvoip).
- [@delivrance](https://github.com/delivrance) for [Pyrogram](https://github.com/pyrogram/pyrogram).

### License

You may copy, distribute and modify the software provided that modifications
are described and licensed for free under [LGPL-3](https://www.gnu.org/licenses/lgpl-3.0.html).
Expand Down
10 changes: 5 additions & 5 deletions build/windows/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Just use WSL

Otherwise, you will have to do it yourself.
Links that will help you build on Windows:
- [Build instruction for macOS](../macos)
- [Telegram Desktop build instructions for Visual Studio 2019 for 64 bit ](https://github.com/telegramdesktop/tdesktop/blob/dev/docs/building-msvc-x64.md)
Links that will help you build on Windows
- [Build instruction for macOS](../macos).
- [Telegram Desktop build instructions for Visual Studio 2019 for 64 bit ](https://github.com/telegramdesktop/tdesktop/blob/dev/docs/building-msvc-x64.md).

Your contribution as building instructions on Windows is appreciated!
It's even better if you do a GitHub workflow.
- [A GitHub Action to facilitate configuring MSBuild in the workflow PATH for building .NET Framework applications](https://github.com/microsoft/setup-msbuild)
- [Example of CI scripts for Windows](https://github.com/bakatrouble/pytgvoip/tree/master/ci_scripts)
- [A GitHub Action to facilitate configuring MSBuild in the workflow PATH for building .NET Framework applications](https://github.com/microsoft/setup-msbuild).
- [Example of GitHub Windows workflow](https://github.com/telegramdesktop/tdesktop/blob/dev/.github/workflows/win.yml).
Loading

0 comments on commit 97b95e9

Please sign in to comment.