Skip to content

Instantly share code, notes, and snippets.

@Overdrive141
Forked from ploeber/main.py
Created April 19, 2023 09:43
Show Gist options
  • Save Overdrive141/0d1ca134078c4d97fa2ca5ecbb8c61ce to your computer and use it in GitHub Desktop.
Save Overdrive141/0d1ca134078c4d97fa2ca5ecbb8c61ce to your computer and use it in GitHub Desktop.
vocode script
import asyncio
import signal
import vocode
from vocode.streaming.streaming_conversation import StreamingConversation
from vocode.helpers import create_microphone_input_and_speaker_output
# Transcriber
from vocode.streaming.models.transcriber import AssemblyAITranscriberConfig
from vocode.streaming.transcriber.assemblyai_transcriber import AssemblyAITranscriber
# Agent
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
from vocode.streaming.models.agent import ChatGPTAgentConfig
from vocode.streaming.models.message import BaseMessage
# Synthesizer
from vocode.streaming.models.synthesizer import AzureSynthesizerConfig
from vocode.streaming.synthesizer.azure_synthesizer import AzureSynthesizer
vocode.setenv(
OPENAI_API_KEY="<your OpenAI key>",
ASSEMBLY_AI_API_KEY="<your AseemblyAI key>",
AZURE_SPEECH_KEY="<your Azure key>",
AZURE_SPEECH_REGION="<your Azure region>",
)
async def main():
microphone_input, speaker_output = create_microphone_input_and_speaker_output(
streaming=True, use_default_devices=False
)
conversation = StreamingConversation(
output_device=speaker_output,
transcriber=AssemblyAITranscriber(
AssemblyAITranscriberConfig.from_input_device(
microphone_input
)
),
agent=ChatGPTAgent(
ChatGPTAgentConfig(
initial_message=BaseMessage(text="Hello!"),
prompt_preamble="Have a pleasant conversation about life",
),
),
synthesizer=AzureSynthesizer(
AzureSynthesizerConfig.from_output_device(speaker_output)
),
)
await conversation.start()
print("Conversation started, press Ctrl+C to end")
signal.signal(signal.SIGINT, lambda _0, _1: conversation.terminate())
while conversation.is_active():
chunk = microphone_input.get_audio()
if chunk:
conversation.receive_audio(chunk)
await asyncio.sleep(0)
if __name__ == "__main__":
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment