pjsip / pjproject

PJSIP project
http://www.pjsip.org
GNU General Public License v2.0
1.97k stars 765 forks source link

Send audio frames or chunks for the caller instead of WAV #4016

Closed ahmed-troido closed 3 weeks ago

ahmed-troido commented 1 month ago

Describe the feature

I'm using this snippet of code to playback a wav file to the caller using pjsua2 AudioMediaPlayer

How to send a chunk by chunk (audio frames) to the caller instead of playing a wav file ?

I need a way to send chunks instead of playing a WAV

    def onCallState(self, prm):
        ci = self.getInfo()
        self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED
        if(self.connected ==True):
            player=pj.AudioMediaPlayer()
            #Play welcome message
            player.createPlayer('./welcomeFull.wav')
            i=0
            for media in ci.media:
                if (media.type == pj.PJMEDIA_TYPE_AUDIO):
                    self.aud_med = self.getMedia(i)
                    break
                i=i+1
            if self.aud_med!=None:
                mym= pj.AudioMedia.typecastFromMedia(self.aud_med)
                player.startTransmit( mym)
                mym.startTransmit( self.recorder);    

Describe alternatives you've considered

No response

Additional context

No response

andreas-wehrmann commented 1 month ago

You could create a memplayer and supply the buffer yourself or you could create your own media port, insert it into the confbridge and then connect it to the call. The confbridge will then repeatedly call into your media port to get frames.

ahmed-troido commented 1 month ago

Thanks for your help Could you please provide me with some resources or documentation about both ways (specially the memplayer)?

andreas-wehrmann commented 1 month ago

Sure, take a look at the PJ docs here:

ahmed-troido commented 1 month ago

Thanks but I tried to search the whole documentation to find a sample that using memplayer but I didn't find one.

also I tried to call this but there is no fun called pjmedia_mem_player_create in pj pj.pjmedia_mem_player_create()

I'm using python 3.9

andreas-wehrmann commented 1 month ago

Ah sorry I didn't notice it was Python. I'm not sure these "low level" functions are exported to Python... I don't really have any experience in using pj from Python though; If there are no exports of these functions you might need to write and export them yourself I'm afraid.

ahmed-troido commented 1 month ago

Thanks again :pray: but Do you have any resources or what I need to do (steps) to use this in python ?

andreas-wehrmann commented 1 month ago

Not really no, sorry.