Microphone

interface Microphone : MapboxNavigationObserver

Microphone interface allows the platform to define a source for audio. The microphone can be used to stream audio data from the platform to the Mapbox SDK.

Types

Link copied to clipboard
data class Config(val sampleRateHz: Int = 16000)

Defines the specific details from the microphone.

Link copied to clipboard
sealed class State

Represent current microphone state

Functions

Link copied to clipboard
abstract fun onAttached(mapboxNavigation: MapboxNavigation)
Link copied to clipboard
abstract fun onDetached(mapboxNavigation: MapboxNavigation)
Link copied to clipboard
abstract fun stop()

Stops streaming audio from the microphone and causes stream to exit. The state flow will move to State.Idle.

Link copied to clipboard
abstract suspend fun stream(consumer: (Microphone.State.Streaming) -> Unit)

Starts streaming audio from the microphone. The audio is streamed in chunks and surfaced through the consumer lambda as well as the state flow. The consumer lambda will use State.Streaming to process the audio data. The state flow can be used to share the streaming bytes for multiple uses.

Properties

Link copied to clipboard
abstract val config: Microphone.Config

Configuration setting for the microphone.

Link copied to clipboard
abstract val state: StateFlow<Microphone.State>

The current state of the microphone. Implementations should update this as the microphone changes state. Example: