In the if AcceptWaveform where print statement is taking place I want to call a sample message at bottom which will be spoken during the call.
But there is no message call.
But during start of calling, the message of Response Say works
def stream(ws):
rec = KaldiRecognizer(model, 16000)
response = VoiceResponse()
while True:
message = ws.receive()
packet = json.loads(message)
if packet['event'] == 'start':
print('Streaming is starting')
elif packet['event'] == 'stop':
print('\nStreaming has stopped')
elif packet['event'] == 'media':
audio = base64.b64decode(packet['media']['payload'])
audio = audioop.ulaw2lin(audio, 2)
audio = audioop.ratecv(audio, 2, 1, 8000, 16000, None)[0]
if rec.AcceptWaveform(audio):
r = json.loads(rec.Result())
print(CL + r['text'] + '\n', end='', flush=True)
response.say('Sample response message')
else:
r = json.loads(rec.PartialResult())
print(CL + r['partial'] + BS * len(r['partial']), end='', flush=True)```
Expectation was that the caller should hear sample response message during call
It seems you are trying to return a TwiML response to the incoming steam data. This won't work, as this is just the stream of the call. Instead, try to modify the original call that is in progress.