How to get "text" from "speech to text" that needed using in function node

var topi =msg.topic;
msg.topic = "SELECT VOICE FROM USER";//data voice from database

var transcription =msg.transcription;//data from microphone (input data)


if(topic==transcription){
    
    //upload name to history database from user database
    msg.topic = INSERT INTO HISTORY (NAME) VALUES (SELECT NAME FROM USER WHERE VOICE = transcription);
    
    //audio sound
    msg.payload="Welcome";
    
    
}

if(topic!=transcription){
    
    //audio sound
    msg.payload="Access Denied";
    
}

I want compare the text (generate from speech to text) that i get from microphone with the data in database.
So, how to write in function node to get that text?
is that using variable transcription ?(I think my code is wrong)

And i want upload the NAME 's data to HISTORY database from USER database if the input text from microphone is same in USER database.
How to write the correct it?

You have a typo. you define your var your comparing as var topi = msg.topic instead of var topic = msg.topic so when you try to reference topic in your if statement its not declared.

Johannes

okey, but still have error

What does the debug say? Can you show as a debug of the complete msg object the speech to text node puts out?

is not a string.... you're going to need some quotes " in there...

1 Like
[{"id":"ee60c3e3.69e03","type":"mysql","z":"98f4cc17.965b","mydb":"7c738c44.e9a364","name":"DB_MYSQL","x":670,"y":260,"wires":[[]]},{"id":"5d766314.29f91c","type":"function","z":"98f4cc17.965b","name":"Verify Speech","func":"var topic =msg.topic;\nmsg.topic = \"SELECT VOICE FROM USER\";//data voice from database\n\nvar transcription =msg.transcription;//data from microphone (input data)\n\n\nif(topic==transcription){\n    \n    //upload name to history database from user database\n    msg.topic = INSERT INTO HISTORY (NAME) VALUES (SELECT NAME FROM USER WHERE VOICE = transcription);\n    \n    //audio sound\n    msg.payload=\"Welcome\";\n    \n    \n}\n\nif(topic!=transcription){\n    \n    //audio sound\n    msg.payload=\"Access Denied\";\n    \n}","outputs":2,"noerr":17,"x":420,"y":320,"wires":[["ee60c3e3.69e03","5c178158.4733f"],["91d9fd2a.af375"]]},{"id":"2b9d8dd1.390142","type":"watson-speech-to-text","z":"98f4cc17.965b","name":"","alternatives":1,"speakerlabels":true,"smartformatting":false,"lang":"en-US","langhidden":"en-US","langcustom":"NoCustomisationSetting","langcustomhidden":"","custom-weight":"0.5","band":"NarrowbandModel","bandhidden":"NarrowbandModel","keywords":"","keywords-threshold":"0.5","word-confidence":false,"password":"","apikey":"aEfplzvlM_B8MA01nsDy3fj6b3CnG6dOQEGISr2gHxxk","payload-response":true,"streaming-mode":false,"streaming-mute":false,"auto-connect":false,"discard-listening":false,"disable-precheck":false,"service-endpoint":"https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/4ec7115d-1cbf-4ac7-b141-9c9a675fbdac","x":160,"y":340,"wires":[["338d77fb.3e9f88","5d766314.29f91c"]]},{"id":"9c343afa.80e438","type":"microphone","z":"98f4cc17.965b","name":"","x":110,"y":240,"wires":[["2b9d8dd1.390142"]]},{"id":"338d77fb.3e9f88","type":"debug","z":"98f4cc17.965b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"transcription","targetType":"msg","x":410,"y":380,"wires":[]},{"id":"595861ce.b689c","type":"play audio","z":"98f4cc17.965b","name":"Access Denied","voice":"0","x":880,"y":400,"wires":[]},{"id":"d44f4fcb.4f531","type":"play audio","z":"98f4cc17.965b","name":"Welcome","voice":"0","x":880,"y":320,"wires":[]},{"id":"67ca3d11.6eb434","type":"comment","z":"98f4cc17.965b","name":"","info":"Verify the speech from microphone are same with “VOICE” in User table or not.\n\nIf same, then upload that particular user's name to HISTORY table and with the output sound \"Welcome\".\n\nIf not same just output sound \"Access denied\".","x":400,"y":280,"wires":[]},{"id":"4944a410.7d505c","type":"comment","z":"98f4cc17.965b","name":"","info":"To see the speech from microphone to let us can check the speech is from microphone is what we want speech.","x":420,"y":420,"wires":[]},{"id":"91d9fd2a.af375","type":"watson-text-to-speech","z":"98f4cc17.965b","name":"","lang":"en-GB","langhidden":"en-GB","langcustom":"NoCustomisationSetting","langcustomhidden":"","voice":"en-GB_KateV3Voice","voicehidden":"","format":"audio/wav","password":"","apikey":"kxIPJUsW_2zjWfDnhr8yNS4oPK5BPM4ywQGbZcQL9ZLl","payload-response":false,"service-endpoint":"https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/2ead23d4-2528-416d-8e53-c40a658d6bfd","x":680,"y":400,"wires":[["595861ce.b689c"]]},{"id":"5c178158.4733f","type":"watson-text-to-speech","z":"98f4cc17.965b","name":"","lang":"en-GB","langhidden":"en-GB","langcustom":"NoCustomisationSetting","langcustomhidden":"","voice":"en-GB_KateV3Voice","voicehidden":"","format":"audio/wav","password":"","apikey":"kxIPJUsW_2zjWfDnhr8yNS4oPK5BPM4ywQGbZcQL9ZLl","payload-response":false,"service-endpoint":"https://api.us-south.text-to-speech.watson.cloud.ibm.com/instances/2ead23d4-2528-416d-8e53-c40a658d6bfd","x":680,"y":320,"wires":[["d44f4fcb.4f531"]]},{"id":"7c738c44.e9a364","type":"MySQLdatabase","z":"","host":"165.22.51.44","port":"3306","db":"hireelec_vaes","tz":""}]

this is the flow ...

image

@dceejay

where need put quotes?

What is this line supposed to be/do?
You can only assign certain things to an object key like msg.topic.
It has to be something like string, a number, a boolean or a javascript function.
This is neither.
To make it a string put everything after the = into quotes.
And as far as I see this message your handling doesn’t have a topic.

upload the data.... and the data is user name who's voice text is same from input from microphone only

You are trying to build a payload to write something to a database.
In line 2 The function node has no way to access the data from your database where you saved the user names. So you have to get this data into nodered and save it in a global or flow var to be able to access it in a function node.
Than you don’t just need the topic string but also a msg.payload.
I would recommend for a start that you look into the documentation of nodered and read the chapters about the function node, context data and working with messages.
https://nodered.org/docs/user-guide/
you will probably need a to change your function node to send the database and text to speech messages on 2 different exits as two distinct message objects.
Johannes

Edit unfortunately I don’t know much about how to work with the mysql node.

SELECT VOICE FROM USER; will return the column 'VOICE' from all rows of the 'USER' table.

is that wat you want to do?

Ya...because that VOICE like the password....so, I need recieve the speech from microphone and compare one by one the VOICE in database , if same (mean password correct) , then just upload that particular user's name to HISTORY database.
But now problem is how to write the code in verify speech ( function node) ? How to create or write a variable represent the text that recieved from microphone that genetated by speech to text node?

Ya...because that VOICE like the password....so, I need recieve the speech from microphone and compare one by one the VOICE in database , if same (mean password correct) , then just upload that particular user's name to HISTORY database.
But now problem is how to write the code in verify speech ( function node) ? How to create or write a variable represent the text that recieved from microphone that genetated by speech to text node?

have any idea to write the code? or have any example?

Off hand my answer is NO. You store VOICE in the database - what type of value is it" when you analize it does it become a number that will match an equilivant number for the new sound that just came in?

If so, then you should be able to do a SELECT VOICE FROM USER where VOICE = what-ever-you-call-the-new-sample;

and it will return the single value or give you an indication that nothing was returned.

VOICE in database is in String and new sound is also String when it pass to speech to text node and become text....

so, i need declare one variable that can represent the text from speech to text and compare VOICE in database in String form.

If I understand you right you will need to make a database query to get the content of Users/Voice before this speech to text flow and save it to a flow/global variable so that you can use it in this function as you otherwise wont be able to access it to check if the speech to text result is in it.
So best read about flow and global context and how to work with it.
https://nodered.org/docs/user-guide/context

So put the new sound string in msg.payload and send it to a template node to build your sql query like

select voice from user where user = '{{msg.payload}}'

The result needs to be in msg.topic and before connecting it to the mysql node, attach it to a debug node so you see that the query is correct. And it might be {{payload}} I can never remember.

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