首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >必需条件为IsFormatSampleRateAndChannelCountValid(format):SpeechKit必需条件为假

必需条件为IsFormatSampleRateAndChannelCountValid(format):SpeechKit必需条件为假
EN

Stack Overflow用户
提问于 2019-02-08 11:15:59
回答 1查看 483关注 0票数 0

我们已经实现了SpeechKit的听写。它可以正常工作,但有时会受到一些用户的攻击。当用户单击开始录制音频引擎。

代码:

代码语言:javascript
复制
    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
    })

错误:

致命异常: IsFormatSampleRateAndChannelCountValid(format):com.apple.coreaudio.avfaudio必需条件为false

EN

回答 1

Stack Overflow用户

发布于 2020-01-20 09:58:30

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54591255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档