@@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.filter
2727import kotlinx.coroutines.flow.first
2828import kotlinx.coroutines.flow.flatMapConcat
2929import kotlinx.coroutines.flow.flatMapLatest
30+ import kotlinx.coroutines.flow.flatMapMerge
3031import kotlinx.coroutines.flow.flowOf
3132import kotlinx.coroutines.flow.map
3233import kotlinx.coroutines.flow.updateAndGet
@@ -123,12 +124,12 @@ internal constructor(
123124 /* *
124125 * Top level flow that will switch based on the language and muted state.
125126 */
126- @OptIn(ExperimentalCoroutinesApi ::class , FlowPreview :: class )
127+ @OptIn(ExperimentalCoroutinesApi ::class )
127128 private fun audioGuidanceFlow (
128129 mapboxNavigation : MapboxNavigation
129130 ): Flow <MapboxAudioGuidanceState > {
130- return mapboxNavigation.audioGuidanceVoice().flatMapLatest { audioGuidance ->
131- var lastPlayedInstructions : VoiceInstructions ? = null
131+ var lastPlayedInstructions : VoiceInstructions ? = null
132+ return mapboxNavigation.audioGuidanceVoice().flatMapMerge { audioGuidance ->
132133 mutedStateFlow.flatMapLatest { isMuted ->
133134 val voiceInstructions = mapboxVoiceInstructions.voiceInstructions()
134135 .map { state ->
@@ -146,18 +147,15 @@ internal constructor(
146147 } else {
147148 voiceInstructions
148149 .filter { it.voiceInstructions != lastPlayedInstructions }
149- .flatMapConcat {
150+ .map {
150151 lastPlayedInstructions = it.voiceInstructions
151152 val announcement = audioGuidance.speak(it.voiceInstructions)
152- flowOf(announcement)
153- }
154- .map { speechAnnouncement ->
155- internalStateFlow.updateAndGet {
153+ internalStateFlow.updateAndGet { state ->
156154 MapboxAudioGuidanceState (
157- isPlayable = it .isPlayable,
158- isMuted = it .isMuted,
159- voiceInstructions = it .voiceInstructions,
160- speechAnnouncement = speechAnnouncement
155+ isPlayable = state .isPlayable,
156+ isMuted = state .isMuted,
157+ voiceInstructions = state .voiceInstructions,
158+ speechAnnouncement = announcement
161159 )
162160 }
163161 }
0 commit comments