iOS 10 SpeechKit:需要帮助获取部分结果中每个单词的时间戳

iOS 10 SpeechKit: Need help obtaining timestamp of each word during partial results

现在我需要语音转文本转录中每个单词的时间戳——即单词开始的时间以及持续时间。

但是,当记录每个转录的结果时,只有在转录完全完成后才会记录时间戳和持续时间。

示例代码(来自 Apple):

// Configure request so that results are returned before audio recording is finished
recognitionRequest.shouldReportPartialResults = true

// A recognition task represents a speech recognition session.
// We keep a reference to the task so that it can be cancelled.
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest) { result, error in
    var isFinal = false

    if let result = result {
        self.textView.text = result.bestTranscription.formattedString
        isFinal = result.isFinal

        for word in result.bestTranscription.segments {
            print("\(word.substring)\(word.timestamp)")
        }
    }

    if error != nil || isFinal {
        self.audioEngine.stop()
        inputNode.removeTap(onBus: 0)

        self.recognitionRequest = nil
        self.recognitionTask = nil

        self.recordButton.isEnabled = true
        self.recordButton.setTitle("Start Recording", for: [])
    }
}

有人知道如何实时获取单词的时间戳吗?他们每次基本上 return 0 直到完成。我从这里获取示例代码:

https://developer.apple.com/library/prerelease/content/samplecode/SpeakToMe/Introduction/Intro.html

时间戳的计算是一项计算量大的操作,它通常不在解码期间实现,仅作为结果的post-processing。所以在许多引擎中,不可能获得部分时间戳。

如果您仍然需要时间戳,则需要考虑使用不同的库,可能还需要考虑不同的算法。