0

I have this code that uses recognitionTask(with:resultHandler:) that repeats the words recognized.


func transcribeFile(url: URL) {
    print("#", #function)
    
    // 1
    guard let recognizer = SFSpeechRecognizer() else {
        print("Speech recognition not available for specified locale")
        return
    }
    
    if !recognizer.isAvailable {
        print("Speech recognition not currently available")
        return
    }
    
    recognizer.defaultTaskHint = .unspecified
    
    // 2
    let request = SFSpeechURLRecognitionRequest(url: url)
    
    // MARK: mine...
    request.shouldReportPartialResults = true
    request.requiresOnDeviceRecognition = true
    
    // 3
    recognizer.recognitionTask(with: request) {
        (result, error) in
        guard let result = result else {
            print("There was an error transcribing that file")
            return
        }
        
        print("\(String(describing: result.bestTranscription.segments.last!.substring))")
        
        // 4
        if result.isFinal {
            print("Done.")
        }
    }
    
}

Here is part of the debug window:

bed
bed
I
I
daniel
  • 1,446
  • 3
  • 29
  • 65

0 Answers0