Capturing DTMF input while the audio is still playing

Hello, I ran into an issue recently where if I want to gather DTMF inputs, I’d have to wait till the audio file before the Read() finishes. Is it possible to somehow terminate that audio playback as soon as input is detected? Without overlapping with the next audio (which is played afterwards, to inform about that input).
https://wiki.asterisk.org/wiki/display/AST/Application_Read

I found Application_ControlPlayback which could work, however I fear the fact that it will skip the first digit

Any solution that is perhaps already built-in?

More details of your requirement are needed. It is possible that Background() is what you need.

I have an IVR bot asking user for an input (either 1 or 2) and so it happens that the user tries to press 1, way before they are even presented with 2 (which is ok, option number 1 is more popular), but nothing happens. They have to wait till the audio finishes and this issue’s been causing problems lately with customers hanging up due to the fact that nothing happens.

That is what Background is designed for, but you will need to change you control flow so that the number dialled is, directly, used as an extension, not first put in a variable.

There are examples of this usage in the sample configuration: asterisk/extensions.conf.sample at master · asterisk/asterisk · GitHub

not sure what you mean by “not first put in a variable”

Read puts the number in a variable. The correct way of using Background and WaitExten doesn’t use any explicit variables.

I see, so from what I understand so far, I should use Background() before Read(). This way I can terminate the audio using the m parameter as soon as the user starts typing (won’t this skip the first digit though?). As I’m looking at the docs I can see that according to it’s definition Only break if a digit hit matches, it feels like it’s referring to just 1 single digit or is it possible to add multiple (ideally going from 0 - 9)?

Other way I can think of is to make a regex for an extension (so it’s dynamic) and then just capture the whole number that matched that extension. However this would make the size static, right? (user is later presented with OTP ranging from 4 - 9 digits, so this approach wouldn’t work I feel like.

You don’t use Read at all, you do it as for the example I referenced.

Got it, then I run into the other issue I talked about. What if they input:
a) something completely incorrect.
b) while entering the 4 - 9 digit OTP for verification, I can’t have an extension representing each possible combination

I may not understand it correctly, but as of now, this would only work for pre-defined inputs (1 or 2). Not to capture 6 digit OTP which would have1000000 combinations

You can use pattern matches: _XXXXXX

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.