On this page
Speech to Text covers dictation APIs. This project records audio files and processes them afterwards, which lets you transcribe longer notes, re-process later, and run AI over the result.
Architecture
1. Record audio
class VoiceRecorder(private val context: Context) {
private var recorder: MediaRecorder? = null
/** Requires RECORD_AUDIO permission granted. */
fun start(output: File) {
recorder = MediaRecorder(context).apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
setAudioSamplingRate(16_000)
setAudioEncodingBitRate(64_000)
setOutputFile(output)
prepare()
start()
}
}
fun stop() {
recorder?.runCatching { stop() } // stop() throws if nothing was recorded
recorder?.release()
recorder = null
}
}
// MediaRecorder(Context) requires API 31+; use the deprecated no-arg constructor on older versions.Store files in filesDir (app-private). Request RECORD_AUDIO in context. For long recordings in the background, you'd need a foreground service with the microphone type. See Foreground Services.
2. Transcribe
| Option | Pros | Cons |
|---|---|---|
| Cloud multimodal (Gemini audio input) | Works on all devices, handles long audio, can transcribe + summarise together | Audio leaves the device; cost |
| ML Kit GenAI Speech Recognition (alpha) | On-device, private | Alpha; device and language support limited |
Platform SpeechRecognizer | Built in | Designed for live mic input, not files |
suspend fun transcribe(model: GenerativeModel, audio: File): String {
val response = model.generateContent(content {
inlineData(audio.readBytes(), "audio/mp4")
text("Transcribe this voice note verbatim. Mark unclear words as [inaudible].")
})
return response.text.orEmpty()
}
// Inline data has size limits; for long recordings, split audio or use file upload options per the docs.3. Summarise and extract action items
@Serializable
data class Enrichment(val title: String, val summary: String, val actionItems: List<String>)
suspend fun enrich(model: GenerativeModel, transcript: String): Enrichment {
val response = model.generateContent(
"From this voice note transcript, return JSON with: title (max 6 words), " +
"summary (max 2 sentences), actionItems (list, only explicit tasks; empty if none). " +
"Use only information in the transcript.\n\nTranscript:\n$transcript"
)
return Json { ignoreUnknownKeys = true }.decodeFromString(response.text.orEmpty())
}
// Configure the model with responseMimeType = "application/json" and a schema for reliability.4. Process in the background
@HiltWorker
class ProcessNoteWorker @AssistedInject constructor(
@Assisted ctx: Context, @Assisted params: WorkerParameters,
private val notes: NoteRepository,
private val ai: VoiceAi,
) : CoroutineWorker(ctx, params) {
override suspend fun doWork(): Result {
val id = inputData.getLong("noteId", -1)
val note = notes.get(id) ?: return Result.failure()
return try {
val transcript = note.transcript ?: ai.transcribe(File(note.audioPath)).also { notes.saveTranscript(id, it) }
if (note.summary == null) notes.saveEnrichment(id, ai.enrich(transcript))
Result.success()
} catch (e: IOException) {
Result.retry()
}
}
}
// Enqueue with a CONNECTED network constraint as unique work per note.5. Store and search
Use Room with an FTS table over title, transcript and summary for instant search. See Room Database. Show per-note status: "Transcribingβ¦", "Ready", "Failed β retry".
Privacy
- Voice notes can be very personal: explain where audio is processed, and offer on-device mode where supported.
- Let users delete audio after transcription, and delete everything with one action.
- Exclude audio from cloud backups if sensitive.
- See AI Privacy and Data Retention.
Frequently asked questions
Which languages are supported?
Cloud multimodal models support many languages. On-device options are more limited, so check the docs and test with real speakers.
How accurate are transcripts?
Usually good for clear speech, worse with noise, accents and jargon. Let users edit transcripts.
Conclusion
A voice-notes app records to private files, transcribes on device or in the cloud, enriches with summaries and action items as JSON, processes in WorkManager, and stores searchable notes, with privacy controls front and centre.
Next project: an AI Study Assistant.
Official references
π± Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it βΈ
NotiVaultNotification history: recover dismissed notificationsGet it βΈ
Ready to build real Android applications?
Every AI feature still runs inside an Android app that has to be fast, reliable and well structured. Strengthen the Kotlin, Jetpack Compose and architecture skills that AI integrations depend on, then apply these AI concepts with confidence.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.