You can accomplish this by using the say action to read out the passwords to the callee. You can also find more features of the say action(for example how to control the rate, pitch, volume, etc) of your text here.
Here is an example OTP application:
โ
import random
from flask import Flask, request
def createOTP():
numbers = "0123456789"
otp = "".join(random.choices(numbers, k = 4))
return otp
#sending a post request to AT with instructions to read the OTP to the caller.
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def say():
# If number is for OTP only it would be good to block incoming calls
#check call direction(from details sent to the callback URL)
direction = request.values.get("direction", None)
myOtp = createOTP()
#Notoce how I have used google text to speech features to control how I want the text to read out.
if (direction == "Inbound"):
response = '<?xml version="1.0"?>'
response += '<Response>'
response += '<Reject/>'
response += '</Response>'
else:
response = '<?xml version="1.0"?>'
response += '<Response>'
response += f'<Say><speak><prosody rate="slow" pitch="-3st">Your code is <say-as interpret-as="characters">{myOtp}</say-as></prosody></speak></Say>'
response += '</Response>'
return response