Shipping a Full-Duplex Voice App with AI Coding Tools: An Android Practice

    AI coding tools can scaffold an Android voice chat app quickly, but full-duplex audio lives or dies in on-device debugging: echo, barge-in, VAD, and focus. This article explains why token spend does not track wait time, where the engineering difficulty actually is, and five ways to spend model quota on the hard 20%.

    1. What actually happened: output vs. spend in one afternoon plus one evening

    Generating the skeleton of an Android voice chat app with an AI coding tool is usually easy: UI, permissions, record and playback, a simple message path. A runnable first version can appear quickly. The time sink is the second half—real-device debugging.

    After an afternoon and an evening, quota did not “blow up.” The task was not simple; the interaction shape changed. Compile, install, audio tuning, and reproducing issues took most of the clock, while each model reply covered less useful work. Quota spend is not proportional to time spent waiting on the device. That fact is the starting point for cost control.

    Full-duplex voice is also a state-machine-heavy problem. It is not “record plus play.” You must handle barge-in, echo, silence detection, network jitter, and audio-focus preemption as a timed sequence. That debugging depends on a real phone and a real acoustic environment. Static generation cannot close it.

    2. Full-duplex voice: where the difficulty actually is

    2.1 Half-duplex vs. full-duplex

    Half-duplex is “you finish, then I speak”: mutually exclusive states, simpler to implement. Full-duplex allows both sides to talk at once and to interrupt each other. The system must capture continuously, play continuously, and keep two audio paths alive at the same time.

    2.2 Echo cancellation is a usability line

    If played audio is recaptured by the microphone and sent back, the user hears their own voice delayed and the product fails. Engineering typically relies on system echo cancellation and noise reduction, plus a sensible audio source and sample rate. Capability varies by device; you adapt to models instead of assuming uniformity.

    2.3 Voice activity detection decides when to send

    Uploading silence frames wastes bandwidth and compute. A common lightweight approach uses short-term energy and zero-crossing rate, with hold times so the decision does not chatter:

    1. // Sketch: simple energy-based voice activity detection
    2. fun isSpeech(buffer: ShortArray, sampleRate: Int, threshold: Double): Boolean {
    3. var energy = 0.0
    4. for (s in buffer) energy += s.toDouble() * s
    5. energy = Math.sqrt(energy / buffer.size)
    6. return energy > threshold // threshold must be calibrated to device gain
    7. }

    In a real project the threshold must be configurable and tunable at runtime, not a hardcoded constant.

    2.4 Barge-in and audio focus

    When the user starts speaking, the reply that is playing should fade out quickly rather than hard-cut. The app must also handle audio focus so calls, navigation prompts, and similar events can preempt and restore correctly.

    2.5 End-to-end latency budget

    Natural conversation is latency-sensitive. Set budgets by layer: capture and encode, uplink, server inference, downlink, jitter buffer and playback. Each layer needs a hard cap and a degrade path (downsample, shorten the buffer, keep the most recent semantics).

    3. Why the Android debug phase burns quota in a particular way

    • Long feedback loop: A change needs compile, install, permission grants, and reproduction. The model cannot see the result immediately.
    • Context drowned in logs: Dumping full device logs fills the window with low-density text that still consumes budget.
    • Vague problem statements: “There is noise” cannot be localized, so you get many exploratory edits.
    • Environment drift ignored: Emulator vs. device and OS-version audio differences make “fixed” issues regress.

    4. Five engineering moves that put quota on the hard problems

    4.1 Slice the work: one verifiable problem at a time

    Split “build a voice app” into: permissions and audio session init → uplink capture only → downlink playback only → echo-cancellation proof → barge-in → weak-network degrade. Each slice has its own acceptance criteria so you avoid large rewrites.

    4.2 Shrink context: a minimal reproducible sample

    Do not paste full logs. Give a small, reproducible packet: device and OS version, sample rate and audio source, steps, a few key log lines, expected vs. actual.

    1. Environment: physical device / OS version X / 16 kHz / mono
    2. Symptom: local voice is echoed back while the other party speaks, delay ~300 ms
    3. Tried: changing buffer length, no effect
    4. Expected: mic input suppressed while playback is active

    4.3 Isolate quota and compute

    Separate exploratory generation from critical-path work. Reserve dedicated quota for hard debugging. Everyday boilerplate should come from local templates or existing modules so a shared pool is not contended.

    4.4 Observability first

    Instrument capture frame rate, dropped frames, end-to-end latency, buffer water level, and barge-in count. Ship logs to a unified logging and alerting stack. Judge “fixed” with metrics, not feel.

    4.5 Automated regression

    Turn “we can talk” into a repeatable check: scripted install, automated input audio samples, assertions that the output path is suppressed when it should be. Humans only handle acoustic judgment that automation cannot cover.

    5. A staged path to ship

    1. Close the loop: smallest path; only verify capture-to-play latency order of magnitude.
    2. Stabilize quality: lock sample rate, channels, and buffering; sample a device matrix.
    3. Implement barge-in: make the state machine explicit; avoid a pile of boolean flags.
    4. Weak network and degrade: define timeout, reconnect, and bitrate-drop triggers.
    5. Subjective eval: real multi-person conversations scored into a regression baseline.

    6. Conclusion

    AI coding tools amplify people who already know what they are building. Full-duplex voice is not a code-volume problem; it is timing, acoustics, and device fit. Long Android debug sessions do not automatically mean high model spend. The job is to turn a long feedback loop into a short one. Task slicing, tight context, quota isolation, observability, and automated regression keep limited compute on the hard 20%, and leave boilerplate to tools and templates.