Package: yins-music
Voice chats, private incoming and outgoing calls in Telegram for DevelopersExamples•Documentation•Channel•ChatTelegram WebRTC (VoIP)This project consists of two main parts:tgcalls,velar.
The first is a C++ Python extension.
The second uses the extension along with MTProto and provides high level SDK.
All together, it allows you to create userbots that can record and
broadcast in voice chats, make and receive private calls.Fipper's snippetfromfipperimportClient,filtersfromfipper.utilsimportMAX_CHANNEL_IDfromvelarimportGroupCallFactoryapp=Client('velar')group_call=GroupCallFactory(app).get_file_group_call('input.raw')@group_call.on_network_status_changedasyncdefon_network_changed(context,is_connected):chat_id=MAX_CHANNEL_ID-context.full_chat.idifis_connected:awaitapp.send_message(chat_id,'Successfully joined!')else:awaitapp.send_message(chat_id,'Disconnected from voice chat..')@app.on_message(filters.outgoing&filters.command('join'))asyncdefjoin_handler(_,message):awaitgroup_call.start(message.chat.id)app.run()Telethon's snippetfromtelethonimportTelegramClient,eventsfromvelarimportGroupCallFactoryapp=TelegramClient('velar',api_id,api_hash).start()group_call_factory=GroupCallFactory(app,GroupCallFactory.MTPROTO_CLIENT_TYPE.TELETHON)group_call=group_call_factory.get_file_group_call('input.raw')@app.on(events.NewMessage(outgoing=True,pattern=r'^/join$'))asyncdefjoin_handler(event):chat=awaitevent.get_chat()awaitgroup_call.start(chat.id)app.run_until_disconnected()FeaturesPython solution.Prebuilt wheels for macOS, Linux and Windows.Supporting popular MTProto libraries: Fipper, Telethon.Abstract class to implement own MTProto bridge.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 voice activity detection.Mute/unmute, pause/resume, stop/play, volume control and more...Available sources of input/output data transfersRaw (GroupCallRaw,example with pyav,example of restreaming)
— to send and receive data inbytesdirectly from Python.File (GroupCallFile,playout example,recording example)
— to use audio files including named pipe (FIFO).Device (GroupCallDevice,example) —
to use system virtual devices. Please don't use it with real microphone, headphones, etc.Note: All audio data is transmitted in PCM 16 bit, 48k.Example how to convert files using FFmpeg.RequirementsPython 3.7 or higher.ATelegram API key.TODO listIncoming and Outgoing private calls
(already there and working, but not in the release version).Group Video Callsand more...InstallingFor Fipperpip3install-Uvelar[pyrogram]For Telethonpip3install-Uvelar[telethon]PyPi•SourcestgcallsThe first part of the project is C++ extensions for Python.Pybind11was used to write it. Binding occurs to thetgcallslibrary by Telegram, which is used in all official clients.
To implement the binding, the code of Telegram Desktop and Telegram Android was studied.
Changes have been made to the Telegram library.
All modified code isavailable as a subtreein this repository. The main ideas of the changes is to improve
the sound quality and to add ability to work with third party audio device modules.
In addition, this binding implemented custom audio modules. These modules are allowing
transfer audio data directly from Python via bytes, transfer and control
the playback/recording of a file or a virtual system device.How to buildShort answer for Linux:gitclonegit@github.com:MarshalX/tgcalls.git--recursivecdtgcallsFor x86_64:docker-composeuptgcalls_x86_64For AArch64 (ARM64):docker-composeuptgcalls_aarch64Python wheels will be available indistfolder in root oftgcalls.More info:Manylinux.Ubuntu.macOS.Windows.Also, you can investigate intomanylinux GitHub Actions builds.DocumentationTemporarily, instead of documentation, you can usean examplealong with MTProto.Documentation•PyPi•SourcesvelarThis project is implementation of usingtgcallsPython binding together withMTProto.
By default, this library are supportsFipperandTelethonclients for working
with Telegram Mobile Protocol.
You can write your own implementation of abstract class to work with other libraries.Learning by exampleVisitthis pageto discover the official examples.Documentationvelar's documentation lives attgcalls.org.Audio file formatsRAW files are now used. You will have to convert to this format yourself
using ffmpeg. The example how to transcode files from a code is availablehere.From mp3 to raw (to play in voice chat):ffmpeg -i input.mp3 -f s16le -ac 2 -ar 48000 -acodec pcm_s16le input.rawFrom raw to mp3 (files with recordings):ffmpeg -f s16le -ac 2 -ar 48000 -acodec pcm_s16le -i output.raw clear_output.mp3For 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.rawFor 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.rawAnd set input.raw as input filename.Getting helpYou can get help in several ways:We have a community of developers helping each other in ourTelegram group.Report bugs, request new features or ask questions by creatingan issueora discussion.ContributingContributions of all sizes are welcome.Special thanks to@FrayxRulezfor amazing code ofUnigram.@john-prestonforTelegram Desktopandtgcalls.@bakatroublefor help and inspiration bypytgvoip.@delivranceforFipper.@LonamiforTelethon.LicenseYou may copy, distribute and modify the software provided that modifications
are described and licensed for free underLGPL-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.