Recently, I was asked to implement a sort of public announcement system for a banana pi variant running asterisk.
Sure there is the built-in asterisk public announcement system, which will let you make announcements using the phone speakers (if supported and enabled); but the requirement in my case was different.
Basically, there was to be a designated SIP extension. Users wanting to make a public announcement would call this extension & make their announcement. This was to be played on the banana pi speaker in realtime.
I started searching online for a solution and came across the PJSIP library.
I couldn't find a ready-made solution and started to code my own in PJSIP's C API.
Initially, it was a steep learning curve for me. I soon realized that the C API wasn't recommended (or intended) to be used for basic applications such as this.
I then used one of the provided python examples as a starting point and with some reading, was able to achieve what I wanted.
Here's the code: