2016-01-29 45 views
0

如果我使用AVSpeechSynthesizer說一些文字,它可以在設備上正常工作,但只要我使用AirPlay,演講的開始將會被切斷,除非事先剛剛講過。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) 
    } 
} 

回答

0

你可以告訴AVAudioPlayer玩沉默,將導致音頻設備無法入睡。

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