Send audio from android to Node Red / Tasker tutorial for voice2json

How to record your voice and send it to Node Red on Android mobile phones


This description is basically a step by step tutorial. It’s made to get a stream / buffer of your recorded audio sample to Node Red. This will only guide you to create a Tasker app. This is mainly for sending audio to Node Red. A use case is to translate your recorded voice by voice2json into text. I highly recommend node-red-contrib-voice2json as this is more or less an addition to it.

Hardware you need:

  1. Android Smartphone
  2. Any system in your network able to run Node Red

Software you need:

  1. Tasker
  2. Node Red installation running the flow example below***
  3. Sox utils by Johannes Kropf (node-red-contrib-sox-utils)
  4. Recommended: Voice2Json tutorial / nodes by Johannes Kropf

Tasker installation:

  1. First things first: Install Tasker from the google play store: Tasker
  2. After your installation open it. It could be useful to grand tasker it root access but for this case it’s not needed.
  3. Tasker wants you to create a new profile but this is not needed. (skip it) I also recommend to disable notifications if you are running Android 8 or later (tasker will ask to disable them). This will avoid to get flooded with notification messages.

Create your audio recorder tasker flow:

Create a new task flow:

Open Tasker navigate to the tab “Tasks” and you should finally look similar to this: pic1
Add a new task flow (Press the circle with the plus inside) name it “Audio2NodeRed”.

Add “File Delete” task:

Select a category (press the “plus button” again to do) -> Select “File” -> “Delete File” -> Grand Tasker access -> Select the magnifying glass -> Navigate to “Download” folder -> Complete the line “Download/” to “Download/rec.awb” -> Enable “Continue Task After Error” -> Press the arrow in the upper left corner.
Nice! Your first task is finished!

Add “Record Audio” task:

Select a category (press plus button) -> Select “Media” -> “Record Audio” -> Grand Tasker access -> Select the magnifying glass -> Navigate to “Download” folder -> Complete the line “Download/” to “Download/rec” -> Select Codec “AMR Wideband” -> Select Format “AMR Wideband” -> Press the arrow in the upper left corner.

Add “Pause Task” task:

Select a category (press the plus again to do) -> Select “Task” -> “Wait” -> Grab the slider “Seconds” to a value of 8 second (This will be the fixed time of recording length. Change it to a value you think is good for your project.) -> Press the arrow in the upper left corner.

Add “Record Audio Stop” task:

Select a category (press plus button) -> Select “Media” -> “Record Audio Stop” Press the ß arrow in the upper left corner.

Add “HTTP Request” task:

Select a category (press plus button) -> Select “Net” -> “HTTP Request” -> Select as method: “PUT” -> Select as URL your Node Red URL with port followed by the path where a node is listening to take the audio request. Mine is “” as example. Select the magnifying glass -> Navigate to “Download” folder -> Complete the line “Download/” to “Download/rec.awb” -> Press the arrow in the upper left corner.

If you have done well it should look like this: pic2

Adding the task flow to the desktop

Now you can feel free to improve this task flow. I for myself added a sound file that will play on the start and another one that plays at the end of the task flow (I will not describe this). This gives the possibility to use the task flow without creating a gui. In the next step you can create a tasker app / icon on your home screen of your phone to make everything a bit more comfortable.

Add an Icon to your task flow:

Go to tab “Tasks” -> Click on your Task flow to get to “Task edit” -> At the bottom is a quadratic icon, click it -> Select an icon for your task flow -> Press the arrow in the upper left corner.

Make an application from your task flow:

Go to tab “Tasks” -> Hold your finger on your Audio2NodeRed task flow until it´s marked -> Click at the three dots at the upper right corner -> Click “Export” -> Click “As App” -> Rename the package to “audio2nodered.package” -> Press the arrow in the upper left corner -> Agree to install the application -> then ok.

Test your application:

Navigate to your application overview -> Search for your "“Audio2NodeRed” app -> click the app to start it. -> Use the popup or your own way to navigate to the “App-Info” of your application -> Select “Rights” and grand your application the rights it needs. (Should be “Microphone” and “Folders” or so.). Now start your app. Remember: You need the listener flow in Node Red running to check if your audio is sent to Node Red like expected.

Flow example (Derived from Johannes Kropfs example):

[{"id":"db1965bb.04c2e","type":"tab","label":"Tasker Voice2Json Example","disabled":false,"info":""},{"id":"bfc12739.6bb718","type":"http in","z":"db1965bb.04c2e","name":"","url":"/audio","method":"put","upload":true,"swaggerDoc":"","x":80,"y":240,"wires":[["2b3c363f.233f62","81300d71.26655","b611d1ee.ab6e4"]]},{"id":"4cf50d8.eb8de74","type":"sox-convert","z":"db1965bb.04c2e","name":"","conversionType":"wav","outputToFile":"buffer","manualPath":"","wavMore":true,"wavByteOrder":"-L","wavEncoding":"signed-integer","wavChannels":1,"wavRate":16000,"wavBits":16,"flacMore":false,"flacCompression":8,"flacChannels":1,"flacRate":16000,"flacBits":16,"mp3More":false,"mp3Channels":2,"mp3Rate":44100,"mp3BitRate":128,"oggMore":false,"oggCompression":3,"oggChannels":2,"oggRate":44100,"debugOutput":true,"x":450,"y":240,"wires":[["75ca3afb.7886fc","f3f7c191.b94108","128f3c93.8f74b3"],[]]},{"id":"f3f7c191.b94108","type":"voice2json-stt","z":"db1965bb.04c2e","name":"","voice2JsonConfig":"ab2db867.7ea11","inputField":"payload","controlField":"control","outputField":"payload","autoStart":true,"x":660,"y":240,"wires":[["d9eb1521.8484d8","4a0e65b2.5afd0c"]]},{"id":"d9eb1521.8484d8","type":"debug","z":"db1965bb.04c2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":870,"y":180,"wires":[]},{"id":"2b3c363f.233f62","type":"debug","z":"db1965bb.04c2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":290,"y":180,"wires":[]},{"id":"75ca3afb.7886fc","type":"debug","z":"db1965bb.04c2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":180,"wires":[]},{"id":"81300d71.26655","type":"function","z":"db1965bb.04c2e","name":"setFormat","func":"msg.format = \"awb\";\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":240,"wires":[["4cf50d8.eb8de74"]]},{"id":"4a0e65b2.5afd0c","type":"voice2json-record-command","z":"db1965bb.04c2e","name":"","voice2JsonConfig":"ab2db867.7ea11","inputField":"payload","outputField":"payload","x":930,"y":240,"wires":[["842c3efd.47acc8"]]},{"id":"842c3efd.47acc8","type":"debug","z":"db1965bb.04c2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":240,"wires":[]},{"id":"128f3c93.8f74b3","type":"file","z":"db1965bb.04c2e","name":"WriteLineToFile","filename":"/home/pi/Downloads/rec.awb","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":660,"y":300,"wires":[[]]},{"id":"b611d1ee.ab6e4","type":"http response","z":"db1965bb.04c2e","name":"","statusCode":"200","headers":{},"x":280,"y":300,"wires":[]},{"id":"ab2db867.7ea11","type":"voice2json-config","z":"","profilePath":"/home/pi/.config/voice2json","name":"","sentences":"[GetTime]\nwie spät ist es\nsag mir die uhrzeit\n\n[GetTemperature]\nwie ist die temperatur\nwie (heiß | kalt) ist es\n\n[GetGarageState]\nist das garagentor (offen | geschlossen)\n\n[ChangeLightState]\nlight_name = (wohnzimmerlampe | garagenlicht) {name}\nlight_state = (ein | aus) {state}\nschalte (die | das) <light_name> <light_state>","slots":[],"removeSlots":false}]

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