From 6aab907d657f7a48635365d8af1920e27347e736 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 8 Mar 2018 15:41:30 -0800 Subject: [PATCH] Don't speak over each other (#1213) --- MapboxNavigation/MapboxVoiceController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MapboxNavigation/MapboxVoiceController.swift b/MapboxNavigation/MapboxVoiceController.swift index eeeefdd0bb..d839e763d2 100644 --- a/MapboxNavigation/MapboxVoiceController.swift +++ b/MapboxNavigation/MapboxVoiceController.swift @@ -78,8 +78,6 @@ open class MapboxVoiceController: RouteVoiceController { assert(routeProgress != nil, "routeProgress should not be nil.") - - guard let _ = routeProgress!.route.speechLocale else { speakWithDefaultSpeechSynthesizer(instruction, error: nil) return @@ -171,6 +169,9 @@ open class MapboxVoiceController: RouteVoiceController { Plays an audio file. */ @objc open func play(_ data: Data) { + + super.speechSynth.stopSpeaking(at: .immediate) + DispatchQueue.global(qos: .userInitiated).async { do { self.audioPlayer = try AVAudioPlayer(data: data) @@ -186,6 +187,7 @@ open class MapboxVoiceController: RouteVoiceController { let played = self.audioPlayer?.play() ?? false guard played else { + try super.unDuckAudio() self.speakWithDefaultSpeechSynthesizer(self.lastSpokenInstruction!, error: NSError(code: .spokenInstructionFailed, localizedFailureReason: self.localizedErrorMessage, spokenInstructionCode: .audioPlayerFailedToPlay)) return }