Skip to main content
Most people who will use your app carry an Android phone. This page builds the two halves of a voice feature: a small server route that holds your key, and the Kotlin code that records, uploads and plays.
Never put your Namu key in the app. An APK can be unpacked in minutes, and the key would let anyone spend your allowance.

1. The server route

Any server works. Two routes in Python with Flask and the Python library (pip install namu-ai):
server.py

2. Record a voice note

MediaRecorder writes AAC in an M4A file: small, and read by the API as it is. Ask for the microphone permission first (android.permission.RECORD_AUDIO).
Recorder.kt
MediaRecorder(context) needs Android 12 (API 31); on older versions use MediaRecorder().

3. Send it and read the text

With OkHttp (com.squareup.okhttp3:okhttp). Run it off the main thread, in a coroutine:
VoiceApi.kt

4. Play the answer

Keep note.m4a until the transcription succeeds: if the network drops, retry from the file instead of asking the person to speak again. More habits in building for weak networks.