This is a question in Swift 4.2.
When using SFSpeakRecognizer and AVSpeechSynthesizer in one app,
For example, I tried to perform voice recognition with the RecognizeViewController and read aloud with SpeechButton of the SpeechViewController, but I have a problem with the error Thread1:signal SIGABRT, so I have a question.https://qiita.com/croquette0212/items/bf0e41ca1b65c6d320b4
After reading this article, I thought it would be good to use the AVSession setCategory differently.
Voice recognition processing uses the recording processing method
private func startRecording()throws{
// Describe the action to record here
iflet recognitionTask = recognitionTask {
// reset processing
recognitionTask.cancel()
self.recognitionTask=nil
let audioSession=AVAudioSession.sharedInstance()
try audioSession.setCategory (AVAudioSession.Category.record, mode:.default)
try audioSession.setMode (AVAudioSession.Mode.measurement)
tryaudioSession.setActive(true, options: .notifyOthersOnDeactivation)
}
}
and for SpeechViewController,
vartalker=AVSpeechSynthsizer()
override func viewDidLoad(){
// speechButton generation process
speechButton.addTarget(resultCardView, action:#selector(speachButtonTapped(sender:))), for: .touchUpInside
}
@objc func speachButtonTapped(sender:Any){
let avSession=AVAudioSession.sharedInstance()
try?avSession.setCategory(AVAudioSession.Category.ambient, mode: .default, options: .mixWithOthers)
letutterance=AVSpeechUtterance(string:self.Jplabel.text!)
utterance.voice = AVSpeechSynthesisVoice (language: "en-En")
utility.volume=1.2
// execution
self.talker.speak (utterance)
}
I wrote it like this, but it turned out to be Thread1:signal SIGABRT.
If anyone understands, please let me know.
Since there is no If you add One more thing, The Also, regarding Isn't that right?
var speechButton:UIButton!
(!
or ?
) between the class
and func
declarations, does the instance stored in speechButton
fall out of viewDidLoad(/code>)?
vartalker=AVSpeechSynthsizer()
var speechButton:UIButton!
speechButton
as a member variable of the class and delete the declaration part of speechButton
in viewDidLoad()
(let
in letspeechButton
), it will also move to the utterance.voice=AVSpeechSynthesisVoice (language: "en-En")
language
does not have the code en-EN
and
en-US
(USA), en-GB
(UK), en-AU
(Australia), en-IE
(Ireland), or en-ZA
(South Africa).setCategory
, the argument for option:
is []
, sotry?avSession.setCategory (AVAudioSession.Category.ambient, mode:.default, options: [.mixWithOthers])
616 Uncaught (inpromise) Error on Electron: An object could not be cloned
571 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
581 PHP ssh2_scp_send fails to send files as intended
572 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.