Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio doesn't work on call, and dtfm isn't capturing values and not working either. #283

Open
coolcunt opened this issue Oct 28, 2024 · 1 comment

Comments

@coolcunt
Copy link

here's my code,
(password's and the server ip and phone number has been changed obviously cuz of reasons but try it out, i'm currently using python 3.10.0 and the latest version of pyvoip. lmk how it goes (Call works, like it can call the person, but it wont play audio or listen to dtfm inputs, and just auto hangup in 7-9 seconds)

from pyVoIP.VoIP import VoIPPhone, InvalidStateError, CallState
import time
import wave
import socket
import logging

SIP_SERVER = "123.45.67.89"
SIP_USERNAME = "username"
SIP_PASSWORD = "password"
PHONE_NUMBER = "+123456789"

Setup logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(name)

def get_local_ip():
"""Get the local IP address of the machine"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.254.254.254', 1))
local_ip = s.getsockname()[0]
except Exception:
local_ip = '127.0.0.1'
finally:
s.close()
return local_ip

def answer(call):
try:
f = wave.open('raw_audio.wav', 'rb')
frames = f.getnframes()
data = f.readframes(frames)
f.close()

    call.answer()
    call.write_audio(data)

    while call.state == CallState.ANSWERED:
        dtmf = call.get_dtmf()
        if dtmf == "1":
            print("pressed one")
            # Do something
            call.hangup()
        elif dtmf == "2":
            print("pressed 2")
            call.hangup()
        time.sleep(0.1)
except InvalidStateError:
    pass
except:
    call.hangup()

if name == 'main':
local_ip = get_local_ip()
phone = VoIPPhone(
server=SIP_SERVER,
port=5060,
username=SIP_USERNAME,
password=SIP_PASSWORD,
myIP=local_ip,
callCallback=answer
)
phone.start()
logger.info(f"Using local IP: {local_ip}")
logger.info(f"Calling phone number: {PHONE_NUMBER}")
phone.call(PHONE_NUMBER)
input('Press enter to disable the phone')
phone.stop()

@tomlynn
Copy link

tomlynn commented Oct 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@tomlynn @coolcunt and others