swift - 如何让 Xcode 9 循环说出短语

标签 swift xcode

我希望有人可以提供帮助,因为我已经解决这个问题几个小时了。我有一系列短语。我想让应用程序从用户选择的点开始说出 7 个短语。这适用于一个短语,但当我将数组中的位置更改为由 For 循环变化的变量时,这将不起作用。

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)    }

有什么想法吗?

最佳答案

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

关于swift - 如何让 Xcode 9 循环说出短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49068407/

相关文章:

ios - Xcode 不打开我的项目

swift - 用于字数计算的 Swift String 中的字数

ios - 如何使用 Swift 为 JSON 数据创建 JSON Codable 和 Decodable?

swift - 快速使用数组从 FMDB 中删除数据

ios - Lib 工具无法创建存档

ios - 在发布配置中运行时,应用程序无法导入桥接 header 并找到 Google/Analytics.h

ios - Swift:将 UIDatePicker 日期保存到 CoreData 中

swift - 将 float 保存到 NSUSERDEFAULT

ios - SpriteKit : create centred sprites in grid

regex - 我可以通过哪些方式改进这个正则表达式?