Python - Make a call using TAPI (Telephony Application Programming Interface)

997 Views Asked by At

This python code will make a phone call using a modem and TAPI but it only works first time. If I re-run the python script it will not dial again.

import win32com.client

cls = "TAPI.TAPI.1"
sNumber = '12345678' # Adjust it to phone number


ti = win32com.client.Dispatch(cls)._oleobj_.GetTypeInfo()
tlb, index = ti.GetContainingTypeLib()
tla = tlb.GetLibAttr()
win32com.client.gencache.EnsureModule(tla[0], tla[1], tla[3], tla[4], bValidateFile=0)

class TapiEvents(win32com.client.getevents(cls)):
    def OnEvent(self, ev1,ev2): 
        print("OnEvent")

tapi = win32com.client.Dispatch(cls)
if tapi != None:

    hr = tapi.Initialize()
    print("Initialized")

    for item in tapi.Addresses: 
        print(item.AddressName)
        objCrtAddress = [item for item in tapi.Addresses][0]
        gobjCall = objCrtAddress.CreateCall(sNumber, 1, 0x8)
        gobjCall.Connect (False)       
    
    hr = tapi.Shutdown()
    print("Shutdown")
    del tapi
0

There are 0 best solutions below