Upload audio training data using node.js on edge device

I would like to use Node-RED (based on node.js) to upload my recorded audio files to the ingestion service.

On page https://docs.edgeimpulse.com/reference#data-acquisition-format I have found a Node.js example for 'Content-Type': 'application/json' but is it possible to use this content type for uploading audio files ? If so how should the wav audio file be put in the body ?

If not possible: is there some example describing the upload of an audio file (or binary data) for 'Content-Type': 'application/cbor' for Node.js ?

Currently I am using janvda/node-red-contrib-cbor (which is based on hildjj/node-cbor version v5.0.2) for converting json to cbor but once the json structure becomes a bit more complex this doesn’t seem to work properly when I tested it as follows:

  1. manually copy paste the buffer output in string format from node-red debug node to https://codebeautify.org/string-hex-converter and convert it to hex.
  2. copy paste the hex string http://cbor.me/ in the right window and convert it back. In that case it reports error like: Out of bytes to decode (need at least 17 bytes more)

An example fo the problem

  1. The input json string:
  1. the json string converted to cbor (in string format)
  1. cbor this time converted to hex format:
  1. cbor converted back gives
{"protected": {"ver": "v1", "alg": "none", "iat": 1595339766}, "\u0006\u0017\x96\xC6\xF6\u0016JF\xB6FWf\x966U\xF6\xE6\u0016\xD6W\u0016\u00163": {["\xA6\u00133\xA3\u0006\u0013\xA3&C\xA3\u0016&\xB6FWf\x966U", undefined, h'97065734449534']: -21, simple(18): 20(-7558501), "\u0514\xF5C\u0003\u0014\u0016\xB6\x96\xE7FW'f\u0016\xC5\xF6\xD7": -1735615855}}

and reports following error: 71 unused bytes after the end of the data item

Hi @janvda,

You can upload audio samples similarly as with other sensors by filling the values field with your audio samples as an array. Also you derive the interval_ms value from your audio sampling frequency and set the sensors value as follows:

sensors: [{ name: 'audio', units: 'wav' }]

Check also the code example of our cli uploader makeWav function, it uses the ingestion service to import wav files.


1 Like

I have found the issue. The problem is located in step 2 where I am copy pasting the cbor data in string format. Most likely the cbor data in string format doesn’t contain all binary data (all bits).

I fixed this issue by replacing step 2 and 3 by a step in node-red that converts the cbor buffer to a hex string using the command buffer.toString('hex'). This hex string when used in http://cbor.me/ (see step 4) properly converted back to the original json structure.

1 Like

@janvda, interesting. You mean this one?

That decodes fine for me at cbor.me.

Or do you mean:

That’s a special case with both the CBOR file (until ff) and then binary payload in int16 format, so won’t decode fully in cbor.me/

No, the problem was related to the CBOR data I have created, not with the one on page : https://docs.edgeimpulse.com/reference#data-acquisition-format (that is working fine).

This problem is in the mean time fixed (see 2 comments ago).

FYI: I have reported my issue with sending cbor data using node-red in the node-red forum:

Yeah my suggestion with Node would be to use JSON instead. I’ve found CBOR libraries to be of disappointing quality.

I have seen the comment from @aurel concerning JSON option, but that would mean that I need to convert my binary wav file to an array.

I have found a solution:

  • instead of using application/cbor as content type, I should use application/octet-stream.

With this change I managed to upload the following valid audio sample to my edge impulse dashboard via node-red.