[英]AVSpeechSynthesizer and AirPlay — Audio Device Sleeping?
If I use AVSpeechSynthesizer to speak some text it works fine on the device but as soon as I use AirPlay the start of the speech will get cut off unless something was just spoken before. 如果我使用AVSpeechSynthesizer讲一些文本,则可以在设备上正常工作,但是一旦我使用AirPlay,除非您之前刚刚说过什么,否则演讲开始会被切断。
It appears that the audio device is going to sleep. 看来音频设备要入睡了。
Below is my code 下面是我的代码
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)
}
}
You can tell AVAudioPlayer to play silence, that will cause the audio device to not sleep. 您可以告诉AVAudioPlayer播放静音,这将导致音频设备无法休眠。
let silence = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("silence", ofType: "mp3")!)
var silencePlayer: AVAudioPlayer?
try? silencePlayer = AVAudioPlayer(contentsOfURL: silence)
silencePlayer?.numberOfLoops = -1
silencePlayer?.play()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.