WatchKitのAVSpeechSynthesizerで音が鳴らない

自作英単語学習アプリ EverLearn には watchOS用アプリがあり、iOS側でまちがった単語をApple Watchに転送して学習することができる。

Apple Watch 上では AVSpeechSynthesizer を使って英単語を発音させていたのだが、Xcode 11 GM seed + watchOS6 GM seed では音が鳴ってくれない。

おかしいと思って試行錯誤していたところ、AVAudioSessionを設定していなかったことに気づき、設定して試してみたところ、無事音が鳴るようになった。

        AVAudioSession *session = [AVAudioSession sharedInstance];
        NSError *error = nil;
        [session setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeMoviePlayback options:AVAudioSessionCategoryOptionAllowBluetoothA2DP error:&error];
        
        // AVSpeechSynthesizerを初期化する。
        AVSpeechSynthesizer* speechSynthesizer = [[AVSpeechSynthesizer alloc] init];

Audio Session Categories and Modes

ios – AVSpeechSynthesizer is not working After use one time – Stack Overflow

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.