1
在pod規範和S.O.上的當前內容之間。我經歷了一段艱難的時期,弄清楚瞭如何使用SpeechKit + CocoaPod + Swift實現語音到文本的工作。最後讓它工作,所以我想幫助下一個可憐的靈魂來尋求幫助! :)如何在Swift中使用CocoaPods時實現Nuance Speechkit
在pod規範和S.O.上的當前內容之間。我經歷了一段艱難的時期,弄清楚瞭如何使用SpeechKit + CocoaPod + Swift實現語音到文本的工作。最後讓它工作,所以我想幫助下一個可憐的靈魂來尋求幫助! :)如何在Swift中使用CocoaPods時實現Nuance Speechkit
#import <SpeechKit/SpeechKit.h>
到Nuance的開發門戶網站,並創建一個應用程序:https://developer.nuance.com/然後創建一個UIViewController和使用正確的憑據添加以下代碼:
import UIKit
import SpeechKit
class SpeechKitDemo: UIViewController, SKTransactionDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//!!link this to a corresponding button on the UIViewController in I.B.
@IBAction func tappedButton(sender: AnyObject) {
// All fields are required.
// Your credentials can be found in your Nuance Developers portal, under "Manage My Apps".
let SKSAppKey = "[Get this from the nuance app info page]";
let SKSAppId = "[Get this from the nuance app info page]";
let SKSServerHost = "[Get this from the nuance app info page]";
let SKSServerPort = "[Get this from the nuance app info page]";
let SKSLanguage = "eng-USA";
let SKSServerUrl = "nmsps://\(SKSAppId)@\(SKSServerHost):\(SKSServerPort)"
let session = SKSession(URL: NSURL(string: SKSServerUrl), appToken: SKSAppKey)
//this starts a transaction that listens for voice input
let transaction = session.recognizeWithType(SKTransactionSpeechTypeDictation,
detection: .Short,
language: SKSLanguage,
delegate: self)
print(transaction)
}
//required delegate methods
func transactionDidBeginRecording(transaction: SKTransaction!) { }
func transactionDidFinishRecording(transaction: SKTransaction!) { }
func transaction(transaction: SKTransaction!, didReceiveRecognition recognition: SKRecognition!) {
//Take the best result
let topRecognitionText = recognition.text;
print("Best rec test: \(topRecognitionText)")
//Or iterate through the NBest list
let nBest = recognition.details;
for phrase in (nBest as! [SKRecognizedPhrase]!) {
let text = phrase.text;
let confidence = phrase.confidence;
print("\(confidence): \(text)")
}
}
func transaction(transaction: SKTransaction!, didReceiveServiceResponse response: [NSObject : AnyObject]!) { }
func transaction(transaction: SKTransaction!, didFinishWithSuggestion suggestion: String!) { }
func transaction(transaction: SKTransaction!, didFailWithError error: NSError!, suggestion: String!) { }
}
我知道在調試器,阻止我做檢查得到一個問題:錯誤:包括非模塊化頭的內部框架模塊'SpeechKit' – Sean
當我使用我的沙盒憑證(應用程序密鑰,應用程序ID,主機,端口)實現此操作時,我在執行代碼時不斷收到以下錯誤消息:「Recorder Error Code:1 Message:Failed to open Stream 。內部錯誤-50。「你知道這可能是什麼原因嗎? – amurray4