Exported audio wav file is distorted

I have a PCM buffer that has to be saved as a file. The raw audio is not distorted and by playing it with the node-red-contrib-play-audio works as expected.
When I try to save it using the file node, the file saved is really distorted.
I use node-red-contrib-wav to add the wav headers.

Here a mini flow to demonstrate the issue:

[{"id":"3f882ab9.642dd6","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"5d269671.055368","type":"wav-headers","z":"3f882ab9.642dd6","name":"","action":"add","channels":1,"samplerate":"11025","bitwidth":"8","x":670,"y":120,"wires":[["dba3db72.3f0a18","5af79fed.b692b"],[]]},{"id":"dba3db72.3f0a18","type":"play audio","z":"3f882ab9.642dd6","name":"","voice":"9","x":890,"y":80,"wires":[]},{"id":"5af79fed.b692b","type":"file","z":"3f882ab9.642dd6","name":"","filename":"/tmp/test.wav","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"binary","x":890,"y":120,"wires":[[]]},{"id":"c7bdab08.cc0088","type":"inject","z":"3f882ab9.642dd6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["8abe4665.7cb898"]]},{"id":"8abe4665.7cb898","type":"http request","z":"3f882ab9.642dd6","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"http://mauvecloud.net/sounds/pcm0811m.wav","tls":"","persist":false,"proxy":"","authType":"","x":270,"y":120,"wires":[["7597b016.b33b3"]]},{"id":"7597b016.b33b3","type":"wav-headers","z":"3f882ab9.642dd6","name":"","action":"del","channels":1,"samplerate":22050,"bitwidth":16,"x":460,"y":120,"wires":[["5d269671.055368"],[]]}]

@BartButenaers I'm tagging you since maybe you know how to help!

Hey Alberto (@albydnc),

In those cases, always try to simplify your flow as much as possible to find the root case.
Seems not to be related to my node-red-contrib-wav node, because it also fails with this simple flow:

image

[{"id":"4feed947.cded28","type":"file in","z":"b3db206e.b7139","name":"","filename":"/tmp/test.wav","format":"","chunk":false,"sendError":false,"encoding":"none","x":410,"y":620,"wires":[["5c99ef16.93d88"]]},{"id":"57de7ec8.184eb","type":"inject","z":"b3db206e.b7139","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":620,"wires":[["4feed947.cded28"]]},{"id":"5c99ef16.93d88","type":"play audio","z":"b3db206e.b7139","name":"","voice":"9","x":590,"y":620,"wires":[]},{"id":"a833df3d.c5369","type":"file","z":"b3db206e.b7139","name":"","filename":"/tmp/test.wav","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"binary","x":590,"y":520,"wires":[[]]},{"id":"359ebe7c.62df62","type":"inject","z":"b3db206e.b7139","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":520,"wires":[["85018a22.774868"]]},{"id":"85018a22.774868","type":"http request","z":"b3db206e.b7139","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"http://mauvecloud.net/sounds/pcm0811m.wav","tls":"","persist":false,"proxy":"","authType":"","x":410,"y":520,"wires":[["a833df3d.c5369"]]},{"id":"3bc85905.fa6366","type":"comment","z":"b3db206e.b7139","name":"Step 1 : download the WAV file and store it in a file","info":"","x":350,"y":480,"wires":[]},{"id":"8231499.8dfecb8","type":"comment","z":"b3db206e.b7139","name":"Step 2 : play the downloaded WAV file","info":"","x":310,"y":580,"wires":[]}]

The downloaded WAV is saved as binary which should be fine... The WAV contains both binary data (i.e. the audio samples themselves) and headers (to explain to the player how the data has been recorded). And from this discussion I assume that both need to be stored as binary! No clue now why this audio becomes distorted ...

But at the moment I am recovering from a surgery, so not in the mood for an in depth analysis :pleading_face: Since this problem is about storing data in a file, perhaps other community members can help you now. Otherwise I will have a look in a week or so... But then you should mention me again to get my attention!

Good luck with it!
Bart

When you play the stored file with a third-party player (e.g. VLC) then it becomes clear that the problem is somewhere in the File Write node (not in the File Read node)! You can see e.g. here that the file needs to be in Little Endian format. I have no idea whether that is the problem, or how it works or how you can solve it ...

Thanks for the help!
I opened a new discussion to take care of the issue.

Hope you get well soon!

Works ok if you use default encoding.
Any of the others use iconv.encode - not sure why encode of (binary) buffer to binary changes it but it does :frowning:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.