Companion Setup

In the Companion run type, one user at the microphone talks 1:1 with one character. The character hears the user through speech recognition (STT) and answers. It can also look at the screen or a webcam image. Live chat, co-streaming, and topics are not used. For a stream that reacts to viewer chat, see BROADCAST.md.

The sample map /CBMKit/Samples/Maps/CBM_CompanionLevel is set up for this run type.

1. Set the run type to Companion

Method Value
Editor menu Tools > CBM > Run Type > Companion. This writes only RunType to your project's Config/DefaultGame.ini
Project Settings Plugins > CBM > Services > Run Type = Companion
Command line -CBMRunType=companion. Overrides the Project Settings value
While running Console CBMKit.RunType companion, the Run Type selector in the Developer Panel, or /api/runtype?value=companion

In a packaged game, a run type changed while running is saved to the user's Saved/Config/Windows/Game.ini.

Switching to Companion changes the following:

The web control server listens on http://127.0.0.1:18050 by default (ControlPort). If ControlToken is set, add token=<value> to every request.

2. In-game settings window

In the Companion run type, a semi-transparent gear button appears in the top-right corner of the game viewport. The user opens the settings window with this button and changes their name, character language, microphone, and vision input. If WebcamPreviewCorner is Top Right, the gear button moves to the top-left corner. In the Broadcast run type, the button and window do not appear.

2.1 Open and close

Action Result
Click the gear button Opens or closes the settings window
CompanionSettingsKey (default F10) Opens or closes the settings window. Works only when the game window is the active window. In editor PIE, works only when the game viewport has keyboard focus
Esc Closes the settings window only when it is open. When the window is closed, Esc goes to the game as usual
Close button in the window Closes the settings window
Blueprint CBMCompanionUISubsystem > SetSettingsWindowOpen, IsSettingsWindowOpen

If the player controller hides the mouse cursor, the cursor is shown while the settings window is open. When the window closes, the previous cursor visibility and mouse capture state are restored. In a game that hides the cursor, the gear button cannot be clicked, so open the window with F10.

2.2 Items

Item Behavior
Your Name Type a name and press Save or Enter. Same as SetCompanionUserName. See section 6
Character Language The language the character speaks. Same as SetCharacterLanguage. Disabled when the active character definition sets its own Language
Use Microphone On opens the microphone. Off closes it. Same as SetVoiceInputEnabled
Vision Input One of None, Game Viewport, Monitor, Window, Webcam. Same as SetVisionSource. Monitor uses the monitor at VisionMonitorIndex
Window list (Pick a window) Shown when Vision Input is Window. Pick the title of a window from another program that is visible on screen. Minimized windows, tool windows, and this game's windows are not listed. The list is read again when you open it and when you press Refresh. Same as SetVisionWindowTitle
Show Camera on Screen Shown when Vision Input is Webcam. Turns the camera image in the corner of the game viewport on and off. Same as SetWebcamPreviewVisible

If Vision Input is set to anything other than None and no image input (mmproj) model is installed, the window shows "No vision model, so images cannot be seen". See section 4 to install the model.

2.3 Saving

Environment What is saved
Packaged game Each change to Use Microphone, Vision Input, the window title, and Show Camera on Screen is saved to bEnableVoiceInput, VisionSource, VisionWindowTitle, and bShowWebcamPreview in the [/Script/CBMKit.CBMSettings] section of the user's Saved/Config/Windows/Game.ini. The next run starts with these values
Editor (PIE, or -game with the editor binary) Not saved. Saving in the editor would make Saved/Config/WindowsEditor/Game.ini override your Config/DefaultGame.ini. When the game restarts, the Project Settings values are used again

Your Name is saved in both environments (section 6). Character Language is saved to PromptLanguage: in the editor to Config/DefaultGame.ini, in a packaged game to the user's Saved/Config/Windows/Game.ini.

In the editor, if bShowWebcamPreview is off in Project Settings, the camera image does not appear even when Show Camera on Screen is on. In a packaged game, the checkbox also changes bShowWebcamPreview.

2.4 Settings (Project Settings > Plugins > CBM > Companion)

Setting Default Meaning
bShowCompanionSettings On Shows the gear button and settings window in the game viewport
CompanionSettingsKey F10 Key that opens and closes the settings window. Empty = no key; the window opens only with the gear button

Turn bShowCompanionSettings off to build your own settings UI for your game. Then call these Blueprint functions:

Item Blueprint
Your Name CBMConversationSubsystem > SetCompanionUserName, GetCompanionUserName
Character Language CBMConversationSubsystem > SetCharacterLanguage, GetCharacterLanguage
Microphone CBMVoiceInputSubsystem > SetVoiceInputEnabled, IsVoiceInputEnabled, SetPushToTalk, SetPushToTalkPressed
Vision Input CBMConversationSubsystem > SetVisionSource, GetVisionSource, SetVisionWindowTitle, GetVisionWindowTitle
Camera image CBMConversationSubsystem > SetWebcamPreviewVisible, IsWebcamPreviewVisible

Except for the name and character language, these functions do not save their values. To keep values until the next run from your own UI, save them in your game.

2.5 Settings window, Operator Panel, and Developer Panel

Window Use
In-game settings window Settings for the Companion user
Operator Panel (console CBMKit.Operator) Window for the stream operator in the Broadcast run type
Developer Panel (Tools > CBM > Developer Panel, console CBMKit.DevPanel) Window for developers to view service state, metrics, and conversation history

3. Microphone and STT

3.1 STT model

STT runs whisper.cpp inside the Unreal process (STTBackend = InProcess, the default). Tools > CBM > Install/Repair Local AI… downloads the model for your hardware profile to <LocalAIRoot>/models/whisper. To use an external STT API, open Tools > CBM > AI Connections… and set Speech Recognition (STT) to External API. This entry can be edited only in the Companion run type.

3.2 Settings (Project Settings > Plugins > CBM > STT)

Setting Default Meaning
bEnableVoiceInput On Opens the microphone when the game starts. When off, open it while running with Use Microphone in the settings window, the Microphone toggle in the Developer Panel, or /api/mic?on=1
STTLanguage (empty) Language to transcribe. Empty = the character definition's Language, then Character Language (PromptLanguage), then the UI language
MicDeviceFilter (empty) Text contained in the recording device name. Example: USB. Empty = the Windows default recording device
VADStartThresholdDb -38 Sound louder than this level (dBFS) starts an utterance. When background noise is louder, the threshold is raised to the noise level plus a margin
VADEndSilenceSeconds 0.6 After this many seconds of quiet, the utterance ends and is sent to STT
VADMinSpeechSeconds 0.3 Sounds shorter than this are dropped
VADMaxUtteranceSeconds 15 An utterance that reaches this length is cut and sent to STT
bMuteMicWhileSpeaking On Drops microphone input while the character speaks

Notes:

To list microphone devices, call CBMVoiceInputSubsystem > GetCaptureDeviceNames in Blueprint. After changing the device, call RestartCapture.

3.3 Push-to-talk

The default mode detects speech by volume (VAD). In push-to-talk mode, the microphone records only while the button is held.

Method Mode on / press / release
Web control, Stream Deck /api/ptt?mode=1 turns the mode on (mode=0 off). /api/ptt?down=1 press, /api/ptt?down=0 release
Blueprint CBMVoiceInputSubsystem > SetPushToTalk, SetPushToTalkPressed

In push-to-talk mode, bMuteMicWhileSpeaking does not apply. Pressing the button while the character speaks records. After release, a recording shorter than VADMinSpeechSeconds is dropped.

/api/mic, /api/ptt, and /api/username return {"ok":false,"error":"companion only"} in the Broadcast run type.

3.4 OBS overlay for recognized speech

The browser-source overlay http://127.0.0.1:18050/overlay/voice shows the last sentence recognized from the microphone, with a name line above it. The background is transparent. Details on adding overlays to OBS are in BROADCAST.md.

Query value Default Meaning
size 36 Font size (px)
color #b0e7ff Text color
outline #000000 Outline color
label (empty) Name line text. Empty = the user name (section 6), then You
name (shown) name=0 hides the name line
hold 6 Seconds to show the sentence
align left left, center, or right
token (empty) Needed when ControlToken is set

Example: http://127.0.0.1:18050/overlay/voice?size=40&hold=6&align=left

4. Screen and webcam input (Vision)

To answer about the screen or a webcam image, the character needs an image input model (mmproj). In Tools > CBM > Install/Repair Local AI…, keep Image Input (VLM) Model checked (on by default) and press Install. You can also run setup\setup.ps1 -Vision in <LocalAIRoot>. The mmproj for the E4B model uses about 1.2 GB more VRAM.

4.1 Settings (Project Settings > Plugins > CBM > Vision)

Setting Default Meaning
VisionSource None Image attached to a turn. None (no image), GameViewport (game screen), Desktop (whole monitor), Window (one window), Webcam
VisionWindowTitle (empty) For Window: text contained in the window title
VisionMonitorIndex 0 For Desktop: monitor number. 0 = primary monitor
VisionWebcamFilter (empty) For Webcam: text contained in the camera name. Empty = first camera
bVisionOnVoice On Attach the image to the user's voice turns
bVisionOnChat Off Attach the image to chat turns. Companion has no chat input
bVisionOnIdleTalk On Attach the image to idle talk turns. Not attached when the source is Webcam
VisionMaxImageSize 768 Long side of the sent image (px). 128 to 1536
bShowWebcamPreview On For Webcam: show a small camera image in a corner of the game viewport
WebcamPreviewCorner Bottom Right Corner for the camera image: Top Left, Top Right, Bottom Left, Bottom Right
WebcamPreviewWidth 240 Width of the camera image in the game viewport (px). 120 to 640

Webcam is for Companion only. In the Broadcast run type, only the screen sources (GameViewport, Desktop, Window) can be used.

In Companion, when VisionSource is Webcam and bShowWebcamPreview is on, the camera image appears in the WebcamPreviewCorner corner of the game viewport. While running, turn it on and off with Show Camera on Screen in the settings window (section 2).

4.2 Change while running

Call /api/vision?value= with one of none, viewport, desktop, window, webcam. The current value is in the vision field of /api/status.

5. Memory file

When bEnableMemory (default on) is on, the conversation is stored in a SQLite file, and what the character remembers is added to later turns. Companion and Broadcast use separate memory files.

Run type File
Companion <YourProject>/Saved/CBMKit/memory_companion.db
Broadcast <YourProject>/Saved/CBMKit/memory_broadcast.db

If you set a path in MemoryDatabase, _companion or _broadcast is added to that file name. Example: D:/cbm/talk.db becomes D:/cbm/talk_companion.db. To erase the memory, close the game and delete the file.

6. User name

The name the character calls the user. Used only in the Companion run type. When empty, the character does not use a name.

Method Value
Settings window (section 2) Type in Your Name and press Save or Enter
Web control /api/username?value=<name>. An empty value clears the name
Console CBMKit.UserName <name>. No argument clears the name
Blueprint CBMConversationSubsystem > SetCompanionUserName, GetCompanionUserName

7. Prompts

Prompts are read from <LocalAIRoot>/prompts/<lang>/.... In the Companion run type, if a file with the same relative path exists under prompts/<lang>/companion/, that file is read first. Otherwise the file in prompts/<lang>/ is read. Files that exist only under companion/ are used only in Companion. Broadcast uses prompts/<lang>/broadcast/ the same way.

Example: if prompts/en/companion/rules.txt exists, Companion uses it instead of prompts/en/rules.txt.

To edit files per run type, open Tools > CBM > Prompt Editor… and choose Common, Companion, or Broadcast.

8. Troubleshooting

Symptom Check Fix
No answer when talking /api/status shows runType = broadcast, or mic = false Switch the run type to Companion and call /api/mic?on=1
No answer, microphone is on Blueprint GetInputLevelDb stays below -38 while you talk Raise the Windows microphone input volume, or lower VADStartThresholdDb
Wrong microphone is used Blueprint GetCaptureDeviceName result Put part of the device name in MicDeviceFilter, then call RestartCapture or restart the game
Reacts to background sound Blueprint GetInputLevelDb value Raise VADStartThresholdDb (for example -30) or use push-to-talk
Cuts off before you finish Your pauses are longer than 0.6 seconds Set VADEndSilenceSeconds to 0.8 to 1.0
Transcribes the character's own voice Speakers in use and bMuteMicWhileSpeaking off Turn bMuteMicWhileSpeaking on, or use headphones
Does not see images No mmproj file in <LocalAIRoot>/models/llm/vision In Install/Repair Local AI, check Image Input (VLM) Model and install again
/api/vision?value=webcam returns companion only Run type is Broadcast Switch to Companion, then set it again