phone = VoIPPhone(192.168.1.101, 5060, 202, Asd123, myIP=192.168.1.160, callCallback=answer)
phone = VoIPPhone("192.168.1.101'", 5060, 202, Asd123, myIP="192.168.1.160", callCallback=answer)
from pyVoIP.VoIP import VoIPPhone, InvalidStateError, CallState
import time
import wave
def answer(call):
try:
f = wave.open('announcment.wav', 'rb')
frames = f.getnframes()
data = f.readframes(frames)
f.close()
call.answer()
call.write_audio(data) # This writes the audio data to the transmit buffer, this must be bytes.
stop = time.time() + (frames / 8000) # frames/8000 is the length of the audio in seconds. 8000 is the hertz of PCMU.
while time.time() <= stop and call.state == CallState.ANSWERED:
time.sleep(0.1)
call.hangup()
except InvalidStateError:
pass
except:
call.hangup()
if __name__ == "__main__":
phone = VoIPPhone(<SIP Server IP>, <SIP Server Port>, <SIP Server Username>, <SIP Server Password>, myIP=<Your computers local IP>, callCallback=answer)
phone.start()
input('Press enter to disable the phone')
phone.stop()