wit-ai / wit-ios

Wit.ai iOS client
Other
222 stars 71 forks source link

WitUploader cancels uploads before completion #17

Closed hactar closed 10 years ago

hactar commented 10 years ago

The SDK works great on fast connections, but on slow connections the WitUploader can lag behind while uploading. If the user presses the mic button to end the request, the WitUploader instantly cancels the upload task. This leads to audio chunks not being uploaded, only part of the sentence being processed server side:

2014-04-28 18:39:42.878 Wave[1779:60b] Stream open completed
2014-04-28 18:39:43.641 Wave[1779:490b] Audio chunk 16000/16000
2014-04-28 18:39:43.642 Wave[1779:3807] Uploading 16000 bytes
2014-04-28 18:39:43.897 Wave[1779:490b] Audio chunk 13496/16000
2014-04-28 18:39:43.898 Wave[1779:3807] Uploading 13496 bytes
2014-04-28 18:39:44.315 Wave[1779:490b] Audio chunk 16000/16000
2014-04-28 18:39:44.465 Wave[1779:1803] Uploading 16000 bytes
2014-04-28 18:39:44.826 Wave[1779:490b] Audio chunk 16000/16000
2014-04-28 18:39:44.828 Wave[1779:3807] Uploading 16000 bytes
2014-04-28 18:39:45.336 Wave[1779:490b] Audio chunk 16000/16000
2014-04-28 18:39:45.339 Wave[1779:3807] Uploading 16000 bytes
2014-04-28 18:39:45.790 Wave[1779:490b] Audio chunk 9344/16000
2014-04-28 18:39:45.791 Wave[1779:490b] Audio chunk 0/16000

Notice the 9344 chunk is never uploaded.

This PR fixes the issue by closing the stream only once all chunks have been uploaded.

blandinw commented 10 years ago

Good catch, thanks!