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.
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
Hi
After going thru pygui code, I modified the example as below. I have two issues
Note: I am having issues in replying to same thread. So opened a Stakeworkflow query for same. If this time also, it created to new thread, I will continue to use stakeworkflow
Stackoverflow link: https://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
[https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded]https://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
PJSUA2 - Python - How to handle callbacks and createRecorder? - Stack Overflowhttps://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.
stackoverflow.com
-----------------------------Modified code --------------
import pjsua2 as pj
import time
ep=None
class Call(pj.Call):
"""
High level Python Call object, derived from pjsua2's Call object.
"""
def init(self, acc, peer_uri='', chat=None, call_id = pj.PJSUA_INVALID_ID):
pj.Call.init(self, acc, call_id)
self.acc = acc
self.aud_med=pj.AudioMedia
def onCallState(self, prm):
ci = self.getInfo()
self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED
self.recorder=None
if(self.connected ==True):
player=pj.AudioMediaPlayer()
#Play welcome message
player.createPlayer('xxxxxxxxxxxxxx/PJSUA2/example/pygui/welcomeFull.wav');
self.recorder=pj.AudioMediaRecorder()
#self.recorder.createRecorder('xxxxxxxxxxx/PJSUA2/example/pygui/file.wav', enc_type=0, max_size=0, options=0);
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
mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
player.startTransmit( mym);
#mym.startTransmit( self.recorder);
if(ci.state==pj.PJSIP_INV_STATE_DISCONNECTED):
print(">>>>>>>>>>>>>>>>>>>>>>> Call disconnected")
#mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
#mym.stopTransmit(self.recorder);
raise Exception('onCallState done!')
if self.chat:
self.chat.updateCallState(self, ci)
def onCallMediaState(self, prm):
ci = self.getInfo()
for mi in ci.media:
if mi.type == pj.PJMEDIA_TYPE_AUDIO and \
(mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE or \
mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD):
if mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD and not self.onhold:
self.chat.addMessage(None, "'%s' sets call onhold" % (self.peerUri))
self.onhold = True
elif mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE and self.onhold:
self.chat.addMessage(None, "'%s' sets call active" % (self.peerUri))
self.onhold = False
raise Exception('onCallMediaState done!')
class Account(pj.Account):
def onRegState(self, prm):
print ("***OnRegState: " + prm.reason)
def onIncomingCall(self, prm):
c = Call(self, call_id=prm.callId)
call_prm = pj.CallOpParam()
call_prm.statusCode = 180
c.answer(call_prm)
ci = c.getInfo()
msg = "Incoming call from '%s'" % (ci.remoteUri)
print(msg)
call_prm.statusCode = 200
c.answer(call_prm)
raise Exception('onIncomingCall done!')
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep_cfg.uaConfig.threadCnt = 0
ep_cfg.uaConfig.mainThreadOnly = False
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig();
sipTpConfig.port = 12345;
tp=ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig);
# Start the library
ep.libStart();
acfg = pj.AccountConfig();
acfg.idUri = "sip:192.168.1.11:12345";
# Create the account
acc = Account();
acc.create(acfg)
while True:
ep.libHandleEvents(10)
ep.libDestroy()
del ep;
if name == "main":
pjsua2_test()
Hi all
Able to resolve 1st issue, by shifting call.answer to main thread. Struck with second issue, i.e how to create recorder to record to a wave file. Any help is welcome.
recorder=pj.AudioMediaRecorder()
recorder.createRecorder('xxxxxxxxxxx/PJSUA2/example/pygui/file.wav');
Thanks.
Sekar.
From: Sekar S sekarpdkt@hotmail.com
Sent: Thursday, January 3, 2019 10:04 PM
To: pjsip@lists.pjsip.org
Subject: Re: [pjsip] Python PJSUA2 : play wave file and record audio example
Hi
After going thru pygui code, I modified the example as below. I have two issues
Note: I am having issues in replying to same thread. So opened a Stakeworkflow query for same. If this time also, it created to new thread, I will continue to use stakeworkflow
Stackoverflow link: https://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
[https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded]https://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
PJSUA2 - Python - How to handle callbacks and createRecorder? - Stack Overflowhttps://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.
stackoverflow.com
-----------------------------Modified code --------------
import pjsua2 as pj
import time
ep=None
class Call(pj.Call):
"""
High level Python Call object, derived from pjsua2's Call object.
"""
def init(self, acc, peer_uri='', chat=None, call_id = pj.PJSUA_INVALID_ID):
pj.Call.init(self, acc, call_id)
self.acc = acc
self.aud_med=pj.AudioMedia
def onCallState(self, prm):
ci = self.getInfo()
self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED
self.recorder=None
if(self.connected ==True):
player=pj.AudioMediaPlayer()
#Play welcome message
player.createPlayer('xxxxxxxxxxxxxx/PJSUA2/example/pygui/welcomeFull.wav');
self.recorder=pj.AudioMediaRecorder()
#self.recorder.createRecorder('xxxxxxxxxxx/PJSUA2/example/pygui/file.wav', enc_type=0, max_size=0, options=0);
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
mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
player.startTransmit( mym);
#mym.startTransmit( self.recorder);
if(ci.state==pj.PJSIP_INV_STATE_DISCONNECTED):
print(">>>>>>>>>>>>>>>>>>>>>>> Call disconnected")
#mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
#mym.stopTransmit(self.recorder);
raise Exception('onCallState done!')
if self.chat:
self.chat.updateCallState(self, ci)
def onCallMediaState(self, prm):
ci = self.getInfo()
for mi in ci.media:
if mi.type == pj.PJMEDIA_TYPE_AUDIO and \
(mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE or \
mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD):
if mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD and not self.onhold:
self.chat.addMessage(None, "'%s' sets call onhold" % (self.peerUri))
self.onhold = True
elif mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE and self.onhold:
self.chat.addMessage(None, "'%s' sets call active" % (self.peerUri))
self.onhold = False
raise Exception('onCallMediaState done!')
class Account(pj.Account):
def onRegState(self, prm):
print ("***OnRegState: " + prm.reason)
def onIncomingCall(self, prm):
c = Call(self, call_id=prm.callId)
call_prm = pj.CallOpParam()
call_prm.statusCode = 180
c.answer(call_prm)
ci = c.getInfo()
msg = "Incoming call from '%s'" % (ci.remoteUri)
print(msg)
call_prm.statusCode = 200
c.answer(call_prm)
raise Exception('onIncomingCall done!')
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep_cfg.uaConfig.threadCnt = 0
ep_cfg.uaConfig.mainThreadOnly = False
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig();
sipTpConfig.port = 12345;
tp=ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig);
# Start the library
ep.libStart();
acfg = pj.AccountConfig();
acfg.idUri = "sip:192.168.1.11:12345";
# Create the account
acc = Account();
acc.create(acfg)
while True:
ep.libHandleEvents(10)
ep.libDestroy()
del ep;
if name == "main":
pjsua2_test()
Hi
Even a simple 3 line code is giving same error. Can anyone help on this?
import pjsua2 as pj
recorder=pj.AudioMediaRecorder()
recorder.createRecorder('file.wav');
return _pjsua2.AudioMediaRecorder_createRecorder(self, file_name, enc_type, max_size, options)
NotImplementedError: Wrong number or type of arguments for overloaded function 'AudioMediaRecorder_createRecorder'.
Possible C/C++ prototypes are:
pj::AudioMediaRecorder::createRecorder(pj::string const &,unsigned int,pj_ssize_t,unsigned int)
pj::AudioMediaRecorder::createRecorder(pj::string const &,unsigned int,pj_ssize_t)
pj::AudioMediaRecorder::createRecorder(pj::string const &,unsigned int)
pj::AudioMediaRecorder::createRecorder(pj::string const &)
I tried trunk,2.8 and 2.7 and same error.
Sekar
From: Sekar S sekarpdkt@hotmail.com
Sent: Saturday, January 5, 2019 10:05 PM
To: pjsip@lists.pjsip.org
Subject: Re: [pjsip] Python PJSUA2 : play wave file and record audio example
Hi all
Able to resolve 1st issue, by shifting call.answer to main thread. Struck with second issue, i.e how to create recorder to record to a wave file. Any help is welcome.
recorder=pj.AudioMediaRecorder()
recorder.createRecorder('xxxxxxxxxxx/PJSUA2/example/pygui/file.wav');
Thanks.
Sekar.
From: Sekar S sekarpdkt@hotmail.com
Sent: Thursday, January 3, 2019 10:04 PM
To: pjsip@lists.pjsip.org
Subject: Re: [pjsip] Python PJSUA2 : play wave file and record audio example
Hi
After going thru pygui code, I modified the example as below. I have two issues
Note: I am having issues in replying to same thread. So opened a Stakeworkflow query for same. If this time also, it created to new thread, I will continue to use stakeworkflow
Stackoverflow link: https://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
[https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded]https://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
PJSUA2 - Python - How to handle callbacks and createRecorder? - Stack Overflowhttps://stackoverflow.com/questions/54025192/pjsua2-python-how-to-handle-callbacks-and-createrecorder
Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.
stackoverflow.com
-----------------------------Modified code --------------
import pjsua2 as pj
import time
ep=None
class Call(pj.Call):
"""
High level Python Call object, derived from pjsua2's Call object.
"""
def init(self, acc, peer_uri='', chat=None, call_id = pj.PJSUA_INVALID_ID):
pj.Call.init(self, acc, call_id)
self.acc = acc
self.aud_med=pj.AudioMedia
def onCallState(self, prm):
ci = self.getInfo()
self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED
self.recorder=None
if(self.connected ==True):
player=pj.AudioMediaPlayer()
#Play welcome message
player.createPlayer('xxxxxxxxxxxxxx/PJSUA2/example/pygui/welcomeFull.wav');
self.recorder=pj.AudioMediaRecorder()
#self.recorder.createRecorder('xxxxxxxxxxx/PJSUA2/example/pygui/file.wav', enc_type=0, max_size=0, options=0);
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
mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
player.startTransmit( mym);
#mym.startTransmit( self.recorder);
if(ci.state==pj.PJSIP_INV_STATE_DISCONNECTED):
print(">>>>>>>>>>>>>>>>>>>>>>> Call disconnected")
#mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
#mym.stopTransmit(self.recorder);
raise Exception('onCallState done!')
if self.chat:
self.chat.updateCallState(self, ci)
def onCallMediaState(self, prm):
ci = self.getInfo()
for mi in ci.media:
if mi.type == pj.PJMEDIA_TYPE_AUDIO and \
(mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE or \
mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD):
if mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD and not self.onhold:
self.chat.addMessage(None, "'%s' sets call onhold" % (self.peerUri))
self.onhold = True
elif mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE and self.onhold:
self.chat.addMessage(None, "'%s' sets call active" % (self.peerUri))
self.onhold = False
raise Exception('onCallMediaState done!')
class Account(pj.Account):
def onRegState(self, prm):
print ("***OnRegState: " + prm.reason)
def onIncomingCall(self, prm):
c = Call(self, call_id=prm.callId)
call_prm = pj.CallOpParam()
call_prm.statusCode = 180
c.answer(call_prm)
ci = c.getInfo()
msg = "Incoming call from '%s'" % (ci.remoteUri)
print(msg)
call_prm.statusCode = 200
c.answer(call_prm)
raise Exception('onIncomingCall done!')
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep_cfg.uaConfig.threadCnt = 0
ep_cfg.uaConfig.mainThreadOnly = False
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig();
sipTpConfig.port = 12345;
tp=ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig);
# Start the library
ep.libStart();
acfg = pj.AccountConfig();
acfg.idUri = "sip:192.168.1.11:12345";
# Create the account
acc = Account();
acc.create(acfg)
while True:
ep.libHandleEvents(10)
ep.libDestroy()
del ep;
if name == "main":
pjsua2_test()