在过去的几天里,我一直在抨击一个问题。这是我要完成的工作:
我想展示一个由多个 AudioSteps 组成的 ORKOrderedTask,每个步骤都显示一个用户将背诵的句子。当然,ORKOrderedTask.audioTask 很棒,但是这个预配置的任务只给出一个音频提示。我希望用户能够记录一个句子,点击下一个,记录下一个,点击下一个等。
我遇到的问题:当我尝试使用多个 ORKAudioSteps 实现我自己的 OrderedTask 时,无论我做什么,该步骤总是报告“太大声”,波形显示全红条。
相关代码:
var steps = [ORKStep]()
let instructionStep = ORKInstructionStep(identifier: "IntroStep")
instructionStep.title = "Speech Task"
instructionStep.text = "Placeholder"
steps += [instructionStep]
let countdownStep = ORKCountdownStep(identifier: "CountdownStep")
countdownStep.stepDuration = 5
steps += [countdownStep]
let recordingSettings = [
AVFormatIDKey : kAudioFormatAppleLossless,
AVNumberOfChannelsKey : 2,
AVSampleRateKey: 44100.0
] as [String : Any]
for (index, sentence) in sentences.enumerated() {
let audioStep = ORKAudioStep(identifier: "AudioStep\(index)")
audioStep.title = sentence
audioStep.stepDuration = 5
audioStep.shouldContinueOnFinish = true;
let config = ORKAudioRecorderConfiguration(identifier: "Recorder\(index)", recorderSettings: recordingSettings)
audioStep.recorderConfigurations?.append(config)
steps += [audioStep]
}
return ORKOrderedTask(identifier: "SpeechTask", steps: steps)
// And the viewController creation function elsewhere in the application
func presentTask(task: ORKOrderedTask) {
let taskViewController = ORKTaskViewController(task: task, taskRun: nil)
taskViewController.outputDirectory = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] )
taskViewController.delegate = self
self.present(taskViewController, animated: true, completion: nil)
}
(Sentences 只是一个句子提示字符串的数组)
我的想法:我怀疑这个错误与我处理记录配置或输出目录的方式有关。输出目录被分配在这个 OrderedTask 被赋予的 ViewController 中。我在 ORKOrderedTask.m 中使用了 ORKOrderedTask.audioTask 作为构建 ORKAudioStep 的参考,但显然我正在做一些让 Recorder 不开心的事情。
谢谢你的时间。