•  


Telegram VoIP phone calls Link Search Menu Expand Document

Telegram VoIP phone calls

MadelineProto provides an easy wrapper to work with phone calls.

Full webradio example

Requesting a call

<?
php


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


$MadelineProto
 =
 new
 \danog\MadelineProto\API
(
'session.madeline'
);

$MadelineProto
->
start
();


$call
 =
 $MadelineProto
->
requestCall
(
'@danogentili'
);

The requestCall function accepts one parameter with the ID/username/Peer/User/InputPeer of the person to call, and returns a VoIP object that can be used to play audio files, set the hold files, change the configuration and set the output file (see the VoIP API documentation for more info).

You can play audio files of any format as follows:

Playing audio files

You can play audio files of any format:

<?
php


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


use
 danog\MadelineProto\LocalFile
;


$MadelineProto
 =
 new
 \danog\MadelineProto\API
(
'session.madeline'
);

$MadelineProto
->
start
();


$call
 =
 $MadelineProto
->
requestCall
(
'@danogentili'
);

$call
->
play
(
new
 LocalFile
(
"audio.mp3"
))

     ->
then
(
new
 LocalFile
(
"audio.flac"
))

     ->
then
(
new
 LocalFile
(
"audio.wav"
))

     ->
then
(
new
 LocalFile
(
"audio_with_video.mp4"
));

You can also play remote streams (or simple remote files) by URL:

<?
php


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


use
 danog\MadelineProto\RemoteUrl
;


$MadelineProto
 =
 new
 \danog\MadelineProto\API
(
'session.madeline'
);

$MadelineProto
->
start
();


$call
 =
 $MadelineProto
->
requestCall
(
'@danogentili'
);

$call
->
play
(
new
 RemoteUrl
(
"http://icestreaming.rai.it/1.mp3"
));

You can also play Telegram files, using AMP streams!

Webhost support

Starting from MadelineProto 8, VoIP now works on webhosts, too, thanks to a pure PHP implementation of libtgvoip and a pure PHP OGG demuxer!

The only limitation when running on webhosts is that audio files must be preconverted using by sending them to @libtgvoip_bot ( source code ), or by using the following script on your PC:

<?
php


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


use
 danog\MadelineProto\LocalFile
;


\danog\MadelineProto\Ogg
::
convert
(
new
 LocalFile
(
"in.mp3"
),
 new
 LocalFile
(
"out.ogg"
));

Copy out.ogg to your webhost, and then run this script on your webhost:

<?
php


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


use
 danog\MadelineProto\LocalFile
;


$MadelineProto
 =
 new
 \danog\MadelineProto\API
(
'session.madeline'
);

$MadelineProto
->
start
();


$call
 =
 $MadelineProto
->
requestCall
(
'@danogentili'
);

$call
->
play
(
new
 LocalFile
(
"out.ogg"
));

Accepting calls

Accepting calls is just as easy:

<?
php


declare
(
strict_types
=
1
);


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


use
 danog\MadelineProto\EventHandler\SimpleFilter\Incoming
;

use
 danog\MadelineProto\VoIP
;

use
 danog\MadelineProto\RemoteUrl
;

use
 danog\MadelineProto\EventHandler\Attributes\Handler
;


class
 PonyHandler
 extends
 \danog\MadelineProto\SimpleEventHandler

{

    #[Handler]
    public
 function
 handleIncomingCall
(
VoIP
&
Incoming
 $call
)
:
 void

    {

        $call
->
accept
()
->
play
(
new
 RemoteUrl
(
'http://icestreaming.rai.it/1.mp3'
));

    }

}


PonyHandler
::
startAndLoop
(
'session.madeline'
);

Recording calls

To record the incoming audio stream in a call, simply use setOutput :

<?
php


declare
(
strict_types
=
1
);


if
 (
!
file_exists
(
'madeline.php'
))
 {

    copy
(
'https://phar.madelineproto.xyz/madeline.php'
,
 'madeline.php'
);

}

include
 'madeline.php'
;


use
 danog\MadelineProto\EventHandler\SimpleFilter\Incoming
;

use
 danog\MadelineProto\VoIP
;

use
 danog\MadelineProto\RemoteUrl
;

use
 danog\MadelineProto\LocalFile
;

use
 danog\MadelineProto\EventHandler\Attributes\Handler
;

use
 Amp\ByteStream\WritableStream
;


class
 PonyHandler
 extends
 \danog\MadelineProto\SimpleEventHandler

{

    #[Handler]
    public
 function
 handleIncomingCall
(
VoIP
&
Incoming
 $call
)
:
 void

    {

        $call
->
accept
();

        $call
->
play
(
new
 RemoteUrl
(
'http://icestreaming.rai.it/1.mp3'
));


        $call
->
setOutput
(
new
 LocalFile
(
'output.ogg'
));

        
        // $stream can also be a WritableStream.
        // Can be used to pipe OGG OPUS audio data to ffmpeg, asterisk via amphp/process, amphp/socket, etc...
        //
        //$call->setOutput($stream);
    }

}


PonyHandler
::
startAndLoop
(
'session.madeline'
);

Next section


- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본