【问题标题】:How do I configure an ORKOrderedTask with multiple ORKAudioSteps in ResearchKit?如何在 ResearchKit 中配置具有多个 ORKAudioSteps 的 ORKOrderedTask?
【发布时间】:2017-03-13 22:57:33
【问题描述】:

在过去的几天里,我一直在抨击一个问题。这是我要完成的任务:

我想展示一个由多个 AudioSteps 组成的 ORKOrderedTask,每个步骤都显示一个用户将背诵的句子。当然,ORKOrderedTask.audioTask 很棒,但是这个预配置的任务只给出一个音频提示。我希望用户能够记录一个句子,点击下一个,记录下一个,点击下一个,等等。

我遇到的问题: 当我尝试使用多个 ORKAudioStep 实现自己的 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 的参考,但显然我正在做一些让录音机不开心的事情。

感谢您的宝贵时间。

【问题讨论】:

    标签: ios swift researchkit


    【解决方案1】:

    我使用下面的代码解决了这个问题。注意 AVFormatIDKey 和 recorderConfigurations 分配的 UInt 转换。

    let recordingSettings = [
        AVFormatIDKey : UInt(kAudioFormatAppleLossless),
        AVNumberOfChannelsKey : 2,
        AVSampleRateKey: 44100.0
    ] as [String : Any]
    
    
    for (index, sentence) in sentences.enumerated() {
        let countdownStep = ORKCountdownStep(identifier: "CountdownStep\(index)")
        countdownStep.stepDuration = 5
        steps += [countdownStep]
    
        let audioStep = ORKAudioStep(identifier: "AudioStep\(index)")
        audioStep.title = sentence
        audioStep.stepDuration = 5
        audioStep.shouldContinueOnFinish = false;
        let config = ORKAudioRecorderConfiguration(identifier: "audio\(index)", recorderSettings: recordingSettings)
        audioStep.recorderConfigurations = [config]
    
        steps += [audioStep]
    }
    

    【讨论】:

      猜你喜欢
      • 2015-09-18
      • 2020-06-01
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      相关资源
      最近更新 更多