Python PJSUA2 : play wave file and record audio example

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all

I am looking for some sample code to perform followin activities in python. I am able to do all these in pjsua and not in pjsua2.

1. How to play a local wavefile to caller (or remove user)
2. How to record only caller audio
3. How to record both audio (in this case outgoing audio will be the wav file being played)

I tired following, but not working

    def onCallState(self, prm):
        ci = self.getInfo()
        self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED
        if(self.connected ==True):
            print("Call started >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
            player=pj.AudioMediaPlayer()
            #Play welcome message
            play_med=ep.Endpoint.instance.audDevManager().getPlaybackDevMedia();
            player.createPlayer('/home/sekar/PJSUA2/example/pygui/welcomeFull.wav');
            #play_med.startTransmit(player);
            i=0
            for media in ci.media:              
                if (media.type == pj.PJMEDIA_TYPE_AUDIO):
                    self.aud_med = self.getMedia(i).;
                    break;
                i=i+1;
 
            if self.aud_med!=None:
                # This will connect the sound device/mic to the call audio media
                play_med.startTransmit(self.aud_med );


I am getting this error

12:01:55.081            pjsua_aud.c  ...Creating file player: /home/sekar/PJSUA2/example/pygui/welcomeFull.wav..
12:01:55.081           wav_player.c  ....File player '/home/sekar/PJSUA2/example/pygui/welcomeFull.wav' created: samp.rate=24000, ch=1, bufsize=4KB, filesize=589KB
12:01:55.081             resample.c  ....resample created: high qualiy, large filter, in/out rate=24000/16000
12:01:55.081             resample.c  ....resample created: high qualiy, large filter, in/out rate=16000/24000
12:01:55.081            pjsua_aud.c  ....Player created, id=0, slot=2
Traceback (most recent call last):
  File "/home/sekar/PJSUA2/example/pygui/call.py", line 69, in onCallState
    play_med.startTransmit(self.aud_med );
  File "/home/sekar/.local/lib/python3.6/site-packages/pjsua2.py", line 3965, in startTransmit
12:01:55.088         strm0x1c61f1c8 !RTP status: badpt=0, badssrc=0, dup=0, outorder=0, probation=-1, restart=0
    return _pjsua2.AudioMedia_startTransmit(self, sink)
TypeError: in method 'AudioMedia_startTransmit', argument 2 of type 'pj::AudioMedia const &'
12:01:55.090          tsx0x1c60a108 !Timeout timer event


This line is giving error

                play_med.startTransmit(self.aud_med );

Thanks
Regards
Sekar
_______________________________________________
Visit our blog: http://blog.pjsip.org

pjsip mailing list
pjsip@xxxxxxxxxxxxxxx
http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux