2

I'm coding an app to read random study questions to students.

The basic flow is:

  • Generate random question
  • Assign the text to a SpeechUtterrance
  • Play the SpeechUtterance with the SpeechSynthesizer
  • Get the student's answer
  • Check it
  • Generate a new random question
  • Repeat

Everything works except I can't get it to read more than one question. It'll speak the first one, accept an answer, but I can't get it to read subsequent utterances.

Is there a method I can call to reset the SpeechSynthesizer/SpeechUtterance after the didFinish is run?

Gene Z. Ragan
  • 2,643
  • 2
  • 31
  • 41
  • So I mentioned that I was grabbing the student's answer. I'm using SFSpeechRecognizer to do this. After some testing, if I don't use the speech recognizer the subsequent utterances are read, no problem. My guess is that there's some interaction between AVSpeechSynthesizer and SFSpeechRecognizer that I'm missing, if this helps anyone narrow it down? – Nathaniel Hatfield Jul 18 '17 at 23:31

1 Answers1

1

So I was using SFSpeechRecognizer and AVSpeechSynthesizer and starting the audio recorder cut off the audio channel to play audio.

I had to change

try audioSession.setCategory(AVAudioSessionCategoryRecord)

to

try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)

and that resolved my issue.