質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Watson

Watsonは、IBMが開発した質問応答・意思決定支援を行うシステムです。人口知能と言われることもあるが、IBMは自然言語処理と機械学習を用いて人間の意思決定を支援するコグニティブコンピューティングプラットホームと呼んでいます。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

2996閲覧

iOS(swift)におけるSpeechToText(watson)の実装について

hirdd

総合スコア50

Watson

Watsonは、IBMが開発した質問応答・意思決定支援を行うシステムです。人口知能と言われることもあるが、IBMは自然言語処理と機械学習を用いて人間の意思決定を支援するコグニティブコンピューティングプラットホームと呼んでいます。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2016/11/11 08:25

編集2016/11/15 06:03

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:. } }

■Debug navigator
イメージ説明

■storyboard
イメージ説明

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fromageblanc

2016/11/11 10:30

ソースはマークダウンを使っていただくと見やすいです。落ちるのはビルドした途端ですか?それともボタン押下時でしょうか。
hirdd

2016/11/11 12:21

コメントありがとうございます。マークダウンを使用して記載しました。落ちるのは、アプリの起動時です。まだ、ボタンも表示されていない時点で落ちてしまいます。。。
fromageblanc

2016/11/11 13:37

stt初期化の一行をコメントアウトにするとどうなりますか? // stt = SpeechToText(username: username, password: password)
hirdd

2016/11/12 13:30

コメントありがとうございます。状況は変わらず。。。同じエラーが出力されます。
hirdd

2016/11/14 11:51

コメントありがとうございます。override func viewDidLoad() {のすぐ下にprintを仕掛けても出力されないので、ViewController.swiftがロードされる前かと考えています。
hirdd

2016/11/15 05:18

self.setUpAudioRecorder()とself.instantiateSTT()を両方ともコメントアウトしたところ、同じ現象になってしまいました。何が起きているのかよく分かりません。どなたか、確認すべき点など教えていただけないでしょうか。。。
fromageblanc

2016/11/15 05:33

AppDelegate.swiftをアップしてもらえますか?
hirdd

2016/11/15 05:42

コメントありがとうございます。アップしました。
fromageblanc

2016/11/15 15:52

うーん、謎ですねぇ、、self.setUpAudioRecorder()とself.instantiateSTT()をコメントにしても落ちましたか。。。import SpeechToTextV1をコメントにしてそれに伴うエラー箇所もコメントにして実行しても一緒ですかね?
hirdd

2016/11/17 01:45

コメントありがとうございます。はい。一緒でしたね。そこで、別プロジェクトを作成し、同じソースコードを貼り付けたところ、問題は解消いたしました。しかしながら、別の問題が起こっています。stt.recognizeを読んだところで、以下のエラーが返されるようになってしまいました。何かヒントをいただく事は可能でしょうか?
hirdd

2016/11/17 01:45

Error Domain=WebSocket Code=400 "Invalid HTTP upgrade. Check credentials?" UserInfo={NSLocalizedFailureReason=Invalid HTTP upgrade. Check credentials?}
hirdd

2016/11/17 06:36

すみません。こちらの問題は、usernameとパスワードを逆にしていたのが原因でした。失礼しました。これにてこの質問は解決とさせて頂きたいと思います。fromageblancさん、ありがとうございます。
guest

回答1

0

ベストアンサー

1画面目のViewControllerの矢印のとこクリックして、「is Initial View Controller」にチェック入ってるか確認してみてください。
イメージ説明

投稿2016/11/15 05:28

fromageblanc

総合スコア2724

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hirdd

2016/11/15 05:47

確認したところ、is initial View Controllerにチェックが入っていました。ここにスクリーンショットを貼りたいのですが、どうやってはるのでしょうか?
fromageblanc

2016/11/15 05:54

やはり入ってますよね。。。 スクショはコメント欄だと出来ないですね。
hirdd

2016/11/15 06:05

一応、質問欄にdebug navigatorとstoryboardの画像を追加しました。何かお気付きの点があれば教えてください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問