AVSpeechSynthesizer 和 AirPlay — 音频设备休眠?

AVSpeechSynthesizer and AirPlay — Audio Device Sleeping?

如果我使用 AVSpeechSynthesizer 说出一些文本,它在设备上可以正常工作,但是一旦我使用 AirPlay,语音的开头就会被切断,除非之前刚说了些什么。

看来音频设备要休眠了。

下面是我的代码

let synthesizer = AVSpeechSynthesizer()

func speakCall(call: (letter: String, number: Int)) -> Void {
    for  _ in 1...2 { // Speak the message twice
        let utterance = AVSpeechUtterance(string: "\(call.letter), \(call.number)")
        utterance.postUtteranceDelay = 0.15
        synthesizer.speakUtterance(utterance)
    }
}

可以让AVAudioPlayer静音播放,这样会导致音频设备不休眠

let silence = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("silence", ofType: "mp3")!)
var silencePlayer: AVAudioPlayer?
try? silencePlayer = AVAudioPlayer(contentsOfURL: silence)
silencePlayer?.numberOfLoops = -1
silencePlayer?.play()