dont work auto stop in ios?
I've seen a lot of statements on StackOverflow that Apple isn't sending the end event when an utterance ends, and just leaves the SFSpeechRecognitionTask open for the full minute default. This is my experience as well. I call the stop() function to manually stop the SFSpeechRecognitionTask. You can combine that with a timer tied to OnSpeechPartialResult event as suggested on this SO answer: https://stackoverflow.com/questions/42530634/sfspeechrecognizer-detect-end-of-utterance
I solved it by playing with timer and OnSpeechPartialResult
@MichaelPintos Mind sharing your solution? It could just be based on the example already provided. Huge thanks!
After finding a solution, I temporarily create a testing code that works for me.
onSpeechEnd(e) {
console.log(this.state.results);
if (Platform.OS === 'ios') {
this.onSend([{text:this.state.results}]);
}
}
onSpeechResults(e) {
this.setState({results: e.value,});
var relone = e.value;
var keyvt = relone[0];
if (Platform.OS === 'ios') {
console.log('ios: '+keyvt);
Voice.stop();
} else {
if (keyvt != '') {
this.onSend([{text:keyvt}]);
}
}
onSpeechResult iOS STT produce multiple result, so I added a Voice.stop(); which stops the result effectively and gives me the final text, then I added the final call to onSpeechEnd to submit the result.
By the way I only apply this result to iOS, I still use onSPeechResult as my final result for Android.
Let me know if this approach solves the issue for iOS.
thanks,
@eggybot Hello, Your solution looks like it will work. I would like to try it but I am not sure what the onSend() function does and I would need to know in order to give it a try. Huge thanks for posting the sample code.
@JorgeCeja the onSend() is just a function I created so it will send the final result and process the response with query result (Just replace it with your function which will process the text result)
Can someone post here his solution with the timer please?
How about this?
I created this logic just before and it is working for me (iPhone 5s).
I'm afraid if this logic works other iOS devices because I didn't test enough :)
I just share this as soon as this logic worked.
onSpeechPartialResults(e) {
console.log('[onSpeechPartialResults]', e.value);
let result = {
results: e.value,
resultlen: e.value[0].length,
};
if (Platform.OS === 'ios') {
this.silentVoiceStop(this);
}
this.setState(result);
}
...
silenceCheck(e) {
e._stopRecognizing();
}
silentVoiceStop(e) {
clearTimeout(window.silenceSetTimeout);
window.silenceSetTimeout = setTimeout(()=>{e.silenceCheck(e)}, 2000);
}
...
async _startRecognizing(e) {
try {
clearTimeout(window.silenceSetTimeout);
await Voice.start('ko-KR');
} catch (e) {
console.error(e);
}
}
@geoseong I tested the code and I saw that for the 80% of the time, the sentence is duplicated.
It seems that onSpeechPartialResults replicates the sentence got from microphone randomly.
I will investigate more.
anybody want to send this as a recipe inside docs/ folder?
Similar issue in #117.
I think this should be built into the library. What do you think?
Just for future reference, here's an example implementation of the "timer tied to OnSpeechPartialResult event" fix for this problem: https://github.com/pylon/spokestack-ios/blob/master/SpokeStack/AppleSpeechRecognizer.swift#L50
Most helpful comment
How about this?
I created this logic just before and it is working for me (iPhone 5s).
I'm afraid if this logic works other iOS devices because I didn't test enough :)
I just share this as soon as this logic worked.