assistant-sdk-cpp icon indicating copy to clipboard operation
assistant-sdk-cpp copied to clipboard

Why is the chunk_size set to 20kB?

Open mpoullet opened this issue 7 years ago • 6 comments

in audio_input_file.cc the chunk_size is set to 20kB. Why?
Is there any official documentation/guidelines explaining this?

mpoullet avatar Oct 23 '18 13:10 mpoullet

I don't think there's a specific reason why it has to be 20KB.

Fleker avatar Oct 23 '18 17:10 Fleker

It's possible to push it to 31kB but after that I get

assistant_sdk failed, error: Invalid 'audio_in': audio frame length is too long.

see e.g. the comment in this Node.js fork too: https://github.com/albertreed/google-assistant/blob/master/components/conversation.js#L28

At the moment run_assistant_file is pretty lame compared to run_assistant_audio. I'm wondering if it'd be ok to switch to a higher value for chunk_size.

mpoullet avatar Oct 24 '18 12:10 mpoullet

Looking at the proto definition for the field it's of type bytes.

To speculate, 31KB is very similar to 2^15 (32768 bytes), so it may be an encoding limitation and may provide the reason for a ceiling of chunk_size.

Fleker avatar Oct 24 '18 19:10 Fleker

I obtain better results when the chunk_size and the delay match, e.g. 16kB (=500ms worth of audio input) and 500ms delay. As it is now it doesn't make much sense: 20kB (=625ms worth of audio) and 1s=1000ms delay? My first choice was to choose a chunk_size of 32kB to match the 1s delay but it's not possible, so I think a choice of 16kB/500ms would make much more sense in this example. Could I open a PR for this?

mpoullet avatar Nov 02 '18 08:11 mpoullet

Yeah you can open a PR for this. I'm not entirely sure what you mean by 'better results', but it may make sense to match the delay.

Fleker avatar Nov 02 '18 17:11 Fleker

By better results I mean the overall execution time of run_assistant_file, e.g. (very rough measurements):

  • original commit (20kB/1000ms):
time ./run_assistant_file --input resources/weather_in_mountain_view.raw --output resources/response.raw --credentials ./credentials.json 
assistant_sdk response:
Looks like a pleasant day
Currently in Mountain View it's 55 and clear. Today, it'll be sunny, with a forecast high of 72 and a low of 49.
---
( More on weather.com )

real	0m3.480s
user	0m0.080s
sys	0m0.016s
  • by matching size and delay (e.g. 16kB/500ms or 31kB/1000ms):
time ./run_assistant_file --input resources/weather_in_mountain_view.raw --output resources/response.raw --credentials ./credentials.json 
assistant_sdk response:
Looks pleasant outside
Right now in Mountain View it's 55 and clear. Today, it'll be sunny, with a forecast high of 72 and a low of 49.
---
( More on weather.com )

real	0m2.027s
user	0m0.092s
sys	0m0.020s

so about 1s better which is noticeable.

mpoullet avatar Nov 05 '18 09:11 mpoullet