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

Unable to answer call (dev-branch) #278

Open
SolntsevLA opened this issue Sep 27, 2024 · 0 comments
Open

Unable to answer call (dev-branch) #278

SolntsevLA opened this issue Sep 27, 2024 · 0 comments

Comments

@SolntsevLA
Copy link

SolntsevLA commented Sep 27, 2024

I'm using dev-branch and code

from pyVoIP.SIP.message.message import SIPMessage
from pyVoIP.credentials import CredentialsManager
from pyVoIP.VoIP.call import VoIPCall,CallState
from pyVoIP.VoIP.error import InvalidStateError
from pyVoIP.VoIP.phone import VoIPPhone, VoIPPhoneParameter



import time
import wave
import traceback
import librosa
import soundfile


class Call(VoIPCall):
    def ringing(self, invite_request):
        return custom_answer(self)



    def bye(self):
        print('Bye')
        return self.bye()


def custom_answer(call):
    print('start answering')
    original_data, sr = librosa.load('x00_autogen_sample_music.wav', sr=44100)
    resampled_data = librosa.resample(original_data, orig_sr=sr, target_sr=8000)
    soundfile.write('to_play.wav',resampled_data,samplerate=8000,subtype='PCM_U8')
    f = wave.open('to_play.wav', 'rb')
    frames = f.getnframes()
    data = f.readframes(frames)
    f.close()
    return call.answer()
    #call.write_audio(data)

    # call.answer()
    # call.write_audio(data)
    # d=10
    # while d>0:
    #     print(call.state)
    #     time.sleep(.1)



if __name__ == "__main__":




  cm = CredentialsManager()
  server_username='---'
  server_password='---'

  cm.add(server_username, server_password)

  server_ip='----'
  server_port=5060
  server_user='5264'
  bind_ip='---'
  params = VoIPPhoneParameter(server_ip, server_port, server_user, credentials_manager=cm, bind_ip=bind_ip,call_class=Call)
  phone = VoIPPhone(params)
  phone.start()
  print(phone.get_status())


  # call_x=phone.call('89200126698')
  # while call_x.state!=CallState.ENDED:
  #     time.sleep(1)
  #     if call_x.state==CallState.ANSWERED:
  #         original_data, sr = librosa.load('x00_autogen_sample_music.wav', sr=44100)
  #         resampled_data = librosa.resample(original_data, orig_sr=sr, target_sr=8000)
  #         soundfile.write('to_send.wav',resampled_data,samplerate=8000,subtype='PCM_U8')
  #         f = wave.open('to_send.wav', 'rb',)
  #         frames = f.getnframes()
  #         print(f.getframerate())
  #         data = f.readframes(frames)
  #         f.close()
  #         call_x.write_audio(data)



  #print(call_x.state)
  input('Press enter to disable the phone\n')
  phone.stop()

Output is

PhoneStatus.REGISTERED
Press enter to disable the phone
sys:1: UserWarning: RTP Payload type G729 not found.
sys:1: UserWarning: RTP Payload type G729 not found.
sys:1: UserWarning: RTP Payload type speex not found.
sys:1: UserWarning: RTP Payload type iLBC not found.
sys:1: UserWarning: RTP Payload type iLBC not found.
sys:1: UserWarning: RTP Payload type G729 not found.
sys:1: UserWarning: RTP Payload type AMR not found.
start answering

It seems, that ringing () function works and then is happends nothing

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

1 participant