Приложение IOS аварийно завершает работу с сообщением «необходимое условие неверно: IsFormatSampleRateAndChannelCountValIOS

Программируем под IOS
Ответить
Anonymous
 Приложение IOS аварийно завершает работу с сообщением «необходимое условие неверно: IsFormatSampleRateAndChannelCountVal

Сообщение Anonymous »

У меня происходит сбой приложения, когда я использую микрофон (в моем случае Microsoft Teams) в фоновом режиме и пытаюсь записать звук внутри моего приложения.

Закрытие приложения из-за неперехваченного исключения «com.apple.coreaudio.avfaudio», причина: «необходимое условие неверно: IsFormatSampleRateAndChannelCountValid(format)»

Пожалуйста, обратитесь к коду ниже:
func startRecording() {

// Clear all previous session data and cancel task
if recognitionTask != nil {
recognitionTask?.cancel()
recognitionTask = nil
}

// Create instance of audio session to record voice
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSession.Category.record, mode: AVAudioSession.Mode.measurement, options: AVAudioSession.CategoryOptions.defaultToSpeaker)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
} catch {
print("audioSession properties weren't set because of an error.")
}

self.recognitionRequest = SFSpeechAudioBufferRecognitionRequest()

let inputNode = audioEngine.inputNode

guard let recognitionRequest = recognitionRequest else {
fatalError("Unable to create an SFSpeechAudioBufferRecognitionRequest object")
}

recognitionRequest.shouldReportPartialResults = true

self.recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in

var isFinal = false

if result != nil {

self.textField.text = result?.bestTranscription.formattedString
isFinal = (result?.isFinal)!
}

if error != nil || isFinal {

self.audioEngine.stop()
inputNode.removeTap(onBus: 0)

self.recognitionRequest = nil
self.recognitionTask = nil

self.micButton.isEnabled = true
}
})

let recordingFormat = inputNode.outputFormat(forBus: 0)

inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in
self.recognitionRequest?.append(buffer)
}

self.audioEngine.prepare()

do {
try self.audioEngine.start()
} catch {
print("audioEngine couldn't start because of an error.")
}

self.textField.text = ""
}

Я почти уверен, что проблема где-то здесь, но не знаю, как ее исправить.
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in
self.recognitionRequest?.append(buffer)
}


Подробнее здесь: https://stackoverflow.com/questions/745 ... ndchannelc
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»