# RTCDTMFSender

DTMF tones sent over an audio sender.

### *class* webrtc.interfaces.rtc_dtmf_sender.RTCDTMFSender(native_obj=None)

Sends DTMF (telephone keypad) tones over an audio sender, from [`webrtc.RTCRtpSender.dtmf`](rtc_rtp_sender.md#webrtc.interfaces.rtc_rtp_sender.RTCRtpSender.dtmf).

See [MDN: RTCDTMFSender](https://developer.mozilla.org/en-US/docs/Web/API/RTCDTMFSender).

* **Events:**
  **tonechange** ([`webrtc.RTCDTMFToneChangeEvent`](../models/events.md#webrtc.models.events.RTCDTMFToneChangeEvent)) – A tone started playing, or the last one ended
  (with an empty `tone`).

### Events

- `tonechange`: [`Event`](../models/events.md#webrtc.models.events.Event)

Handlers are registered with [`on()`](../events.md#webrtc.utils.events.UniformEventTarget.on).

#### insert_dtmf(tones, duration=100, inter_tone_gap=70)

Queues tones to play, replacing the ones not played yet.

Durations and gaps out of range are clamped to the nearest limit.

See [MDN: RTCDTMFSender/insertDTMF](https://developer.mozilla.org/en-US/docs/Web/API/RTCDTMFSender/insertDTMF).

* **Parameters:**
  * **tones** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The tones: `0` to `9`, `A` to `D` (any case), `#`, `*`, and `,` for a
    2-second pause. An empty string cancels the tones not played yet.
  * **duration** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The length of each tone in milliseconds, clamped to 40 to 6000.
  * **inter_tone_gap** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The pause after each tone in milliseconds, clamped to 30 to 6000.
* **Raises:**
  * [**webrtc.InvalidStateError**](../exceptions.md#webrtc.exceptions.InvalidStateError) – If the sender can’t send DTMF now.
  * [**webrtc.InvalidCharacterError**](../exceptions.md#webrtc.exceptions.InvalidCharacterError) – If `tones` has another character.

#### *property* tone_buffer *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

The tones not played yet, in upper case.

See [MDN: RTCDTMFSender/toneBuffer](https://developer.mozilla.org/en-US/docs/Web/API/RTCDTMFSender/toneBuffer).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### *property* can_insert_dtmf *: [bool](https://docs.python.org/3/builtins/functions.html#bool)*

Whether tones can be sent.

That needs the sender to be negotiated to send with a telephone-event codec.
See [MDN: RTCDTMFSender/canInsertDTMF](https://developer.mozilla.org/en-US/docs/Web/API/RTCDTMFSender/canInsertDTMF).

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)
