question

usernickyang avatar image
usernickyang asked ·

Error reading entity from input stream

Hi,

When I send a Recognize event like example 1 https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/avs-http2-requests,

I always get the 500 response code and the message is {"header":{"namespace":"System","name":"Exception","messageId":"d33d8627-9014-4331-9f64-5cd2f3e9bc9d"},"payload":{"code":"INTERNAL_SERVICE_EXCEPTION","description":"Error reading entity from input stream."}}.

Is it related to the audio file I send to the AVS?

Here is the infomation about the audio file.

weather.m4a File Size (Bytes): 12,826

[Format] Format (Short Name): mov,mp4,m4a,3gp,3g2,mj2 Format (Long Name): QuickTime/MPEG-4/Motion JPEG 2000 format Duration: 00:00:04.41 Duration (Microseconds) 4,415,938 Bit Rate (bits/sec): 23,235 Number of Streams: 1

[Metadata] major_brand: M4A minor_version: 512 compatible_brands: isomiso2 encoder: Lavf55.19.100

[Stream #0] Type: Audio Codec (Short Name): aac Codec (Long Name): Advanced Audio Coding Codec Tag: 0x6134706d Codec Tag (String): mp4a Codec Time Base: 0/1 Time Base: 1/16000 Real Base Frame Rate: 0/0 Average Frame Rate: 0/0 Duration: 00:00:00.41 Duration (Microseconds) 70,655 Bit Rate (bits/sec): 21,369 Number of Frames: 69

Channels: 1 Sample Rate (Hz): 16,000 Bit Rate: 16 bits (Integer)

[Metadata] language: eng

And also if there is a sample code about how to record the exact format audio file in android would help a lot.

alexa voice service
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered ·

Are you still blocked here? The SynchronizeState event and the Recognize event contexts should have all client component states - SpeechSynthesizer included. See: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/reference/speechrecognizer#Recognize%20Event

I would recommend checking your HTTP request to make sure there are not any non-UTF-8 characters in your request.

1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks a lot!

It turns out that if I don't send the SpeechSynthesizer state, it works well.

0 Likes 0 ·
usernickyang avatar image
usernickyang answered ·
Here are the related codes. RequestBody audioBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addPart(Headers.of ("Content-Disposition", "form-data; name=\"metadata\""), RequestBody.create(MediaType.parse("application/json; charset=utf-8"), audioJson())) .addPart(Headers.of("Content-Disposition", "form-data; name=\"audio\""), RequestBody.create (MediaType.parse("application/octet-stream"), audioFile)).build(); Request request3 = new Request.Builder().url(" https://avs-alexa-na.amazon.com/v20160207/events").post (audioBody).addHeader("authorization", "Bearer " + token).addHeader("content-type", "multipart/form-data; " + "boundary=--this-is-a-boundary--").build(); try { Response response = client.newCall(request3).execute(); Log.i(TAG, "[audio]code: " + response.code()); Log.i(TAG, "[audio]isSuccessful: " + response.isSuccessful()); Log.i(TAG, "[audio]string: " + response.body().string()); } catch (IOException e) { e.printStackTrace(); } Here is what the audioJson() returns. JSONObject jsonObject = new JSONObject(); JSONArray context = new JSONArray(); JSONObject ap = new JSONObject(); JSONObject apHeader = new JSONObject(); apHeader.put("namespace", "AudioPlayer"); apHeader.put("name", "PlaybackState"); JSONObject apPayload = new JSONObject(); apPayload.put("token", "play1234"); apPayload.put("offsetInMilliseconds", 0); apPayload.put("playerActivity", "PLAYING"); ap.put("header", apHeader).put("payload", apPayload); JSONObject sp = new JSONObject(); JSONObject spHeader = new JSONObject(); spHeader.put("namespace", "Speaker"); spHeader.put("name", "VolumeState"); JSONObject spPayload = new JSONObject(); spPayload.put("volume", 50); spPayload.put("muted", false); sp.put("header", spHeader).put("payload", spPayload); JSONObject ss = new JSONObject(); JSONObject ssHeader = new JSONObject(); ssHeader.put("namespace", "SpeechSynthesizer"); ssHeader.put("name", "SpeechState"); JSONObject ssPayload = new JSONObject(); ssPayload.put("token", "play1234"); ssPayload.put("offsetInMilliseconds", 0); ssPayload.put("playerActivity", "IDLE"); ss.put("header", ssHeader).put("payload", ssPayload); context.put(ap).put(sp); context.put(ss); jsonObject.put("context", context); JSONObject event = new JSONObject(); JSONObject evHeader = new JSONObject(); evHeader.put("namespace", "SpeechRecognizer"); evHeader.put("name", "Recognize"); evHeader.put("messageId", "msgId-123"); evHeader.put("dialogRequestId", "dialogRequestId-124"); JSONObject evPayload = new JSONObject(); evPayload.put("profile", "CLOSE_TALK"); evPayload.put("format", "AUDIO_L16_RATE_16000_CHANNELS_1"); event.put("header", evHeader).put("payload", evPayload); jsonObject.put("event", event); return jsonObject.toString(); Hope the code would help analyze.
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

usernickyang avatar image
usernickyang answered ·
Here's another information. After I send a SynchronizeState event to the AVS, I always get a 204 respond code. I don't know if it's related to the error reading entity problem.
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

elstryan@Amazon avatar image
elstryan@Amazon answered ·
Hi, A 204 response for a SynchronizeState is correct. For the audio format that you are sending to AVS - it should be encoded: -> Linear PCM -> 16kHz sample rate -> Single channel -> Little endian byte order Here is a snippet of how to configure your audio recorder in Android to do this: int SAMPLE_RATE_IN_HZ = 16000; int MIN_BUFFER_SIZE = AudioRecord.getMinBufferSize(SAMPLE_RATE_IN_HZ, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); AudioRecord audioRecorder = new AudioRecord(AudioSource.MIC, SAMPLE_RATE_IN_HZ, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, MIN_BUFFER_SIZE);
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

usernickyang avatar image
usernickyang answered ·
Hi, Thanks a lot for your reply. I can get a correct response without the SpeechSynthesizer part in the context request now. Part of the request is like this. "context": [ { "header": { "namespace": "AudioPlayer", "name": "PlaybackState" }, "payload": { "token": "play1234", "offsetInMilliseconds": 50, "playerActivity": "IDLE" } }, { "header": { "namespace": "Speaker", "name": "VolumeState" }, "payload": { "volume": 50, "muted": false } } ], But when I send a SynchronizeState or Recognize event with correct audio file with the request below, I still get aError reading entity from input stream response. "context": [ { "header": { "namespace": "AudioPlayer", "name": "PlaybackState" }, "payload": { "token": "play1234", "offsetInMilliseconds": 50, "playerActivity": "IDLE" } }, { "header": { "namespace": "Speaker", "name": "VolumeState" }, "payload": { "volume": 50, "muted": false } }, { "header":{ "namespace":"SpeechSynthesizer", "name":"SpeechState" }, "payload":{ "token":"nick8723", "offsetInMilliseconds":0, "playerActivity":"PLAYING" } } ], Even if I change the SpeechSynthesizer part to a Alerts part, I also get the same error. So I'm a little confused why this happens and is there any limit of the context part? Thanks in advance.
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.