from swarms import Agent
from swarms.structs.conversation import Conversation
from swarms.utils.history_output_formatter import history_output_formatter
from voice_agents import speech_to_text, record_audio, StreamingTTSCallback
def debate_with_speech(
agents: list,
max_loops: int = 1,
task: str = None,
output_type: str = "str-all-except-first",
use_stt_for_input: bool = False,
):
if len(agents) != 2:
raise ValueError("There must be exactly two agents in the dialogue.")
conversation = Conversation()
agent1, agent2 = agents
tts_callback1 = StreamingTTSCallback(voice="onyx", model="openai/tts-1")
tts_callback2 = StreamingTTSCallback(voice="nova", model="openai/tts-1")
# Optional: capture the opening prompt by voice
if use_stt_for_input and task is None:
print("Please speak your question or topic for the debate...")
audio = record_audio(duration=10.0)
task = speech_to_text(audio_data=audio, sample_rate=16000)
print(f"Transcribed: {task}\n")
message = task
speaker, other = agent1, agent2
current_callback, other_callback = tts_callback1, tts_callback2
for i in range(max_loops):
print(f"\n--- Turn {i+1}: {speaker.agent_name} speaking ---\n")
response = speaker.run(task=message, streaming_callback=current_callback)
current_callback.flush()
conversation.add(speaker.agent_name, response)
message = response
# swap roles + callbacks
speaker, other = other, speaker
current_callback, other_callback = other_callback, current_callback
tts_callback1.flush()
tts_callback2.flush()
return history_output_formatter(conversation=conversation, type=output_type)