Coder Social home page Coder Social logo

misc's People

Contributors

sekarpdkt avatar

Watchers

 avatar

misc's Issues

Help with a code to dial and play audio

Hello, congratulations for sharing your knowledge, I need help, I need to create a code to make a call and as soon as the call is answered it plays an audio, my code below already does the authentication and when I try to make the call It fails, can you help me solve this problem?

import pjsua2 as pj
import time

# Subclass to extend the Account and get notifications etc.
class Account(pj.Account):
    def onRegState(self, prm):
        print("***OnRegState: " + prm.reason)
        if prm.code == 200:
            make_call(self)

# Subclass to handle call events
class MyCall(pj.Call):
    def __init__(self, acc, dest_uri):
        pj.Call.__init__(self, acc)
        self.dest_uri = dest_uri

    def on_state(self):
        if self.info().state == pj.PJSIP_INV_STATE_CALLING:
            print("Chamando", self.dest_uri)
        elif self.info().state == pj.PJSIP_INV_STATE_INCOMING:
            print("Chamada recebida de", self.info().remote_uri)
            self.answer()
        elif self.info().state == pj.PJSIP_INV_STATE_EARLY:
            pass
        elif self.info().state == pj.PJSIP_INV_STATE_CONNECTING:
            pass
        elif self.info().state == pj.PJSIP_INV_STATE_CONFIRMED:
            print("Chamada conectada. Reproduzindo áudio...")
            self.start_audio("testeaudio.wav")
        elif self.info().state == pj.PJSIP_INV_STATE_DISCONNECTED:
            print("Chamada desconectada, motivo:", self.info().last_reason)
            self.delete()

# pjsua2 test function
def pjsua2_test():
    # Create and initialize the library
    ep_cfg = pj.EpConfig()
    ep = pj.Endpoint()
    ep.libCreate()
    ep.libInit(ep_cfg)

    # Create SIP transport. Error handling sample is shown
    sipTpConfig = pj.TransportConfig()
    sipTpConfig.port = 5064
    ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
    # Start the library
    ep.libStart()

    acfg = pj.AccountConfig()
    acfg.idUri = "sip:[email protected]:5064"
    acfg.regConfig.registrarUri = "sip:sbc.dominio.servidor:5064"
    cred = pj.AuthCredInfo("digest", "*", "9999", 0,  "9999#")
    acfg.sipConfig.authCreds.append(cred)
    # Create the account
    acc = Account()
    acc.create(acfg)
    # Here we don't have anything else to do..
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Encerrando chamada...")
        if acc.calls.count > 0:
            call = acc.calls[0]
            call.hangup()
            time.sleep(2)
        ep.libDestroy()

def make_call(account):
    dest_uri = "sip:[email protected]:5064"  # Ramal 1571
    call = MyCall(account, dest_uri)
    call.make_call(dest_uri)

#
# main()
#
if __name__ == "__main__":
    pjsua2_test()

When I try to make the call I get this error message here.

***OnRegState: OK
Traceback (most recent call last):
  File "/app/notifica_voz/call_2.py", line 9, in onRegState
    make_call(self)
  File "/app/notifica_voz/call_2.py", line 72, in make_call
    call.make_call(dest_uri)
AttributeError: 'MyCall' object has no attribute 'make_call'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.