ios - Swift: iPhone's volume is low when trying to change speech to iPhone's voice in swift -
i trying speech recognition sample. if started recognise speech via microphone, tried iphone's voice of recognised text. working. but, voice low. can u guide me on this?
rather than, if trying in simple button action, avspeechutterance
code, volume normal.
after that, if go startrecognise()
method, volume low.
my code
func startrecognise() { let audiosession = avaudiosession.sharedinstance() //2 { try audiosession.setcategory(avaudiosessioncategoryplayandrecord) try audiosession.setmode(avaudiosessionmodedefault) try audiosession.setmode(avaudiosessionmodemeasurement) try audiosession.setactive(true, with: .notifyothersondeactivation) try avaudiosession.sharedinstance().overrideoutputaudioport(avaudiosessionportoverride.speaker) } catch { print("audiosession properties weren't set because of error.") } recognitionrequest = sfspeechaudiobufferrecognitionrequest() guard let inputnode = audioengine.inputnode else { fatalerror("audio engine has no input node") } guard let recognitionrequest = recognitionrequest else { fatalerror("unable create sfspeechaudiobufferrecognitionrequest object") } recognitionrequest.shouldreportpartialresults = true recognitiontask = speechrecognizer.recognitiontask(with: recognitionrequest, resulthandler: { (result, error) in if result != nil { let lastword = result?.besttranscription.formattedstring.components(separatedby: " ").last if lastword == "repeat" || lastword == "repeat"{ self.myutterance2 = avspeechutterance(string: "you have spoken repeat") self.myutterance2.rate = 0.4 self.myutterance2.volume = 1.0 self.myutterance2.pitchmultiplier = 1.0 self.synth1.speak(self.myutterance2) // here voice low. } } }) let recordingformat = inputnode.outputformat(forbus: 0) //11 inputnode.installtap(onbus: 0, buffersize: 1024, format: recordingformat) { (buffer, when) in self.recognitionrequest?.append(buffer) } audioengine.prepare() { try audioengine.start() } catch { print("audioengine couldn't start because of error.") } }
my button action
func buttonaction() { self.myutterance2 = avspeechutterance(string: "you in button action") self.myutterance2.rate = 0.4 self.myutterance2.volume = 1.0 self.myutterance2.pitchmultiplier = 1.0 self.synth1.speak(self.myutterance2) // before going startrecognise() method, //i tried buttonaction(), //this time volume normal. //after startrecognise() method call, volume low in both methods. }
finally, got solution.
func startrecognise() { let audiosession = avaudiosession.sharedinstance() //2 { try audiosession.setcategory(avaudiosessioncategoryplayandrecord) try audiosession.setmode(avaudiosessionmodedefault) //try audiosession.setmode(avaudiosessionmodemeasurement) try audiosession.setactive(true, with: .notifyothersondeactivation) try avaudiosession.sharedinstance().overrideoutputaudioport(avaudiosessionportoverride.speaker) } catch { print("audiosession properties weren't set because of error.") } ... }
once comment line, try audiosession.setmode(avaudiosessionmodemeasurement)
, volume working normal.
Comments
Post a Comment