watson-developer-cloudのiOS-sdkを使用して簡単なSpeechToTextを使用した簡単なアプリを開発しようとしてます。
mainStoryboad上のrecordボタンとstopボタンで録音します。
その後、transcribeボタンでpressTranscribeButtonでSpeechToTextが呼び出されるようにしたいと思っています。
いかのソースコードのように実装して、あとはATSの認証のためにinfo.plistを修正しました。
コンパイルも通り、実行してみたところAppDelegate.swiftで以下のエラーが出てしまい、解決できずに困っています。
どなたか、解決方法をご教授いただけないでしょうか?
■エラー内容
class AppDelegate: UIResponder, UIApplicationDelegate { Thread1:signalSIGABRT
■WatsonDeveloperCloud iOS-sdk
https://github.com/watson-developer-cloud/ios-sdk
■環境
iOS:10.1
xcode:8.1
■ソースコード
swift
1import UIKit 2import AVFoundation 3import SpeechToTextV1 4 5class ViewController: UIViewController { 6 7 var audioRecorder : AVAudioRecorder? 8 var fileName = "Sample.wav" 9 var stt : SpeechToText? 10 @IBOutlet weak var transcribeField: UITextView! 11 12 override func viewDidLoad() { 13 14 super.viewDidLoad() 15 // Do any additional setup after loading the view, typically from a nib. 16 self.setUpAudioRecorder() 17 self.instantiateSTT() 18 } 19 20 @IBAction func pressRecordeButton(_ sender: Any) { 21 22 audioRecorder?.record() 23 } 24 25 @IBAction func pressStopButton(_ sender: Any) { 26 27 audioRecorder?.stop() 28 } 29 30 31 @IBAction func pressTranscribeButton(_ sender: Any) { 32 33 let settings = RecognitionSettings(contentType: .wav) 34 35 stt!.recognize(audio:audioRecorder!.url, settings: settings,failure: failureData) { results in 36 self.showResults(results: results) 37 } 38 } 39 40 func failureData(error: Error) { 41 let title = "Speech to Text Error:\nTranscribe" 42 print(title) 43 } 44 45 func showResults(results: SpeechRecognitionResults) { 46 var text = "" 47 48 text = results.bestTranscript 49 self.transcribeField.text = text 50 } 51 52 override func didReceiveMemoryWarning() { 53 super.didReceiveMemoryWarning() 54 } 55 56 func instantiateSTT() { 57 58 let username = "username" 59 let password = "password" 60 61 stt = SpeechToText(username: username, password: password) 62 } 63 64 func setUpAudioRecorder() { 65 66 let session = AVAudioSession.sharedInstance() 67 68 do { 69 try session.setCategory(AVAudioSessionCategoryPlayAndRecord) 70 try session.setActive(true) 71 let recordSetting : [String : AnyObject] = [ 72 AVEncoderAudioQualityKey : AVAudioQuality.min.rawValue as AnyObject, 73 AVEncoderBitRateKey : 16 as AnyObject, 74 AVNumberOfChannelsKey: 2 as AnyObject, 75 AVSampleRateKey : 44100.0 as AnyObject 76 ] 77 78 try audioRecorder = AVAudioRecorder(url: self.documentFilePath(), settings: recordSetting) 79 80 }catch { 81 82 print("setupAudioRecorderの初期設定でのエラー") 83 } 84 } 85 86 // 87 // Create the URL to store WAV file. 88 // 89 func documentFilePath() -> URL { 90 91 // let urls = FileManager.urls(FileManager.SearchPathDirectory.DocumentDirectory, inDomains:FileManager.SearchPathDomainMask.userDomainMask) 92 93 let urls = FileManager.default.urls(for: .documentDirectory, in:.userDomainMask) as [URL] 94 let dirUrl = urls[0] 95 96 // Just out of curiosity, check the directory structure. 97 let numOfUrl = urls.count 98 99 for i in 0..<numOfUrl { 100 101 print(urls[i]) 102 } 103 104 return dirUrl.appendingPathComponent(fileName) 105 } 106}
■AppDelegate.swift
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }
回答1件
あなたの回答
tips
プレビュー