question

newuser-336fd740-bd6a-4999-b8f6-fe34bc14b4da avatar image
newuser-336fd740-bd6a-4999-b8f6-fe34bc14b4da asked ·

How to parse binary audio attachment from Alexa directive response?

I am using node js to develop.

I been able to send a http/2 request now , the request been able to carry the binary audio attachment.

The request is correct , I can confirm from AVS history information.

but the response is string data .

I will binary audio attachment converted into buffer,write a file or pipe the sream to play, All method can not play !

I know binary audio attachment is mp3 and :

  • 16bit Linear PCM
  • 16kHz sample rate
  • Single channel
  • Little endian byte order

How to parse binary audio attachment ?

Is not binary encode ?

alexa voice serviceapinode_js
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.

had the same problem. I used some code from NET to receive the audio, and it had utf8 encoding

var req = avsClient.request({':method': 'POST',...})
req.setEncoding('utf8') <-- this was wrong, had to simple delete it. req.write(payload)
0 Likes 0 ·
Jordan@Amazon avatar image
Jordan@Amazon answered ·

Hi,

It is difficult to see what the issue is without seeing the code. The response will have a multipart response with one part being JSON for a Speak directive and another part having the attached binary audio. Please take a look a the example responses on this page for more information about how the response is structured. Let us know if you have any additional questions

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.

newuser-336fd740-bd6a-4999-b8f6-fe34bc14b4da avatar image
newuser-336fd740-bd6a-4999-b8f6-fe34bc14b4da answered ·

The answer did not hlep me. I know the page ,but my problem is:How to parse binary audio attachment ?

it is my receive data:

--40bda091-3be1-40ce-acc4-abc6a235405f
Content-Type: application/json; charset=UTF-8

{"directive":{"header":{"namespace":"Speaker","name":"SetMute","messageId":"9ae85c4c-b5c6-48ac-94ea-3312215ce549","dialogRequestId":"SpeechRecognizer-RequestId-20170802114309536"},"payload":{"mute":false}}}
--40bda091-3be1-40ce-acc4-abc6a235405f
Content-Type: application/json; charset=UTF-8

{"directive":{"header":{"namespace":"SpeechSynthesizer","name":"Speak","messageId":"9a0bfccd-80a4-4736-a2e4-506534525c0d","dialogRequestId":"SpeechRecognizer-RequestId-20170802114309536"},"payload":{"url":"cid:KnowledgePrompt.8b380a91-bae5-4035-b438-2daaeff1f5da_1854566336","format":"AUDIO_MPEG","token":"amzn1.as-ct.v1.Domain:Application:Knowledge#ACRI#KnowledgePrompt.8b380a91-bae5-4035-b438-2daaeff1f5da"}}}
--40bda091-3be1-40ce-acc4-abc6a235405f
Content-ID: <KnowledgePrompt.8b380a91-bae5-4035-b438-2daaeff1f5da_1854566336>
Content-Type: application/octet-stream

ID3#TSSELavf57.71.100��d�F
                          !���P��8]tDM.���_̟B��w��w��Ϛ���8��n{©�    ©i�_SDD@�� ϼ�I���ə�,#7�|��DG���:EJd�.�A�����<���d�1�@�t�H)F � ���P��
                                                                                                                                                 ���$d�l���N�d��.sD�7:��W=ý<���s�Y0����_™�����'!�YyB
                      �0\N�Q�]��m��
                                   �ۢ��kg�4sfq�`g�B��0
                                                     11��d�&%&�^�E���>�f���F
��5��]±�=�����↓┘1Vyޯ�┘��� ����'���!)™���WW�⎺#┤│
C�ڇ^£��A├�⎽�I��c��2A1 PH��6�@�:Q�(�N�(5�<��CG│KLIP�▒���┘
����mUR��T��f:�;S����d��޼4��0G�$�U�ڶ���w�n�)�≤����G▒!����π�W
™�→����"�ڎҤ�E��:ޫ�!��5lָjSм>��R�ŷ™:����G���b ��⎺��*e��/�����d�!���&�ELπX�G*↓N�K�#���[┐�B�1���IO���פ�慬���e"^π▒P���
                                                                                                                                �┴)G>ҧ©]�%°���͇:�⎺���7���°�⎼1�◆�AO�����▒�└cJH·�=⎽�U���H��G←�⎺▒8←�����d�!3��V│�_�
�2�5�%���
         ─b��S9©�_��ᛡϫ�†↓�141�X���"!N     ���⎺©"B2�PB�)�R���┘©ڍ9N�&(�W▒��"�;%��v�-Y���oZr��d� ;��V��ث�f'©
�"s���ı�C���C/�\��@�����J£���└^�����C��G±���≤�_C└��R'7��_�┼©V©↑�Z���GMN�
G��_�����ס�d└%�����Pܲ�К▒K┴��↓�����'阊���d��ư☃�┘┌����┴�\≤�ƺC�樄JТ≥▮�1·┼☃�8�┬�⎼�L_⎺�5]I���2��└
�����└@─6=�<©└���3�▒��լ?H��>LA©��VA��▒┬���QI*�M@J↑!�W� ���՝3��d�%$˦����6B⎼⎼�┤�MR�≤��│≠����(��Q��!J�≤�1*(&2�⎻��.�Ӧ���71Ս�?���  �����FjZ1L"�s�����.��i�Ael��:�(P<1�/�jI*��Y=��Β+��ㅧ����d�{Ɍ�����=e����2��9��M�����*�����pn�ie��RX轣h�q�W|�����U'C;6�P©��G��dY_L�?��^JՈ�fh?"-�т7(�X�ϟ=b�"�`|�����.�'@�؞t��d�%���{
nm��,w�����v���PY����O©m�)�͕e{��~��G$��C�����L��| ����j]�(��-R�G���uW5o�>5+�ϗ`�_�(�b!� ��݂I��d�5Ɋ�~��T�Ipf��A)7��u�l��iɿ©f
                                                                                                                                  5™rZT���|����V"C $ՀL©≤��N
PG�⎼
--40bda091-3be1-40ce-acc4-abc6a235405f
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.

Jordan@Amazon avatar image
Jordan@Amazon answered ·

Hi @NewUser-336fd740-bd6a-4999-b8f6-fe34bc14b4da,

Are you using a multipart parsing library? In order to obtain the binary audio you will need to read the first parts of the response as JSON content and the audio part as binary content. We do not have an implementation in NodeJS to provide you, so without seeing any code or errors from your code it will be difficult to help you parse the binary audio. I would recommend looking into some multipart parsing libraries that are available that are available on NodeJS and reading the documentation on those for how to read each part of the response. The process of parsing the response should be similar to the process of sending the request.

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.

vivek@sasken avatar image
vivek@sasken answered ·

how to pase my own audio into binary audio and it to alexa

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.

newuser-d9a8ed29-88a9-4cc2-9378-8039b9b58800 avatar image
newuser-d9a8ed29-88a9-4cc2-9378-8039b9b58800 answered ·

were you able to save the audio attachment as a file? is it playable?

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.