Android Offline STT SDK
SDK Version: 1.0.0
The STT SDK transcribes local WAV audio without a network connection. It prepares the bundled Vosk model, validates the audio stream, and returns text. Recording, permissions, transcoding, and UI remain host responsibilities.
Requirements
- WAV/RIFF container
- 16-bit PCM, mono, 16 kHz
- A URI that
ContentResolvercan open - A release package containing the Vosk/JNA native libraries and bundled models
Add the supplied STT SDK artifact and preserve its transitive/native dependencies.
APIs
object XTalkStt {
suspend fun prepare(context: Context, languageTag: String? = null)
suspend fun transcribeWavUri(
context: Context,
wavUri: String,
languageTag: String? = null,
): XTalkSttResult
}
data class XTalkSttResult(val text: String)
class XTalkSttException(val code: XTalkSttErrorCode, ...)
Tags beginning with zh select the bundled Chinese model. Other or null tags select the English model.
Example
suspend fun transcribe(context: Context, uri: Uri): String =
withContext(Dispatchers.IO) {
XTalkStt.prepare(context, "en-US") // optional warm-up
XTalkStt.transcribeWavUri(
context = context,
wavUri = uri.toString(),
languageTag = "en-US",
).text
}
Both calls are suspending. Warm-up is optional because transcription prepares the selected model automatically.
Errors
XTalkSttErrorCode | Meaning and action |
|---|---|
ENGINE_NATIVE_MISSING | Vosk/JNA native library is absent or ABI-incompatible; check packaging. |
MODEL_MISSING | The selected model asset is missing; replace the release package. |
MODEL_CORRUPT | Model extraction/loading failed; clear the app model cache and retry once. |
AUDIO_UNSUPPORTED | Input is not mono 16-bit 16 kHz PCM WAV; transcode before retrying. |
TRANSCRIBE_FAILED | Engine or result parsing failed; retain the classified error and retry only when appropriate. |
try {
val text = XTalkStt.transcribeWavUri(context, uri.toString(), "en-US").text
} catch (e: XTalkSttException) {
showSttError(e.code)
}
Do not send audio or model contents to logs. The SDK performs no cloud recognition.