Skip to main content

Pyrogram support module for Telegram VoIP Library for Python

Project description

pytgvoip_pyrogram

PyPI

Sample usage of PytgVoIP library with Pyrogram

Hopefully pytgvoip support will be integrated in Pyrogram itself, but this repository would still be available as reference even after merge.

Detailed pytgvoip usage guide is also available here

Community

# making outgoing calls
from pyrogram import Client
from tgvoip_pyrogram import VoIPFileStreamService

app = Client('account')
app.start()

service = VoIPFileStreamService(app, receive_calls=False)
call = service.start_call('@bakatrouble')
call.play('input.raw')
call.play_on_hold(['input.raw'])
call.set_output_file('output.raw')

@call.on_call_ended
def call_ended(call):
    app.stop()

app.idle()
# accepting incoming calls
from pyrogram import Client
from tgvoip_pyrogram import VoIPFileStreamService, VoIPIncomingFileStreamCall

app = Client('account')
app.start()

service = VoIPFileStreamService(app)

@service.on_incoming_call
def handle_call(call: VoIPIncomingFileStreamCall):
    call.accept()
    call.play('input.raw')
    call.play_on_hold(['input.raw'])
    call.set_output_file('output.raw')

    # you can use `call.on_call_ended(lambda _: app.stop())` here instead
    @call.on_call_ended
    def call_ended(call):
        app.stop()

app.idle()

More examples

Requirements

  • Python 3.4 or higher
  • PytgVoIP (listed as dependency)
  • Pyrogram (listed as dependency)

Installing

pip3 install pytgvoip-pyrogram

Encoding audio streams

Streams consumed by libtgvoip should be encoded in 16-bit signed PCM audio.

$ ffmpeg -i input.mp3 -f s16le -ac 1 -ar 48000 -acodec pcm_s16le input.raw  # encode
$ ffmpeg -f s16le -ac 1 -ar 48000 -acodec pcm_s16le -i output.raw output.mp3  # decode

Copyright & License

Download files

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

Files for pytgvoip-pyrogram, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size pytgvoip_pyrogram-0.0.5-py3-none-any.whl (27.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page