I have made a Python app that runs on NAO Robot functioned as a "friend" with the help of Watson Speech To Text and Watson Conversation services. The Robot will alternate between asking the question and answering a question.
When the robot is in "asking question" mode, it will listen to Human and stream the speech to Watson STT. The speech is recorded using Arecord. Arecord is then stopped whenever user finishes talking. The transcribed speech will then be sent to Conversation and Robot will then answer the question accordingly. Usually, the "answering question" mode will last less than 30 seconds. But some reply is long enough that the Watson STT will trigger session timeout.
To prevent this session timeout, we used to send "no-op" message signal every 10 seconds.
def keepAlive(self):
self.send({"action": "no-op"})
However, Watson recently deprecated the sending "no-op" message to prevent session timeout. As an alternative to sending "no-op", you can send a silence audio data to prevent session timeout. According to the documentation:
"Sending audio data, including silence, to the service to avoid the 30-second >session timeout. You will be charged for any data sent to the service, >including the silence that you send to extend the session."
So I tried this:
def keepAlive(self):
data = {"action": "start", "content-type": "audio/l16;rate=16000", "inactivity_timeout":-1}
self.send(json.dumps(data).encode('utf8'), binary)
reccmd = ["arecord", "-f", "S16_LE", "-r", "16000", "-t", "raw"]
p = subprocess.Popen(reccmd, stdout=subprocess.PIPE)
data = p.stdout.read(1024)
self.send(bytearray(data), binary=True)
self.send({"action": "stop"})
However, I received this error:
Msg received: {u'error': u'could not detect endianness after looking at the tail 924 non-zero byte string in a data stream of 1024 bytes. Is the bytestream really PCM data?'}
The websocket is also closed immediately after that. What is the correct way to send silence audio data to Watson STT? Or is there any other workaround to prevent session timeout?