innFactory / react-native-dialogflow

A React-Native Bridge for the Google Dialogflow (API.AI) SDK
https://innfactory.de/softwareentwicklung/ui-ux/sprachsteuerung-mit-api-ai-in-einer-react-native-app/
MIT License
200 stars 64 forks source link

Multiple results returned from iOS version #47

Closed gunslingerfry closed 6 years ago

gunslingerfry commented 6 years ago

New multiple results problem this time. In between startListening and stopListening multiple results will get returned from Voice.onSpeechResults and therefore multiple calls to Dialogflow.

Either you are making an assumption about when the onSpeechResults event is supposed to return on iOS or react-native-voice is returning partial results in the onSpeechResults event.

Another ignorant attempted fix:

dialogflow2.setConfiguration = async function (clientEmail, privateKey, languageTag, projectId) {   
    ...

    let mostRecentResults = null;                                                                                                                                          
    Voice.onSpeechEnd = (c) => {                                                                                                                                           
        if (mostRecentResults != null) {                                                                                                                                   
            let clonedResult = JSON.parse(JSON.stringify(mostRecentResults.value[0]));                                                                                     
            mostRecentResults = null;
            dialogflow2.requestQuery(clonedResult, dialogflow2.onResult, dialogflow2.onError);                                                                             
            dialogflow2.onListeningFinished(c);                                                                                            
        }                                                                                                                                                                  
    };                                                                                                                                                                     

    Voice.onSpeechResults = (result) => {                                                                                                                                  
        if (result.value) {                                                                                                                                                
            mostRecentResults = result;                                                                                                                                    
        }                                                                                                                                                                  
    }   
}
spoeck commented 6 years ago

Thanks for this issue Should be fixed with version 3.2.1