1

Hello i am creating Call Recording App and i am playing recording through app using AVAduioPlayer and also transcribe audio to text Using SFSpeechRecognizer below is my code for playing audio and transcribe using below code

func requestSpeectAuth(){
        SFSpeechRecognizer.requestAuthorization { authStatus in
            if authStatus == SFSpeechRecognizerAuthorizationStatus.authorized{
                if let path = Bundle.main.url(forResource: "audio", withExtension: "m4a"){
                    print(path)
                    do {
                        let sound = try AVAudioPlayer(contentsOf: path)
                        self.audiPlayer = sound
                        sound.play()
                    } catch {
                        print("Error")
                    }
                    let reconizer = SFSpeechRecognizer()
                    let request = SFSpeechURLRecognitionRequest(url: path)
                    self.recpnizer?.recognitionTask(with: request){ (result,error) in
                        if let error = error{
                            print(error.localizedDescription)
                        }else{
                            print(result?.bestTranscription.formattedString)
                            self.txtView.text = result?.bestTranscription.formattedString
                        }
                    }
                }
            }
        }
    }

and i successfully done this but now when i pause audio at that time i need to stop Transcription is there any way to to stop SFSpeechRecognizer on button click then please help me

gipeje
  • 61
  • 7

1 Answers1

0

When you calling installTap, there will be one block which let you append audio buffer to the recognitionRequest, just don't append the audio to buffer when you want to pause.

Steven
  • 468
  • 4
  • 14