Home Community Blog Buy Now

Misty Community Forum

Unknown error from response Google STT & Way to handle different Json response for call back to TTS

Hi misty team,
After recently 2 update with regard to GoogleCaptureSpeech , it become really unstable i keep getting String “0” or True after STT to detect transcribe text and it got stuck in the program.
Also i would like to ask which is the best way to implement handle different JSON response from callback to pass to TTS ? I tried using misty.set or initialize variable to undefined data/value but the program will be stuck in loop.
with snippet code exampe for better explaination and understanding

// callback from sendExternalRequest(Google STT) questionResponse
function _questionResponse(data){
//** How can i use condition statement e.g if ,else if to check for different JSON responsed **/

if(data.Result.ResponseObject.Data != "{}\n"){

    let _data = JSON.parse(data.Result.ResponseObject.Data);

 //*** i have tried to check for if ((_data[0].text) !== undefined) , it does the key is not set well with misty.Set sdk method ***/ 
//*** Let say i have two different response will be varied from callback of data object ***/
//*** Note only one of the two below will be valid text based on the from the json key property. ***//
//*** To make it clear one of the two variable will be undefined ***/ 
    let jsonResTxt = _data[0].text; 
    let jsonResCustomTxt = _data[0].custom.text;

    misty.Set("rasaResponseTxt",jsonResTxt, false);

    misty.Set("rasaCustomResponseTxt",jsonResCustomTxt, false);

    misty.Debug("Debug key speechTTxt (Before findIntentModel()): " + misty.Get("speechTTxt"));

    findIntentModel(misty.Get("speechTTxt")); // Retrieve Intent from user speech.



function findIntentModel(stt_result){

    let mess_id = 1234;

    let arguments = {

        "message_id": mess_id,

        "text": stt_result


    misty.SendExternalRequest("POST","http://9ba02f8642f0.ngrok.io/model/parse",null,null,JSON.stringify(arguments), false, false, null, "application/json", "_intentModelResponse");


function _intentModelResponse(res){

    if(res.Result.ResponseObject.Data != "{}\n"){

        let _res = JSON.parse(res.Result.ResponseObject.Data);

        misty.Debug("JSON INTENT Response: "+_res.intent.name);

        let intent_name = _res.intent.name ;


        if(intent_name == "greet")




        else if(intent_name == "weather_in_city"){










Hope to hear from you guys soon . Thanks for reading

i solved the undefine with the solution :

if(typeof _data[0].text !== "undefined"){
        misty.Set("rasaResponseTxt",_data[0].text, false);
    else if(typeof _data[0].custom.text !== "undefined"){
        misty.Set("rasaCustomResponseTxt",_data[0].custom.text, false);
        misty.Set("rasaCustomResponseIcon",_data[0].custom.icon, false);

But the GoolgeCaptureSpeech Return from STT still return me with “0” or boolean true has not resolved.

Hi @cp_sridhar , would you mind helping me address this problem with GoogleCaptureSpeech something returning “0” or boolean true . These two results causing my SendExternalRequest to an undefined data return causing my misty script to stuck or hang in a loop. Thanks

Hi @believeitcode ,

Sorry for the delay, I totally missed this one. Have you already solved it?

Reg - Issue with GoogleCaptureSpeech returning “0” or a bool :
I don’t completely understand which part of the response you are referring to here that is carrying the value of “0”/bool. Below are some info related to this based on my understanding. If this isn’t what you are looking for, please share the whole response with the “0” or bool so I can look at it and get back to you :slight_smile:

Every GoogleCaptureSpeech response that comes into VoiceRecord event’s callback has two parameter Success and SpeechRecognitionResult.

Success - will either be True or False indicating the status of audio recording by itself. If there was complete silence and Misty never picked up any speech this could be False.
SpeechRecognitionResult - will contain the STT result. This can be a valid sting if google was able to parse the audio or it can be null if google couldn’t extract audio from the text.
There are chances you can get a Success: True and SpeechRecognitionResult: null (audio recording was successful but STT parsing from that audio was not). I would recommend doing a null check here before using the STT result.

Here is a simple example : MistySkills/captureSpeech.js at master · CPsridharCP/MistySkills · GitHub
In this example I would check if stt_result is not null before using it with _intentModelResponse and _questionResponse.

Reg - Handling date between callbacks:
Misty.Set and misty.Get are the way to go!

Hi CP , its the result speech to text from the transcribed text return to me ‘0’ or boolean true sometimes. I will check again does the problem still occurs . The only way now I can resolve will be something similar to null check . I will get back to you when I have misty on hand and tested it. Thanks