AI Coding Assistants in Practice: Building a Full-Duplex Voice App End to End

    This article walks through building an Android app with full-duplex voice chat using an AI coding assistant. It explains why full-duplex voice is difficult, covering echo cancellation, interruption handling, and end-to-end latency, then shows how to split the system into replaceable layers. It also covers how to prompt AI tools effectively, why observability should come first when debugging, how to combine cloud services, and what to check before release.

    1. What Changed After a Hands-On Session

    A developer spent one afternoon and one evening continuously generating code with an AI coding tool. The goal was an Android app that supported full-duplex voice chat. In the end, the usage quota was not exhausted, and the app basically ran.

    What makes this case interesting is not how long it took. It is the shift in how the work was done: instead of typing code line by line, the developer described intent in natural language, let the tool generate the skeleton and candidate implementations, and then judged, verified, and narrowed down the result.

    AI coding tools do not remove engineering complexity automatically. Real-time voice pipelines, the timing of audio capture and playback, and the experience under network jitter still require the developer to make the calls. These tools are good at quickly laying down code for known patterns, but architecture trade-offs and problem isolation remain core human work. The original account mentions that debugging took a lot of time, which shows that generated code is only the starting point. Verification and tuning are what actually consume time.

    2. Breaking Down the Requirements: What Makes Full-Duplex Voice Hard

    Full-duplex means both sides can speak and be heard at the same time, rather than taking turns as in half-duplex. The core challenges come down to three points.

    First, echo and self-hearing. The far-end audio played through the speaker is picked up again by the microphone. Without handling, this creates harsh feedback. The common industry approach is echo cancellation: on the capture side, use the playback signal as a reference for adaptive filtering and subtract the self-played component from the microphone signal.

    Second, interruption and turn management. Full-duplex lets the user jump in at any time, so the system cannot rely on an explicit state machine like push-to-talk. It needs to continuously determine speaking state at the audio-stream level and support switching quickly to capture priority when playback is interrupted.

    Third, end-to-end latency. Voice is extremely sensitive to latency, and the goal is usually to keep end-to-end delay low. Latency accumulates across capture buffering, encoding, network transmission, decoding, and playback buffering. If any stage sets its buffer too large, the sense of conversation breaks immediately.

    3. Architecture Choices: Split the Pipeline into Replaceable Modules

    A recommended approach is to split the system into four layers that communicate through clear interfaces, so each layer can be replaced and tested independently.

    • Capture and playback layer: audio input and output, echo cancellation, gain, and noise reduction.
    • Codec and transport layer: compression, packetization, real-time transmission, and jitter buffering.
    • Session and state layer: connection setup, identity, interruption arbitration, and silence detection.
    • Business and model layer: speech recognition, dialogue understanding, speech synthesis, or integration with a remote AI service.

    The benefit of layering is that when you use an AI coding tool, you can focus it on one layer at a time. This avoids tightly coupled output that is hard to debug.

    A sketch of the interfaces could look like this:

    1. interface AudioCapture {
    2. fun start(sampleRate: Int, channels: Int, onFrame: (ShortArray) -> Unit)
    3. fun stop()
    4. }
    5. interface AudioPlayback {
    6. fun start(sampleRate: Int, onUnderrun: () -> Unit)
    7. fun push(frame: ShortArray)
    8. fun flush()
    9. }
    10. interface Transport {
    11. fun send(frame: ByteArray)
    12. fun onReceive(callback: (ByteArray) -> Unit)
    13. fun close()
    14. }

    4. Using AI Coding Tools Correctly: Generate in Small Steps, Verify Fast

    To get real gains from an AI coding tool, control the size of each generation. Asking it to “write a complete app” in one shot often produces something that looks complete but does not run. Splitting the task into pieces like “implement an echo cancellation wrapper,” “implement a jitter buffer queue,” or “complete the permission request flow” raises the success rate noticeably.

    A reusable prompt structure is: role + goal + constraints + acceptance criteria. For example:

    1. You are a senior Android audio engineer.
    2. Goal: implement an audio capture wrapper class.
    3. Constraints: minimum supported version is Android 8.0, use a foreground service to keep capture running, request the recording permission.
    4. Acceptance: provide the class code, the permission list, and a minimal runnable usage example.

    Also build a loop of generate, compile, run, and collect logs. Compile after each small module, and feed compile errors and runtime logs back to the tool as-is so it can make targeted fixes. This is far more efficient than piling up errors and dealing with them all at once, and it keeps the tool from drifting further off in a wrong context.

    5. Debugging Is the Main Battlefield: Observability First

    The original account notes that debugging was time-consuming, which matches engineering reality. Add observability from the start rather than after problems appear.

    • Stage timing: record timestamps at capture, encoding, sending, receiving, decoding, and playback to compute the time spent in each stage directly.
    • Audio visualization: show input and output waveforms or energy values on screen or in logs so you can tell at a glance whether valid sound is being captured.
    • State logs: record session state transitions, such as the trigger that switches from playback state to capture state.
    • Fallback switch: provide a forced half-duplex mode to quickly determine whether the problem lies in the full-duplex arbitration logic.

    With this data, questions to the AI coding tool can include precise context, such as “the average receive time is normal, but the playback buffer frequently underflows.” The tool’s suggested fix will be much more accurate.

    6. How Cloud Capabilities Fit In: Assemble Services from Common Categories

    A voice app usually does not need to run all AI capabilities on the device. You can organize things around common cloud product categories: use object storage to hold necessary audio assets and configuration; use a message queue or real-time channel to carry signaling and forwarding; use a container platform to deploy recognition and synthesis services for elastic scaling; use a logging service to collect client and server logs centrally; and use monitoring and alerting to set thresholds for latency, error rate, and resource usage. Baidu AI Cloud offers these common capability categories, and you can choose a combination based on business scale rather than adopting every component at once.

    One thing to keep in mind is to define the split between device and cloud early: keep the most latency-sensitive parts as close to the device as possible, put compute-heavy model inference on the cloud side, and connect them with a lightweight protocol.

    7. Pre-Launch Checklist

    1. Permissions and privacy: recording is a sensitive permission, so state its purpose clearly and provide a way to turn it off.
    2. Foreground service and lifecycle: define capture and playback behavior when the app goes to the background, during a call, and when the screen locks.
    3. Weak-network strategy: adaptive jitter buffering, packet loss compensation, and falling back to half-duplex when necessary.
    4. Resource usage: continuous capture and playback noticeably affect battery and heat, so measure duration and power consumption.
    5. Gradual rollout and rollback: release to a small group first and keep a switch to disable the new pipeline quickly.

    8. Conclusion

    The real value of this hands-on case is that it shows a new development rhythm: state intent clearly in natural language, use an AI coding tool to quickly lay down a runnable skeleton, and then use solid observability to narrow down problems one by one. Tools compress coding time. What cannot be saved is always design judgment and debugging effort. Break modules into smaller pieces, add full logging, and write clear acceptance criteria, and you can turn an afternoon plus an evening of work into a voice app that is genuinely deliverable and maintainable.