Skip to content

πŸ€– Build voice-based LLM agents. Modular + open source.

License

Notifications You must be signed in to change notification settings

speaksage/vocode-python

Β 
Β 

Repository files navigation

SpeakSage set up

Set up a virtual env

pyenv activate vocodeenv
pyenv deactivate

Copy the .env.template and add in your own API keys for Deepgram and Eleven Labs Make sure this new .env file is in apps/client_backend/.env

Run the backend

There are two ways to run the BE server:

  1. In Docker
# from vocode-python dir (not /apps/client-backend)
make build-dev # build for development
make run-dev # build and run for development
make deploy # deploy to Docker Hub repo

Be sure to get Docker permissions before doing the last step.

  1. Natively with poetry:
cd apps/client_backend
poetry run uvicorn main:app --host 0.0.0.0 --port 8080

If you make edits to the vocode app outside the client_backend dir, then run poetry install to rebuild the dependency from local. If you get a warning that the poetry.lock file is not consistent with pyproject.toml, run

poetry lock --no-update
poetry install

and you should see the vocode dependency getting updated.

Β  vocode

Build voice-based LLM apps in minutes

Vocode is an open source library that makes it easy to build voice-based LLM apps. Using Vocode, you can build real-time streaming conversations with LLMs and deploy them to phone calls, Zoom meetings, and more. You can also build personal assistants or apps like voice-based chess. Vocode provides easy abstractions and integrations so that everything you need is in a single library.

We're actively looking for community maintainers, so please reach out if interested!

⭐️ Features

Check out our React SDK here!

πŸ«‚ Contribution and Roadmap

We're an open source project and are extremely open to contributors adding new features, integrations, and documentation! Please don't hesitate to reach out and get started building with us.

For more information on contributing, see our Contribution Guide.

And check out our Roadmap.

We'd love to talk to you on Discord about new ideas and contributing!

πŸš€ Quickstart

pip install 'vocode'
import asyncio
import logging
import signal
from vocode.streaming.streaming_conversation import StreamingConversation
from vocode.helpers import create_streaming_microphone_input_and_speaker_output
from vocode.streaming.transcriber import *
from vocode.streaming.agent import *
from vocode.streaming.synthesizer import *
from vocode.streaming.models.transcriber import *
from vocode.streaming.models.agent import *
from vocode.streaming.models.synthesizer import *
from vocode.streaming.models.message import BaseMessage
import vocode

# these can also be set as environment variables
vocode.setenv(
    OPENAI_API_KEY="<your OpenAI key>",
    DEEPGRAM_API_KEY="<your Deepgram key>",
    AZURE_SPEECH_KEY="<your Azure key>",
    AZURE_SPEECH_REGION="<your Azure region>",
)


logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


async def main():
    (
        microphone_input,
        speaker_output,
    ) = create_streaming_microphone_input_and_speaker_output(
        use_default_devices=False,
        logger=logger,
        use_blocking_speaker_output=True
    )

    conversation = StreamingConversation(
        output_device=speaker_output,
        transcriber=DeepgramTranscriber(
            DeepgramTranscriberConfig.from_input_device(
                microphone_input,
                endpointing_config=PunctuationEndpointingConfig(),
            )
        ),
        agent=ChatGPTAgent(
            ChatGPTAgentConfig(
                initial_message=BaseMessage(text="What up"),
                prompt_preamble="""The AI is having a pleasant conversation about life""",
            )
        ),
        synthesizer=AzureSynthesizer(
            AzureSynthesizerConfig.from_output_device(speaker_output)
        ),
        logger=logger,
    )
    await conversation.start()
    print("Conversation started, press Ctrl+C to end")
    signal.signal(
        signal.SIGINT, lambda _0, _1: asyncio.create_task(conversation.terminate())
    )
    while conversation.is_active():
        chunk = await microphone_input.get_audio()
        conversation.receive_audio(chunk)


if __name__ == "__main__":
    asyncio.run(main())

πŸ“ž Phone call quickstarts

🌱 Documentation

docs.vocode.dev

About

πŸ€– Build voice-based LLM agents. Modular + open source.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.1%
  • Other 0.9%