【问题标题】:SpeechKit required condition is false: IsFormatSampleRateAndChannelCountValid(format)SpeechKit 所需条件为假:IsFormatSampleRateAndChannelCountValid(format)
【发布时间】:2019-07-02 15:03:28
【问题描述】:

我们已经为听写实现了 SpeechKit。它工作正常,但有时会从一些用户那里崩溃。当用户点击开始录制音频引擎时。

代码:

    if recognitionTask != nil {
        recognitionTask?.cancel()
        recognitionTask = nil
    }

    let node = audioEngine.inputNode
    let recordingFormat = node.outputFormat(forBus: 0)
    node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { buffer, _ in
        self.request.append(buffer)
    }
    audioEngine.prepare()
    do {
        try audioEngine.start()
    } catch {
        self.sendAlert(message: "There has been an audio engine error.")
        return print(error)
    }

    guard let myRecognizer = SFSpeechRecognizer() else {
        self.sendAlert(message: "Speech recognition is not supported for your current locale.")
        return
    }

    if !myRecognizer.isAvailable {
        self.sendAlert(message: "Speech recognition is not currently available. Check back at a later time.")
        // Recognizer is not available right now
        return
    }

    recognitionTask = speechRecognizer?.recognitionTask(with: request, resultHandler: { result, error in
    //Code here
    })

错误:

致命异常:com.apple.coreaudio.avfaudio 所需条件为 false: IsFormatSampleRateAndChannelCountValid(格式)

【问题讨论】:

    标签: ios swift speech-recognition speech-to-text


    【解决方案1】:

    这个问题是因为您可能在虚拟机或任何未连接任何麦克风的设备上运行您的项目。如果您在连接麦克风的真实 Mac 设备上运行项目或在真实 iOS 设备上运行项目,则不会遇到此问题

    【讨论】:

    • 运行类似的代码,但对我来说不是这样!在sim上工作,但不在设备上。仍在调查崩溃:(
    猜你喜欢
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    相关资源
    最近更新 更多