Net::SIP::DTMF(3pm)

πŸ’– Net::SIP::DTMF πŸ’–

okay bestie so this is a page from the User Contributed Perl Documentation, and it's literally all about DTMF RTP packet generating and extracting. yes ma'am. that's the whole vibe.


✨ SYNOPSIS ✨

use Net::SIP::DTMF;
my $sub = dtmf_generator(
  11,                  # event '#'
      100,                 # duration 100ms
      rfc2833_type => 101, # RTP type 101 for telephone-event/8000
      # audio_type => 0,   # RTP type 0 for PCMU/8000, 8 for PCMA/8000
);
while (...) {
      my @pkt = $sub->($sequence,$timestamp,$srcid);
      last if ! @pkt;        # dtmf done
      next if $buf[0] eq ''; # more coming, but no data this time (pause)
      .. send @pkts ...
}

use Net::SIP::DTMF;
my $sub = dtmf_extractor(
      rfc2833_type => 101, # RTP type 101 for telephone-event/8000
      audio_type => 0,     # RTP type 0 for PCMU/8000, 8 for PCMA/8000
);
while (...) {
      if ( my ($event,$duration,$type) = $sub->($packet)) {
        # event received
        ...
      }
}

🌸 DESCRIPTION 🌸

so this package hands you functions that either generate RTP packets stuffed with DTMF events, or extract DTMF events back out of RTP packets. that's the whole job. it's giving switchboard energy. πŸ’…


πŸŽ€ FUNCTIONS πŸŽ€

dtmf_generator ( EVENT, DURATION, %ARGS )

this one builds you a function β€” an actual little closure β€” that you then use to generate packets for whatever EVENT you asked for. it's iconic honestly.

  • EVENT is the event number, and it lives in the range 0..15. or you can pass undef if you just want it to generate silence or a pause. yes, undef is a valid mood.
  • DURATION is how long the event lasts, measured in ms.
  • %ARGS is where you tell it how to pack the thing: either as an RFC2833 RTP event, or as RTP audio PCMU/8000 or PCMA/8000.

and %ARGS can be any of these, bestie:

  • rfc2833_type => rtp_type β€” gives the RTP payload type number for rfc2833 RTP events (telephone-event/8000). if you don't pass it, it'll try audio_type instead.
  • audio_type => rtp_type β€” gives the RTP payload type number. 8 means PCMA/8000, 0 means PCMU/8000. and if you give neither this nor rfc2833_type? it will croak. loudly. it's not playing. 😭
  • volume => volume β€” sets the volume for the RTP event, per rfc2833.

so the function you just got generated? you call it with SEQUENCE,TIMESTAMP,SRCID and it'll generate the RTP packets and return @RTP_PACKETS, where:

  • () β€” DTMF event is finished. done. periodt.
  • $RTP_PACKETS[0] eq '' β€” no RTP packet for this call (a pause, lowkey a little break)
  • @RTP_PACKETS β€” actual RTP packets you can send to the peer πŸ”₯

dtmf_extractor ( %ARGS )

this one generates a function that pulls DTMF events out of stuff. the keys rfc2833_type and audio_type mean exactly the same thing as they do in generate_dtmf. important though: it will only attempt to extract DTMF events from rfc2833 RTP events or from audio if the relevant rtp_type is given. no type, no attempt, that's the rule. 🫢

the function gets called with the RTP packet as its only argument, and it returns:

  • () β€” if no new events were found (nothing to see here)
  • (EVENT,DURATION,TYPE) β€” if an event finished, where DURATION is the duration in ms and TYPE is audio|rfc2833.
πŸ’€ heads up: for performance reasons it is best to use only rfc2833 if the peer supports it. like, genuinely bestie, don't make it do extra work for no reason.

πŸ¦‹ SEE ALSO πŸ¦‹

wait β€” there's nothing else listed here. just you, me, and the DTMF packets. main character energy fr fr. ✨


and that's a wrap on the Net::SIP::DTMF page πŸ’œ this lil' slice of the User Contributed Perl Documentation is brought to you by perl v5.40.1, dated 2025-12-07. slay, stay hydrated, and may all your events finish cleanly. πŸŽ€πŸŒˆπŸ«Ά

πŸ“¦ where this page comes from