按住按钮即可讲话

时间:2019-03-08 16:30:30

标签: swift firebase-realtime-database

问题是如何按下录制按钮到语音,当我按住该按钮时,它将不断转换“从语音到文本” 直到我释放按钮

我可以迅速4做到吗?

这是可见负载:

  {
    super.viewDidLoad()



    Voiec.isEnabled = false  //2
    speechRecognizer?.delegate = self as? SFSpeechRecognizerDelegate  
    speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: lang))
    SFSpeechRecognizer.requestAuthorization { (authStatus) in  //4


        var isButtonEnabled = false

        switch authStatus {  //5
        case .authorized:
            isButtonEnabled = true

        case .denied:
            isButtonEnabled = false
            print("User denied access to speech recognition")

        case .restricted:
            isButtonEnabled = false
            print("Speech recognition restricted on this device")

        case .notDetermined:
            isButtonEnabled = false
            print("Speech recognition not yet authorized")
        }

        OperationQueue.main.addOperation() {
            self.Voiec.isEnabled = isButtonEnabled
        }
    }
    speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: lang))


        }

这是btn

 @IBAction func startstopbtn(_ sender: Any) {

    speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: lang))

    if audioEngine.isRunning {
        audioEngine.stop()
        recognitionRequest?.endAudio()
        Voiec.isEnabled = false
        Voiec.setTitle("*", for: .normal)
        }
     else {
        startRecording()
        Voiec.setTitle("..", for: .normal)

    }

0 个答案:

没有答案