问题是如何按下录制按钮到语音,当我按住该按钮时,它将不断转换“从语音到文本” 直到我释放按钮
我可以迅速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)
}