dtmf

package
v0.0.0-...-cb2363a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 9

Documentation

Index

Constants

View Source
const (
	SDPNameOnly = "telephone-event"
)

Variables

This section is empty.

Functions

func CodeToChar

func CodeToChar(code byte) byte

CodeToChar converts a DTMF event code to its character representation. It returns 0 for unknown codes.

func Encode

func Encode(out []byte, ev Event) (int, error)

func Tone

func Tone(digit byte) (code byte, freq []tones.Hz)

Tone returns DTMF tone frequencies for a given digit.

func Write

func Write(ctx context.Context, audio media.Writer[media.PCM16Sample], events *rtp.Stream, eventsRate int, startTs uint32, digits string) error

Write in-band (analog) and off-band (digital) DTMF tones to audio and RTP streams respectively.

Digits may contain a special character 'w' which adds a 0.5 sec delay.

Types

type Event

type Event struct {
	Code   byte
	Digit  byte
	Volume byte   // in dBm0 (without sign)
	Dur    uint16 // in timestamp units
	End    bool
}

func Decode

func Decode(data []byte) (Event, error)

func DecodeRTP

func DecodeRTP(h *rtp.Header, payload []byte) (Event, bool)

func DecodeRTPWithEnd

func DecodeRTPWithEnd(h *rtp.Header, payload []byte) (Event, bool)

DecodeRTPWithEnd decodes a DTMF event from an RTP packet using both the Marker bit and the End bit to determine event completion. This is useful for SIP providers that may or may not set the Marker bit. See RFC 4733 §2.3.1.

type Handler

type Handler func(ev Event)

type Writer

type Writer interface {
	WriteDTMF(ctx context.Context, ev string) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL