String variable with Integers Format.Number.playDigits

Are there any plans to allow bot flows to communicate strings with variables as single digits vs whole numbers? When we ask for loan information and set it for confirmation we don't want the bot to respond as Four Thousand Ninety Five. We would like to be able to do formatting so it will respond as four zero nine five.

Thank you,

Eric

I found a work around using substrings but it can be quite lengthy because one of our products is credit cards which are 16 digits

Hi @Eric_Allen,

Thanks for the question!

With regards to whether or not we're planning to add support for functionality like this:

    ToCommunication(Flow.IntegerVar, Format.Number.playDigits)

similar to what you can do in call flows:

    ToAudioNumber(Flow.IntegerVar, Format.Number.playDigits) 

the answer is yes we are working on it but I don't have a release date at this time.

Now, with that being said, we do have functionality today that might meet your need and not require a lot of substring calls. The trick is to get your number expressed as a string, split on "" and then convert the resulting string collection back to a string using " " or ", " as the delimiter.

Lets say you have the number 12345678 in a Flow.MyInteger variable. If we wanted to convert this to a communication with individual digit read back on a call, you could try this by adding an expression to a communication builder with this text:

    ToCommunication(
        If(IsSet(Flow.MyInteger),
            ToString(Split(ToString(Flow.MyInteger), ""), " "),
            ""
        )
    )

So above we're making sure that the Flow.MyInteger isn't NOT_SET before performing operations on it and if it is we simply return a blank string for it but that expression shows how we get the number converted to a string, split on "" which will take each character from the string representation of the number and create a string collection where each item is an individual character and then use the ToString call with " " as the delimiter to join each item from the string collection back to a string. For example:

    12345678 becomes "1 2 3 4 5 6 7 8"

or if you used ", " instead of " " on the ToString call:

    12345678 becomes "1, 2, 3, 4, 5, 6, 7, 8"

that is converted to a Communication value with the ToCommunication call. The resulting Communication value when read back on a call would get that individual digit experience.

And yes if you had a string with spaces in it like an account number of "111 222", you can always use the Replace function to replace " " with "" prior to doing the Split / ToString call so the string submitted to the ToCommunication call becomes "1 1 1 2 2 2". Assuming Flow.AccountNumStr variable has the string "111 222" in it:

    ToCommunication(
        If(IsNotSetOrEmpty(Flow.AccountNumStr),
            "",
            ToString(Split(Replace(Flow.AccountNumStr, " ", ""), ""), " ")
        )
    )

And if you already had a number expressed as a string like "5950" in Flow.AccountNumStr, this would work:

    ToCommunication(
        If(IsNotSetOrEmpty(Flow.AccountNumStr),
            "",
            ToString(Split(Flow.AccountNumStr, ""), " ")
        )
    )

I made the expressions here multi-line to aid with readability.

Hope this helps! :slight_smile:

Jim

1 Like

Hi @Ullyot_Jim

On similar lines we are calling the variable with string value from an database and playing it as an audio to customer using ToAudioTTS in an audio sequence set in Inbound flow. But lately it was reported the audio speed is too fast to understand and need to slower down. Can help to suggest on how this can be achieved?

Hi @dmadhu ,

Thanks for asking.

Did you try using ", " instead of " " on the ToString call to get a pause?

Usually when a TTS engine sees that ", " between digits will add a pause in playback.

So in a call flow when dealing with an Audio value rather than a Communication value like you would in a bot flow, that ToCommunication call would be ToAudioTTS. Here is an example that will add a one second pause if the account number is blank or a NOT_SET String or otherwise insert ", " between characters in the string:

If(IsNotSetOrEmpty(Flow.AccountNumStr),
    ToAudioBlank(1000),
    ToAudioTTS(ToString(Split(Replace(Flow.AccountNumStr, " ", ""), ""), ", "))
)

As an example, if Flow.AccountNumStr was "123 43 21" the result of that ToString part of the expression would be:

"1, 2, 3, 4, 3, 2, 1"

and that is submitted to the ToAudioTTS function. I have seen flow authors use periods or even multiple commas on string values submitted to TTS engines to get longer pauses. The behavior here is TTS engine dependent but generally works fine.

Now if you wanted something more explicit you could, after validating that the account number is not an empty or NOT_SET String do this:

1.  Assign `Split(Replace(Flow.AccountNumStr, " ", ""), "")` to 
    Flow.AccountNumStrCollection that is a String Collection variable 
    using an Update Statement.

2.  Next add a Loop action that loops the number of items in the 
    Task.AccountNumStrCollection variable using the Count function.  
    Set the loop index variable to be `Task.LoopIndex` on the Loop action.

3.  Inside the Loop add a PlayAudio action that does this using an expression:

    Append(
        ToAudioTTS(Flow.AccountNumStrCollection[Task.LoopIndex]), 
        ToAudioBlank(500)
    )

This is a little more work than the suggestion above but here you have more control over the amount of blank audio between each ToAudioTTS call unlike the previous example where the blank audio length was how the TTS engine interpreted , or . depending on the string you inserted between characters. The above example shows 500ms of blank audio but obviously change it to what works best on the ToAudioBlank call. Do note that in this solution there is blank audio inserted after the last digit.

Hope this helps!

Jim

This is a great post. But how can we take this one step further to customise each character to phonetically read back a variable. For example
AccountNameStr = "JohnSmith12!@"
becomes
"Capital J, o, h, n, Capital S, m, i, t, h, 1, 2, exlamation mark, at symbol"

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