Voice Agents (com.stefanwebb.voiceagents) is a Unity package for building open-source AI voice agents that run fully locally.
You can use it to build intelligent non-player characters (NPCs), voice-driven game interfaces, and more.
The package connects Unity to local speech-to-text (STT) and LLM chat servers over named pipes, and exposes everything as typed events on a lightweight event bus so your gameplay code never touches the transport.
Text-to-speech (TTS) is not yet implemented — see Limitations.
Microphone ─► named_pipes.stt server ─┐
│ /tmp/tool-stt, /tmp/tool-chat (FIFOs)
vLLM / any OpenAI-style LLM ◄─ named_pipes.chat server ─┘
▲
│ ToolClient (JSON lines)
▼
SttClient ──────► EventBus ◄────── ChatClient
▲ │
ConversationManager │ SttTranscriptionDisplay / ChatDisplay / SttStateIcon
your scripts (raise commands, subscribe to events)
| Component | Role |
|---|---|
ToolClient |
C# client for the Named Pipe Tools protocol (/tmp/tool-{name}) |
SttClient |
Connects to the stt tool; raises SpeechStartEvent, SpeechEvent, TokenEvent, StateChangedEvent, DevicesEvent…; forwards StartCommandEvent, PauseCommandEvent, SetDeviceCommandEvent…. Runs in Edit mode too, with a device dropdown in the Inspector |
ChatClient |
Connects to the chat tool; raises streaming ChatTokenEvent, ChatDoneEvent, ChatStateChangedEvent; forwards ChatCommandEvent |
ConversationManager |
Turns a ConfirmedInputEvent into a ChatCommandEvent with full history and optional system prompt |
EventBus |
Static typed event bus (built on GenericEventBus) |
SttTranscriptionDisplay, ChatDisplay, SttStateIcon |
Drop-in uGUI/TextMeshPro views |
- Unity 6000.0 or later (uses
System.Text.Json, available with the .NET Standard 2.1 profile) - macOS or Linux —
ToolClientuses POSIX FIFOs (mkfifo) vialibc - Running
sttandchattool servers from the companionnamed_pipesPython package (instructions to follow) - TextMeshPro essentials imported into your project (Window ▸ TextMeshPro ▸ Import TMP Essential Resources)
- In Unity, open Window ▸ Package Manager.
- Click + ▸ Add package from git URL… and enter:
(or Add package from disk… and pick this folder's
https://github.com/stefanwebb/unity-voice-agents.gitpackage.json). - Dependencies (
com.unity.ugui,com.unity.inputsystem,com.unity.render-pipelines.universal) are pulled in automatically. If prompted to enable the new Input System, accept and restart the Editor.
- In Package Manager select Voice Agents ▸ Samples and click Import next to Voice Agent Demo.
- Start the
sttandchatservers so/tmp/tool-sttand/tmp/tool-chatexist. - Open
Assets/Samples/Voice Agents/<version>/Voice Agent Demo/VoiceAgentDemo.unity. The sample uses URP — if your project is not on URP, assign a URP asset in Graphics settings or ignore the post-processing volume. - Select the AgentManager object: the
SttClientinspector shows the connection state and lets you pick a microphone (works without entering Play mode). Paste a system prompt intoConversationManagerif you like (SystemPrompt.Textin the sample is an example). - Press Play, press Space and speak (the game pauses while you talk; the server detects when you stop), then press Enter to send the transcription to the LLM. The reply streams into the on-screen textbox — press Enter again to dismiss it and resume. The icon shows disconnected / listening / transcribing / thinking state.
- Add
SttClient,ChatClient, andConversationManagerto a GameObject. - Raise commands and subscribe to events from any script:
using GenerativeGamedev; void OnEnable() => EventBus.SubscribeTo<ChatTokenEvent>(OnToken); void OnDisable() => EventBus.UnsubscribeFrom<ChatTokenEvent>(OnToken); void StartListening() => EventBus.Raise(new StartCommandEvent()); void Send(string text) => EventBus.Raise(new ConfirmedInputEvent { Text = text }); void OnToken(ref ChatTokenEvent e) => Debug.Log(e.Text);
- No text-to-speech yet.
- macOS/Linux only (named pipes).
- No tool calling, memory, or planning on the LLM side — the "agent" is a chat completion with a system prompt.
- Server setup and the
named_pipesPython package are documented separately.
CC BY-SA 4.0 — see LICENSE.md.