3

I am trying to implement DTMF for Android/iOS Application based out on WebRTC. Is there any API for DTMF for Android? I have tried calling the following:

m_peerConnectionFactory.createdtmfsender(localAudioTrack);
m_peerConnectionFactory.insertDtmf(tone, duration,gap);

I have tried using the above api's for javascript and it works well on browser, but could nt make it work on Android. I havent tried it on iOS still, as I need to make it run on android first.

Please let me know if this is supported on Android/iOS or not? If yes, could any one please help me with the correct api's

libjingle version used : chrome 74.0.3729.169

Aagman
  • 684
  • 6
  • 18

1 Answers1

6

I got it Working on both android and iOS . The Api createdtmfsender has been deprecated, details can be found here

Android Code :

RtpSender m_audioSender = null;
for (RtpSender sender : m_peerConnection.getSenders()) {
//m_peerConnection is object of webRTC peerconnection
  if (sender.track().kind().equals("audio")) {
   m_audioSender = sender;
  } 
}
if (m_audioSender != null) {
  DtmfSender dtmfSender = m_audioSender.dtmf();
  dtmfSender.insertDtmf(m_tone, 1000, 500);//Here the timers are in ms

iOS Code

-(void)dtmfTonePlayer: (NSString *)dtmfTone {
    RTCRtpSender* m_audioSender = nil ;
    for( RTCRtpSender *rtpSender in m_peerConnection.senders){
     if([[[rtpSender track] kind] isEqualToString:@“audio”]) {
       DLog(@“Assigning audio to rtp sender”);
       m_audioSender = rtpSender;
     }  
    }
     if(m_audioSender){
     NSOperationQueue *queue = [[NSOperationQueue alloc] init];
     [queue addOperationWithBlock:^{
        BOOL istoneplayed = [m_audioSender.dtmfSender insertDtmf :(NSString *)dtmfTone 
        duration:(NSTimeInterval)2 interToneGap:(NSTimeInterval)0.5];
        NSLog(@“DTMF Tone played :: [%s]“, istoneplayed ? “true” : “false”);
     }];
     }
   }
Aagman
  • 684
  • 6
  • 18
  • that saved my life. I use these codes to add dtmf functionalty for flutter webrtc package. thanks – Bilal Şimşek Sep 11 '20 at 20:06
  • @Aagman, are you doing anything to generate dial tones? The javascript web sdk is generating sounds when you send dtmf but the iOS and android sdks do not. – giorgos.nl Sep 22 '20 at 09:56
  • @giorgos.nl, which SDK you are using here, I have developed an app using which I am.sending the numbers from the native mobile keyboard – Aagman Sep 23 '20 at 10:10
  • I'm using the latest Android SDK and I'm doing the same, sending the numbers from the keyboard. I found out about the tones: using the `ToneGenerator` DTMF tones: https://developer.android.com/reference/android/media/ToneGenerator#TONE_DTMF_1 – giorgos.nl Sep 25 '20 at 09:00
  • You don't need to use the tone generator method here, as it applicable when you are generating tone from your native mobile framework. But as in your case if you are using WebRtc , you just need to use the code mentioned above and give the value of number which you want to send across as DTMF to the m_tone variable. – Aagman Sep 27 '20 at 04:08
  • May I ask what String are you sending for insertDTMF -> I am sending for example "1" I get result TRUE, and sender.canInsertDtmf is true however the robot from the phone call I am doing does not go past the first step (doesn't take the dtmf) – rosu alin Nov 11 '21 at 11:57
  • Putting a "1" will send the DTMF tone corresponding to 1, to the remote peer. As you are getting a true return value, that means the tone is created successfully. – Aagman Nov 12 '21 at 12:21
  • I would suggest to debug it from the RTP packets sent out from your device. – Aagman Nov 12 '21 at 12:22