Tôi đang triển khai Nhận dạng giọng nói trong ứng dụng của mình. Khi tôi lần đầu tiên trình bày bộ điều khiển xem với logic nhận dạng giọng nói, mọi thứ hoạt động tốt. Tuy nhiên, khi tôi cố gắng trình bày các điều khiển xem lại, tôi nhận được lỗi sau:Đầu vào AVAudioEngineNút cài đặtTạm dừng khi khởi động lại bản ghi
ERROR: [0x190bf000] >avae> AVAudioNode.mm:568: CreateRecordingTap: required condition is false: IsFormatSampleRateAndChannelCountValid(format)
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
Dưới đây là mã được sử dụng để khởi động và dừng ghi:
@available(iOS 10.0, *)
extension DictationViewController {
fileprivate func startRecording() throws {
guard let recognizer = speechRecognizer else {
debugLog(className, message: "Not supported for the device's locale")
return
}
guard recognizer.isAvailable else {
debugLog(className, message: "Recognizer is not available right now")
return
}
mostRecentlyProcessedSegmentDuration = 0
guard let node = audioEngine.inputNode else {
debugLog(className, message: "Could not get an input node")
return
}
let recordingFormat = node.outputFormat(forBus: 0)
node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { [weak self] (buffer, _) in
self?.request.append(buffer)
}
audioEngine.prepare()
try audioEngine.start()
recognitionTask = recognizer.recognitionTask(with: request, resultHandler: {/***/})
}
fileprivate func stopRecording() {
audioEngine.stop()
audioEngine.inputNode?.removeTap(onBus: 0)
request.endAudio()
recognitionTask?.cancel()
}
}
startRecording()
được gọi trong viewDidLoad khi chúng tôi có yêu cầu ủy quyền. stopRecording()
được gọi khi bộ điều khiển xem bị loại bỏ.
Vui lòng hỗ trợ. Tôi đang phải vật lộn để tìm một giải pháp cho vụ tai nạn
Bạn có tìm giải pháp này không? Tôi đang gặp sự cố tương tự, nhưng chỉ khi chạy trên iOS 8.1 ?? –