10

AVSpeechUtterance を使用して、指定されたテキストを読み上げています。私は以下のコードを使用しており、「iPhone リンガー モード」では問題なく動作しますが、iPhone を「サイレント モード」に変更すると、発話音声がミュートになります。そして「サイレントモード」だと発声音声が聞こえません。「サイレントモード」で発声音声を聞くにはどうすればよいですか。

AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@"Hello World"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
[utterance setRate:AVSpeechUtteranceMinimumSpeechRate];
[utterance setVolume:1];
[self.speechSynthesizer speakUtterance:utterance];
4

3 に答える 3

1

同様の問題があり、AVAudio セッション メソッドを追加して修正しました。スイフト5.0

    // this  AVAudioSession method is for speak text when device is in silent mode
    do {
        try AVAudioSession.sharedInstance().setCategory(.playback,mode: .default)

    } catch let error {
        print("This error message from SpeechSynthesizer \(error.localizedDescription)")
    }
    
    let speechSynthesizer = AVSpeechSynthesizer()
    let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: text)
    
    speechUtterance.rate = AVSpeechUtteranceMaximumSpeechRate / 2.3
    speechUtterance.voice = AVSpeechSynthesisVoice(language: "en-US")
    speechSynthesizer.speak(speechUtterance)
    
}
于 2020-10-25T05:36:59.867 に答える