Skip to content

Commit

Permalink
Don't speak over each other (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Sudekum committed Mar 8, 2018
1 parent 9ffcc58 commit 6aab907
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions MapboxNavigation/MapboxVoiceController.swift
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit 6aab907

Please sign in to comment.