Last active
July 9, 2021 19:13
-
-
Save av1d/e66819e0e92028dd97d82f425165e55e to your computer and use it in GitHub Desktop.
Quickstart guide for RTClite SIP Caller. Setup, settings, how-to. Place VoIP/SIP calls from Python. Includes example template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from rtclite.app.sip.caller import Caller, default_options | |
from rtclite.std.ietf.rfc2396 import Address, URI | |
from rtclite.std.ietf import rfc4566 | |
rfc4566.lineending = '\n' | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
''' | |
QUICK SETUP GUIDE AND SIMPLIFIED USAGE | |
Installing and importing RTClite SIP Caller into Python as a module. | |
See end of this file for an easy template. | |
------------------------------------------------------------------- | |
Make sure you're using Python 2.7. | |
Verify by typing: python --version | |
Type: | |
git clone https://github.com/theintencity/rtclite.git | |
git clone https://github.com/theintencity/py-audio.git | |
sudo pip install gevent | |
IF you have problem installing gevent due to the greenlet dependency, you may want to install greenlet explicitly as follows, before installing gevent: | |
sudo easy_install greenlet==0.4.10 | |
Now, we must add sip caller to PYTHONPATH. | |
On Ubuntu we will add the $PYTHONPATH to our .bashrc profile. | |
Type (replace the path with the path of your installation): | |
cp ~/.bashrc ~/.bashrc.bak && echo 'export PYTHONPATH="${PYTHONPATH}:/home/av1d/rtclite"' >> ~/.bashrc | |
(.bashrc.bak becomes your profile backup just in case). | |
Now reload .bashrc by typing: | |
source ~/.bashrc | |
The module will now be working from within Python. | |
''' | |
# All of these options are options of the command line software. | |
# Type: python -m rtclite.app.sip.caller -h | |
# in terminal to get all the options or see below for complete list. | |
# They're accessed by "options.whatever_option_you_want". | |
# Follow the same syntax as below (replace hyphen with underscore, etc.): | |
options = default_options() | |
options.to = Address('sip:18007741500@tollfree.alcazarnetworks.com') | |
options.uri = URI('sip:18007741500@tollfree.alcazarnetworks.com') | |
options.samplerate = 41000 | |
options.domain = 'example.net' | |
options.use_lf = True | |
caller = Caller(options) | |
try: caller.wait() | |
except: pass | |
caller.close() | |
''' | |
Options: | |
-h, --help show this help message and exit | |
-v, --verbose enable verbose mode for this module | |
-q, --quiet enable quiet mode with only critical logging | |
--test run any tests and exit | |
Network: | |
Use these options for network configuration | |
--int-ip=INT_IP listening IP address for SIP and RTP. Use this option | |
only if you wish to select one out of multiple IP | |
interfaces. Default "0.0.0.0" | |
--ext-ip=EXT_IP IP address to advertise in SIP/SDP. Use this to | |
specify external IP if running on EC2. Default is to | |
use "--int-ip" if supplied or any local interface, | |
which is "127.0.1.1" | |
--transport=TRANSPORTS | |
the transport type is one of "udp", "tcp" or "tls". | |
Default is "udp" | |
--port=PORT listening port number for SIP UDP/TCP. TLS is one more | |
than this. Default is 5092 | |
--listen-queue=LISTEN_QUEUE | |
listen queue for TCP socket. Default is 5 | |
--max-size=MAX_SIZE | |
size of received socket data. Default is 4096 | |
--fix-nat enable fixing NAT IP address in Contact and SDP | |
SIP: | |
Use these options for SIP configuration | |
--user-agent=USER_AGENT | |
set this as User-Agent header in outbound SIP request. | |
Default is empty "" to not set | |
--subject=SUBJECT set this as Subject header in outbound SIP request. | |
Default is empty "" to not set | |
--user=USER username to use in my SIP URI and contacts. Default is | |
"av1d" | |
--domain=DOMAIN domain portion of my SIP URI. Default is to use local | |
hostname, which is "superscape" | |
--proxy=PROXY IP address of the SIP proxy to use. Default is empty | |
"" to mean disable outbound proxy | |
--authuser=AUTHUSER | |
username to use for authentication. Default is to not | |
use authentication | |
--authpass=AUTHPASS | |
password to use for authentication. Only used together | |
with --authuser | |
--strict-route use strict routing instead of default loose routing | |
when proxy option is specified | |
--to=TO the target SIP address, e.g., '"Henry Sinnreich" | |
<sip:henry@iptel.org>'. This is mandatory | |
--uri=URI the target request-URI, e.g., "sip:henry@iptel.org". | |
Default is to derive from the --to option | |
--listen enable listen mode with or without REGISTER and wait | |
for incoming INVITE or MESSAGE | |
--register send REGISTER to SIP server. This is used with | |
--listen to receive incoming INVITE or MESSAGE and | |
with --to if the SIP server requires registration for | |
outbound calls | |
--register-interval=REGISTER_INTERVAL | |
registration refresh interval in seconds. Default is | |
3600 | |
--retry-interval=RETRY_INTERVAL | |
retry interval in seconds to re-try if register or | |
subscribe fails. Default is 60 | |
--send=SEND enable outbound instant message. The supplied text | |
with this option is sent in outbound MESSAGE request | |
--auto-respond=AUTO_RESPOND | |
automatically respond to an incoming INVITE or MESSAGE | |
if we are not already in a call. Default is 200 to | |
auto accept. Use 0 to not respond | |
--auto-respond-after=AUTO_RESPOND_AFTER | |
number of seconds after which to auto-respond an | |
incoming call if we are available. Default is 3 | |
--auto-terminate-after=AUTO_TERMINATE_AFTER | |
number of seconds after which to auto-terminate an | |
accepted incoming call. Default is 0 to not auto- | |
terminate | |
--use-lf use LF as line ending instead of default CRLF | |
Media: | |
Use these options for media configuration | |
--no-sdp disable sending SDP in outbound INVITE | |
--no-audio disable audio in a call | |
--audio-loopback enable audio loopback mode where this agent sends back | |
the received audio to the other end | |
--samplerate=SAMPLERATE | |
audio samplerate for capture and playback. Default is | |
44100. Use 48000 on OS X | |
--no-touchtone disable sending touch tone (DTMF) digits when typed. | |
By default touch tone sending is enabled | |
--recognize enable speech recognition to show the received audio | |
as text | |
--textspeech enable text to speech to send typed text as audio. If | |
touchtone is also enabled, it distinguishes between | |
typed digits and non-digits to determine whether to | |
use touchtone or textspeech for the typed text. | |
''' | |
# QUICK SETUP TEMPLATE - PASTE INTO ITS OWN FILE (remove the ''' at beginning/end): | |
''' | |
# -*- coding: utf-8 -*- | |
from rtclite.app.sip.caller import Caller, default_options | |
from rtclite.std.ietf.rfc2396 import Address, URI | |
from rtclite.std.ietf import rfc4566 | |
rfc4566.lineending = '\n' | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
options = default_options() | |
options.to = Address('sip:18007741500@tollfree.alcazarnetworks.com') | |
options.uri = URI('sip:18007741500@tollfree.alcazarnetworks.com') | |
options.samplerate = 41000 | |
options.domain = 'example.net' | |
options.use_lf = True | |
#options.int_ip = | |
#options.ext_ip = | |
#options.transport = | |
#options.port = | |
#options.listen_queue = | |
#options.max_size = | |
#options.fix_nat | |
#options.user_agent = | |
#options.subject = | |
#options.user = | |
#options.proxy = | |
#options.authuser = | |
#options.authpass = | |
#options.strict_route | |
#options.listen | |
#options.register | |
#options.register_interval = | |
#options.retry_interval = | |
#options.send = | |
#options.auto_respond = | |
#options.auto_respond_after = | |
#options.auto_terminate_after = | |
#options.no_sdp = | |
#options.no_audio = | |
#options.audio_loopback = | |
#options.no_touchtone | |
#options.recognize | |
#options.textspeech | |
caller = Caller(options) | |
try: caller.wait() | |
except: pass | |
caller.close() | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment