0

I hope someone can help as I have worked on this problem for hours. I have an array of phrases. I want to get the app to speak 7 of the phrases starting at the point the user chooses. This works for one phrase but will not work when I change the position in the array to a variable varied by a For loop.

import UIKit
import AVFoundation

class view_ViewController: UIViewController {
    var numSubject = 0
    var noteArray = writeString.components(separatedBy: “#”)
    var speakIt = AVSpeechUtterance(string: "Fred")
    IBAction func subButtonOne(_ sender: Any) {
        speakIt = AVSpeechUtterance(string: noteArray[numSubject + 1])
        speakIt.rate = 0.5
        synth.speak(speakIt)    }

any thoughts?

John
  • 11
  • 1
  • 5
  • Please have a look there https://stackoverflow.com/questions/37287261/swift-ios-text-to-speech-not-working-with-delay-in-loop – aBilal17 Mar 02 '18 at 11:45

1 Answers1

0
var results = ["1", "2", '3', '4', '5', '6', '7', '8', '9', '10']
// replace values in results with your phrases
for var i in (0..<results.count)
{
    if (results[i + numSubject] < results.count)
    {
        print (results[i + numsubject] // call speakIt with this result
        i += 1
    }
}

Modified from This Answer

Jake
  • 2,126
  • 1
  • 10
  • 23