voice icon indicating copy to clipboard operation
voice copied to clipboard

fix iOS 18 bug where onSpeechEnd is never called

Open AndersonVanzo opened this issue 1 year ago • 3 comments

Refers to #517

AndersonVanzo avatar Oct 16 '24 19:10 AndersonVanzo

Just a few notes on this PR (as I work on a similar library):

  • There's a bit of functionality change here to how would previously have worked on iOS. I'm pretty sure on the current version of react-native-voice for iOS, speech recognition runs continuously. On Android it stops once you've paused for a second or two and processes a final result. This PR brings the functionality similar to Android.
  • So the part where you have transcript = [@" " stringByAppendingString:transcription.formattedString]; is unnecessary as this is actually meant for continuous speech transcription where multiple final segments occur in a speech recognition task.
  • If this library does implement continous recognition, you'll also need to reset the _hasSeenFinalResult variable back to it's initial state once starting speech recognition, otherwise you'll see an extra prepended space on your second and subsequent speech recognition attempts, such as the following:
onSpeechPartialResults "this"
onSpeechPartialResults "this is"
onSpeechPartialResults "this is a"
onSpeechPartialResults "this is a demo"
onSpeechPartialResults "this is a demo"
onSpeechResults        " this is a demo"

jamsch avatar Oct 17 '24 21:10 jamsch

i copied same lines , it does not work for me

Shaka912 avatar Dec 13 '24 16:12 Shaka912

opening this up for collab

i dug into the Voice.m file

NSLog(@"%@",result); shows the following:

<SFSpeechRecognitionResult: 0x3027a9980> final=0, bestTranscription=<SFTranscription: 0x3032c8f60>, formattedString=Hello there, segments=(
    "<SFTranscriptionSegment: 0x3019585a0>, substringRange={0, 5}, timestamp=0, duration=0.011, confidence=0, substring=Hello, alternativeSubstrings=(\n), phoneSequence=, ipaPhoneSequence=, voiceAnalytics=(null)",
    "<SFTranscriptionSegment: 0x301958c00>, substringRange={6, 5}, timestamp=0.011, duration=0.011, confidence=0, substring=there, alternativeSubstrings=(\n), phoneSequence=, ipaPhoneSequence=, voiceAnalytics=(null)"
), speakingRate=0.000000, averagePauseDuration=0.000000, speechRecognitionMetadata=(null)

result.speechRecognitionMetadata always returns null and result.final always returns 0

is there a way to dig further into the root cause for why these values do not change?

RN: 0.76.5 ios: 18.2

richkuo avatar Jan 03 '25 07:01 richkuo