我是PJSIP的新手。我想制作一个可以打电话的应用程序,播放wave文件并在此之后挂断。当我使用以下代码时,拨打电话但我听不到任何应该在我的手机上播放的音乐(message.wav)。代码有什么问题吗?如果是这样,在python中为play wav音乐编写代码的正确方法是什么。这是完整的代码链接https://github.com/jrocharodrigues/sipamos/blob/master/sipamos.py
def on_state(self):
global current_call
global in_call
print "Call with", self.call.info().remote_uri,
print "is", self.call.info().state_text,
print "last code =", self.call.info().last_code,
print "(" + self.call.info().last_reason + ")"
if self.call.info().state == pjsua.CallState.DISCONNECTED:
current_call = None
print 'Current call is', current_call
in_call = False
elif self.call.info().state == pjsua.CallState.CONFIRMED:
#Call is Answred
print "Call Answred"
wfile = wave.open("message.wav")
time = (1.0 * wfile.getnframes ()) / wfile.getframerate ()
print str(time) + "ms"
wfile.close()
call_slot = self.call.info().conf_slot
self.wav_player_id=pjsua.Lib.instance().create_player('message.wav',loop=False)
self.wav_slot=pjsua.Lib.instance().player_get_slot(self.wav_player_id)
pjsua.Lib.instance().conf_connect(self.wav_slot, call_slot)
sleep(time)
pjsua.Lib.instance().player_destroy(self.wav_player_id)
self.call.hangup()
in_call = False
# Notification when call's media state has changed.
def on_media_state(self):
if self.call.info().media_state == pjsua.MediaState.ACTIVE:
print "Media is now active"
else:
print "Media is inactive"