Inspiration
FINLIT TRACK The project was inspired by the idea of bringing financial debates to life using AI voices. I wanted to create a platform where two agents, Bull and Bear, could autonomously prepare, debate, and rebut each other’s arguments on topics like stocks, crypto, or macro trends. The goal was to make financial discourse more engaging, accessible, and interactive, with real-time audio and citations.
What it does
TwoCents is a streaming AI debate platform. It features two autonomous agents (Bull and Bear) who prepare arguments, debate, and rebut each other in real time. The debate is streamed to the frontend with both text and synthesized audio, including citations for facts and sources. Users can watch and listen to the debate unfold live, with visual indicators for the current speaker and clickable source links.
How we built it
- Backend (FastAPI):
- Designed a debate orchestrator to manage agent prep, turn-taking, and phase transitions (Opening, Rebuttal, Closing).
- Integrated Google Gemini for text and TTS, with proper voice mapping (
zephyrfor Bull,rasalgethifor Bear). - Implemented an SSE endpoint to stream debate events, including audio and citations.
- Frontend (React/Next.js):
- Built a single streaming debate page that consumes SSE events, displays transcript, and plays audio using a hidden
<audio>element and a playback queue. - Added visual indicators for the current speaker and source links for citations.
- Built a single streaming debate page that consumes SSE events, displays transcript, and plays audio using a hidden
- Environment & Configuration:
- Managed API keys securely via
.envfiles. - Ensured cross-origin compatibility and smooth local development.
- Managed API keys securely via
Challenges we ran into
- SSE Chunking & JSON Parsing: Large base64 audio payloads often arrived split across network chunks, causing
Unterminated string in JSONerrors. I solved this by buffering incoming data and only parsing complete SSE events. - TTS Model Constraints: Gemini’s TTS model only supports specific voice names. Initial attempts with studio voices failed, so I switched to documented voices and added fallback logic.
- Audio Playback Queue: Ensuring audio clips played sequentially without overlap or dropped turns required careful state management and error recovery.
- Grounding & Citations: Extracting and displaying reliable sources from AI-generated content was non-trivial, especially with varying SDK responses.
Accomplishments that we're proud of
- Built a fully autonomous, streaming debate system with real-time audio and citations.
- Solved tricky streaming and parsing issues for robust client-server communication.
- Achieved seamless audio playback and visual speaker indication in the frontend.
- Integrated advanced AI models for both text and speech, with proper error handling and voice selection.
What we learned
- Streaming Architectures: Implementing Server-Sent Events (SSE) for real-time updates and audio streaming taught me about chunked data delivery and client-side buffering.
- AI Model Integration: Learned how to use Google Gemini’s generative models for both text and TTS (text-to-speech), including handling model-specific constraints like supported voice names and response modalities.
- Frontend Audio Queuing: Building a React audio queue for seamless playback of streamed base64 audio required careful handling of asynchronous events and browser APIs.
- Error Handling: Debugging issues like partial JSON parsing and unsupported TTS voices deepened my understanding of robust client-server communication.
What's next for TwoCents
- Add user barge-in and live question support, allowing users to interrupt or participate in the debate.
- Enhance grounding and citation extraction for more reliable fact-checking.
- Implement chunked audio streaming for lower latency and smoother playback.
- Persist debate transcripts and audio for later review or sharing.
- Expand to more debate topics and agent personalities.
Math & AI
The debate agents use prompt engineering and context-aware generation, leveraging search grounding to cite facts. While not directly mathematical, the system could be extended to discuss equations, e.g.:
$$ P = \frac{E}{r} $$
where $P$ is price, $E$ is earnings, and $r$ is the discount rate—a common topic in financial debates.
Log in or sign up for Devpost to join the conversation.