【问题标题】:Stop speech recognition when user is finished speaking用户说完后停止语音识别
【发布时间】:2017-05-16 05:25:19
【问题描述】:

Siri 如何确定我何时说完。我想知道的原因是我想在我的应用程序中使用 Apple 的语音识别 API 实现类似的功能。这是可行的,还是通过用户输入知道用户何时停止说话的唯一方法?

【问题讨论】:

  • 我的理解是你不需要处理“当用户说完”。您应该在此处阅读 SiriKit 指南:developer.apple.com/library/content/documentation/Intents/…。基本上,SiriKit 通过从用户语音中收集的数据为您提供“意图”,您只需要处理意图并执行自己的操作。
  • 问题是关于语音识别 API,而不是 SiriKit。
  • 运气好吗?我自己也在为此苦苦挣扎
  • 这方面有什么更新吗?

标签: ios swift speech-recognition


【解决方案1】:

你可以使用计时器,我也遇到了同样的问题,但我无法用优雅的方法解决它。

fileprivate var timer:Timer?
func startRecordingTimer() {
    lastString = ""
    createTimerTimer(4)
}
func stopRecordingTimer() {
    timer?.invalidate()
    timer = nil
}
fileprivate func whileRecordingTimer() {
    createTimerTimer(2)
}
fileprivate var lastString = ""
func createTimerTimer(_ interval:Double) {
    OperationQueue.main.addOperation({[unowned self] in
        self.timer?.invalidate()
        self.timer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { (_) in
            self.timer?.invalidate()
            if(self.lastString.characters.count > 0){
                //DO SOMETHING
            }else{
                self.whileRecordingTimer()
            }
        }
    })
}

在SFSpeechRecognitionTaskDelegate

public func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didHypothesizeTranscription transcription: SFTranscription) {
    let result = transcription.formattedString
    lastString = result
}

【讨论】:

    猜你喜欢
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 2020-10-03
    相关资源
    最近更新 更多