簡體   English   中英

需要設備識別

[英]Require on device recognition

有沒有辦法知道Swift下載語音模型需要多長時間?

嘗試使用OSSSpeechKit 它在沒有模型的情況下工作。 這是鏈接: https : //cocoapods.org/pods/OSSSpeechKit#speech-to-text

示例代碼:

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
        
    }

}

我很確定這會奏效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM