Created
April 18, 2023 15:37
-
-
Save ploeber/54ff43e3537f3a3367d2f642328332ab to your computer and use it in GitHub Desktop.
vocode script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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