JanSmutný
JanSmutný

Reputation: 157

React-native Expo SpeechOptions

I would like to use these expo react native events (onPause, onResume, onDone,...) which can be found here: https://docs.expo.dev/versions/v44.0.0/sdk/speech/#speecheventcallback but I cannot find any correct way to use it. Can anyone please help me with syntax? I haven't found any examples at all. Thank you Jan

Upvotes: 2

Views: 837

Answers (1)

BIDESH BANERJEE
BIDESH BANERJEE

Reputation: 46

const [Playing,setPlaying] = useState(false);
const Text = 'Mom I missed you';
const play = () => {

  Speech.speak(Text,{
      rate:1,
      onStart:() => setPlaying(true), 
      onPause:() => setPlaying(false), 
      onResume:() => setPlaying(true)  
  })

}

return (
  <Button title = 'play' onPress = {play}/>
)

Basically on each events(start, resume, pause) respective callback functions will be called.. don't know about onBoundary and onMark. basically there is a boundary event for SpeechSysthesisUtterance(an api for text to speech for web browsers) maybe onBoundary is related to that.

//This is only for Web-Apps
  let utt = new SpeechSynthesisUtterance('Hello everyone');
  
   utt.addEventListener('boundary' ,(e) => {
          console.log(e.charIndex)
      });

speechSynthesis.speak(utt);
   

e.charIndex is index of Text. https://www.youtube.com/watch?v=nx_k1XCaWWs check at 13:30 min

Upvotes: 3

Related Questions