Я хочу включить распознавание речи в свое приложение, для этого я использовал Speech Framework от Apple в сочетании с App Intents Framework. Намерение приложения «Слушать» запускает распознавание речи. Теперь у меня проблема: я постоянно получаю следующее сообщение об ошибке:
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of type NSException
в следующей строке:
self.audioEngine.inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in
self.recognitionRequest?.append(buffer)
}
Эта проблема не возникает, когда я выполняю тот же код простым нажатием кнопки, но ONYL с намерением приложения «Слушать». Мне известно, что существует проблема с микрофоном, который Siri использует при прослушивании намерений приложения. Но как я могу решить эту проблему? Я провел много исследований, а также попробовал использовать асинхронные функции, но это не помогло
Мой код:
import Speech
import UIKit
class TestVoice: UIControl, SFSpeechRecognizerDelegate {
let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
var recognitionRequest : SFSpeechAudioBufferRecognitionRequest?
var recognitionTask : SFSpeechRecognitionTask?
let audioEngine = AVAudioEngine()
func stopRecording() {
self.audioEngine.stop()
self.recognitionRequest?.endAudio()
}
func setupSpeech() {
self.speechRecognizer?.delegate = self
SFSpeechRecognizer.requestAuthorization { (authStatus) in
switch authStatus {
case .authorized:
print("yes")
case .denied:
print("died")
case .restricted:
print("died")
case .notDetermined:
print("none")
}
OperationQueue.main.addOperation() {
}
}
}
func startRecording() -> Bool {
setupSpeech()
clearSessionData()
createAudioSession()
recognitionRequest = bufferRecRequest()
recognitionRequest?.shouldReportPartialResults = true
self.recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest!, resultHandler: { (result, error) in
var finished = false
if let result = result {
//do something
finished = result.isFinal
}
if error != nil || finished {
self.audioEngine.stop()
self.audioEngine.inputNode.removeTap(onBus: 0)
self.recognitionRequest = nil
self.recognitionTask = nil
}
})
let recordingFormat = self.audioEngine.inputNode.outputFormat(forBus: 0)
self.audioEngine.inputNode.installTap(onBus: 0, bufferSize: 2048, 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.")
delegate?.showFeedbackError(title: "Sorry", message: "Your microphone is used somewhere else")
return false
}
return true
}
func clearSessionData(){
if recognitionTask != nil {
recognitionTask?.cancel()
recognitionTask = nil
}
}
func bufferRecRequest()->SFSpeechAudioBufferRecognitionRequest{
self.recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
guard let recognitionRequest = recognitionRequest else {
fatalError("Unable to create an SFSpeechAudioBufferRecognitionRequest object")
}
return recognitionRequest
}
func createAudioSession()-> Bool{
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: .mixWithOthers)
} catch {
print("audioSession properties weren't set because of an error.")
delegate?.showFeedbackError(title: "Sorry", message: "Mic is busy")
return false
}
return true
}
}
Цель приложения
import AppIntents
import UIKit
struct ListenIntent: AppIntent {
static var openAppWhenRun: Bool = true
@available(iOS 16, *)
static let title: LocalizedStringResource = "Listen"
static var description =
IntentDescription("Listens to the User")
let speechRecognizer = TestVoice()
func perform() throws -> some IntentResult & ProvidesDialog {
speechRecognizer.startRecording()
return .result(dialog: "Done")
}}
Подробнее здесь: https://stackoverflow.com/questions/746 ... matsampler
Запустите микрофон с помощью App Intents: «Необходимое условие неверно: IsFormatSampleRateAndChannelCountValid(format)» ⇐ IOS
Программируем под IOS
1716234156
Anonymous
Я хочу включить распознавание речи в свое приложение, для этого я использовал Speech Framework от Apple в сочетании с App Intents Framework. Намерение приложения «Слушать» запускает распознавание речи. Теперь у меня проблема: я постоянно получаю следующее сообщение об ошибке:
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of type NSException
в следующей строке:
self.audioEngine.inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in
self.recognitionRequest?.append(buffer)
}
Эта проблема не возникает, когда я выполняю тот же код простым нажатием кнопки, но ONYL с намерением приложения «Слушать». Мне известно, что существует проблема с микрофоном, который Siri использует при прослушивании намерений приложения. Но как я могу решить эту проблему? Я провел много исследований, а также попробовал использовать асинхронные функции, но это не помогло
Мой код:
import Speech
import UIKit
class TestVoice: UIControl, SFSpeechRecognizerDelegate {
let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
var recognitionRequest : SFSpeechAudioBufferRecognitionRequest?
var recognitionTask : SFSpeechRecognitionTask?
let audioEngine = AVAudioEngine()
func stopRecording() {
self.audioEngine.stop()
self.recognitionRequest?.endAudio()
}
func setupSpeech() {
self.speechRecognizer?.delegate = self
SFSpeechRecognizer.requestAuthorization { (authStatus) in
switch authStatus {
case .authorized:
print("yes")
case .denied:
print("died")
case .restricted:
print("died")
case .notDetermined:
print("none")
}
OperationQueue.main.addOperation() {
}
}
}
func startRecording() -> Bool {
setupSpeech()
clearSessionData()
createAudioSession()
recognitionRequest = bufferRecRequest()
recognitionRequest?.shouldReportPartialResults = true
self.recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest!, resultHandler: { (result, error) in
var finished = false
if let result = result {
//do something
finished = result.isFinal
}
if error != nil || finished {
self.audioEngine.stop()
self.audioEngine.inputNode.removeTap(onBus: 0)
self.recognitionRequest = nil
self.recognitionTask = nil
}
})
let recordingFormat = self.audioEngine.inputNode.outputFormat(forBus: 0)
self.audioEngine.inputNode.installTap(onBus: 0, bufferSize: 2048, 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.")
delegate?.showFeedbackError(title: "Sorry", message: "Your microphone is used somewhere else")
return false
}
return true
}
func clearSessionData(){
if recognitionTask != nil {
recognitionTask?.cancel()
recognitionTask = nil
}
}
func bufferRecRequest()->SFSpeechAudioBufferRecognitionRequest{
self.recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
guard let recognitionRequest = recognitionRequest else {
fatalError("Unable to create an SFSpeechAudioBufferRecognitionRequest object")
}
return recognitionRequest
}
func createAudioSession()-> Bool{
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: .mixWithOthers)
} catch {
print("audioSession properties weren't set because of an error.")
delegate?.showFeedbackError(title: "Sorry", message: "Mic is busy")
return false
}
return true
}
}
Цель приложения
import AppIntents
import UIKit
struct ListenIntent: AppIntent {
static var openAppWhenRun: Bool = true
@available(iOS 16, *)
static let title: LocalizedStringResource = "Listen"
static var description =
IntentDescription("Listens to the User")
let speechRecognizer = TestVoice()
func perform() throws -> some IntentResult & ProvidesDialog {
speechRecognizer.startRecording()
return .result(dialog: "Done")
}}
Подробнее здесь: [url]https://stackoverflow.com/questions/74669763/start-microphone-using-app-intents-required-condition-is-false-isformatsampler[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия