2

Is there any way to know how long it takes Swift to download speech models?

Michael Jajou
  • 312
  • 2
  • 13

1 Answers1

1

Try using OSSSpeechKit. It works without a model. Here's the link: https://cocoapods.org/pods/OSSSpeechKit#speech-to-text.

Example Code:

import UIKit
import OSSSpeechKit

class ViewController: UIViewController, OSSSpeechDelegate {
    
    let speechKit = OSSSpeech.shared
    
    func didCompleteTranslation(withText text: String) {
        textView.text = text
        
    }
    
    func didFailToProcessRequest(withError error: Error?) {
        let alert = UIAlertController(title: "Error Processing Request", message: "We couldn't process your request.", preferredStyle: .alert)
        let action = UIAlertAction(title: "OK", style: .default)
        alert.addAction(action)
        present(alert, animated: true) {
            self.speechKit.endVoiceRecording()
            self.endButton.isHidden = true
            self.startButton.isHidden = false
        }
        
    }
    
    
    func didFinishListening(withText text: String) {
        textView.text = text
        
    }
    
    func authorizationToMicrophone(withAuthentication type: OSSSpeechKitAuthorizationStatus) {
        
    }
    
    func didFailToCommenceSpeechRecording() {
        let alert = UIAlertController(title: "Error Accessing the Microphone", message: "Make sure to check that you have given the app access to your microphone.", preferredStyle: .alert)
        let action = UIAlertAction(title: "OK", style: .default)
        alert.addAction(action)
        present(alert, animated: true) {
            self.speechKit.endVoiceRecording()
            self.endButton.isHidden = true
            self.startButton.isHidden = false
        }
        
    }
    
    @IBOutlet weak var textView: UITextView!
    
    @IBOutlet weak var startButton: UIButton!
    
    @IBOutlet weak var endButton: UIButton!
    
    @IBAction func startButtonPressed(_ sender: UIButton) {
        startButton.isHidden = true
        endButton.isHidden = false
        speechKit.recordVoice()
        
    }
    
    @IBAction func endButtonPressed(_ sender: UIButton) {
        endButton.isHidden = true
        startButton.isHidden = false
        speechKit.endVoiceRecording()
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        speechKit.delegate = self
        endButton.isHidden = true
        
    }

}

I'm pretty sure this'll work.

nerdintown
  • 115
  • 1
  • 7