Not able to call Response.Say during live streaming of call twilio websocket python

41 Views Asked by At

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
1

There are 1 best solutions below

0
IObert On

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.

// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
      .update({twiml: '<Response><Say>Ahoy there</Say></Response>'})
      .then(call => console.log(call.to));