-
Notifications
You must be signed in to change notification settings - Fork 576
Basic support for Local devices #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+2,780
−412
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a41681c
Local audio/video transport implementation
dangusev 00acd42
Add `vision-agents-plugins-local` to `all-plugins`
dangusev b03136e
Update uv.lock
dangusev 52ed977
Lock turbopuffer version
dangusev cd0c634
Local plugin update
dangusev 78d4a0b
Fix deepgram.STT not closing properly
dangusev d447821
LocalEdge: add docstring
dangusev 325d61a
Update local_transport_example.py
dangusev 567ed9e
Fix _FakeAudioInput in tests
dangusev ddabb6d
Fix devices tests
dangusev 409d8c6
Fix non-deterministic in tests
dangusev 4c9e487
Remove unused params
dangusev 8cf0ecb
Init tk.Root inside try-except
dangusev 5051736
Fix VideoDisplay.start() docstring
dangusev 02f97b1
Add param validation
dangusev b39f492
Improve tests
dangusev 708ded7
Use InMemoryConversation in LocalEdge
dangusev 2bf7bdb
Use deepgram.STT in local_transport_example
dangusev 139b114
Merge branch 'main' into local
dangusev f1c6f5b
Update uv.lock
dangusev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Local Transport Example | ||
|
|
||
| This example demonstrates how to run a vision agent using local audio/video I/O (microphone, speakers, and camera) instead of a cloud-based edge network. | ||
|
|
||
| ## Overview | ||
|
|
||
| The LocalEdge provides: | ||
|
|
||
| - **Microphone input**: Captures audio from your microphone | ||
| - **Speaker output**: Plays AI responses on your speakers | ||
| - **Camera input**: Captures video from your camera (optional) | ||
| - **No cloud dependencies**: Media runs locally (except for the LLM, TTS, and STT services) | ||
|
|
||
| ## Running | ||
|
|
||
| Uses Gemini LLM with Deepgram STT and TTS for a voice experience with optional camera input. | ||
|
|
||
| ```bash | ||
| uv run python local_transport_example.py | ||
| ``` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. A working microphone and speakers | ||
| 2. A camera (optional, for video input) | ||
| 3. API keys: | ||
| - Google AI (for Gemini LLM) | ||
| - Deepgram (for STT and TTS) | ||
|
|
||
| ## Setup | ||
|
|
||
| 1. Create a `.env` file with your API keys: | ||
|
|
||
| ```bash | ||
| GOOGLE_API_KEY=your_google_api_key | ||
| DEEPGRAM_API_KEY=your_deepgram_api_key | ||
| ``` | ||
|
|
||
| 2. Install dependencies: | ||
|
|
||
| ```bash | ||
| cd examples/10_local_transport_example | ||
| uv sync | ||
| ``` | ||
|
|
||
| ## Device Selection | ||
|
|
||
| The example will prompt you to select: | ||
|
|
||
| 1. **Input device** (microphone) | ||
| 2. **Output device** (speakers) | ||
| 3. **Video device** (camera) - can be skipped by entering 'n' | ||
|
|
||
| Press Enter to use the default device, or enter a number to select a specific device. | ||
|
|
||
| Press `Ctrl+C` to stop the agent. | ||
|
|
||
| ## Listing Audio Devices | ||
|
|
||
| To see available audio devices on your system: | ||
|
|
||
| ```python | ||
| from vision_agents.plugins.local.devices import list_audio_input_devices, list_audio_output_devices | ||
|
|
||
| list_audio_input_devices() | ||
| list_audio_output_devices() | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| You can customize the audio settings when creating the LocalEdge: | ||
|
|
||
| ```python | ||
| from vision_agents.plugins.local import LocalEdge | ||
| from vision_agents.plugins.local.devices import ( | ||
| select_audio_input_device, | ||
| select_audio_output_device, | ||
| ) | ||
|
|
||
| input_device = select_audio_input_device() | ||
| output_device = select_audio_output_device() | ||
|
|
||
| edge = LocalEdge( | ||
| audio_input=input_device, # AudioInputDevice (microphone) | ||
| audio_output=output_device, # AudioOutputDevice (speakers) | ||
| ) | ||
| ``` | ||
dangusev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### No audio input/output | ||
|
|
||
| 1. Check that your microphone and speakers are properly connected | ||
| 2. Run `list_audio_input_devices()` or `list_audio_output_devices()` to see available devices | ||
| 3. Try specifying explicit device indices in the LocalEdge constructor | ||
|
|
||
| ### Audio quality issues | ||
|
|
||
| - Try increasing the `blocksize` parameter for smoother audio | ||
| - Ensure your microphone isn't picking up too much background noise | ||
|
|
||
| ### Permission errors | ||
|
|
||
| On macOS, you may need to grant microphone permissions to your terminal application. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Local Transport Example |
106 changes: 106 additions & 0 deletions
106
examples/10_local_transport_example/local_transport_example.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """ | ||
| Local Transport Example | ||
| Demonstrates using LocalTransport for local audio/video I/O with vision agents. | ||
| This enables running agents using your microphone, speakers, and camera without | ||
| cloud-based edge infrastructure. | ||
| Usage: | ||
| uv run python local_transport_example.py run | ||
| Requirements: | ||
| - Working microphone and speakers | ||
| - Optional: Camera for video input | ||
| - API keys for Gemini, Deepgram, and ElevenLabs in .env file | ||
| """ | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from dotenv import load_dotenv | ||
| from vision_agents.core import Agent, AgentLauncher, Runner, User | ||
| from vision_agents.core.utils.examples import get_weather_by_location | ||
| from vision_agents.plugins import deepgram, gemini | ||
| from vision_agents.plugins.local import LocalEdge | ||
| from vision_agents.plugins.local.devices import ( | ||
| select_audio_input_device, | ||
| select_audio_output_device, | ||
| select_video_device, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| load_dotenv() | ||
|
|
||
| INSTRUCTIONS = ( | ||
| "You're a helpful voice AI assistant running on the user's local machine. " | ||
| "Keep responses short and conversational. Don't use special characters or " | ||
| "formatting. Be friendly and helpful." | ||
| ) | ||
|
|
||
|
|
||
| def setup_llm(model: str = "gemini-3.1-flash-lite-preview") -> gemini.LLM: | ||
| llm = gemini.LLM(model) | ||
|
|
||
| @llm.register_function(description="Get current weather for a location") | ||
| async def get_weather(location: str) -> dict[str, Any]: | ||
| return await get_weather_by_location(location) | ||
|
|
||
| return llm | ||
|
|
||
|
|
||
| async def create_agent() -> Agent: | ||
| llm = setup_llm() | ||
|
|
||
| if input_device is None: | ||
| raise RuntimeError("No audio input device available") | ||
| if output_device is None: | ||
| raise RuntimeError("No audio output device available") | ||
|
|
||
| logger.info(f"Using input: {input_device.name} ({input_device.sample_rate}Hz)") | ||
| logger.info(f"Using output: {output_device.name} ({output_device.sample_rate}Hz)") | ||
| if video_device: | ||
| logger.info(f"Using video device: {video_device.name}") | ||
|
|
||
| transport = LocalEdge( | ||
| audio_input=input_device, | ||
| audio_output=output_device, | ||
| video_input=video_device, | ||
| ) | ||
|
|
||
| agent = Agent( | ||
| edge=transport, | ||
| agent_user=User(name="Local AI Assistant", id="local-agent"), | ||
| instructions=INSTRUCTIONS, | ||
| processors=[], | ||
| llm=llm, | ||
| tts=deepgram.TTS(), | ||
| stt=deepgram.STT(), | ||
| ) | ||
|
|
||
| return agent | ||
|
|
||
|
|
||
| async def join_call(agent: Agent, call_type: str, call_id: str, **kwargs: Any) -> None: | ||
| call = await agent.edge.create_call(call_id) | ||
| async with agent.join(call=call, participant_wait_timeout=0): | ||
| await agent.simple_response("Greet the user briefly") | ||
| await agent.finish() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print("\n" + "=" * 60) | ||
| print("Local Transport Voice Agent") | ||
| print("=" * 60) | ||
| print("\nThis agent uses your local microphone, speakers, and optionally camera.") | ||
|
|
||
| input_device = select_audio_input_device() | ||
| output_device = select_audio_output_device() | ||
| video_device = select_video_device() | ||
|
|
||
| print("Speak into your microphone to interact with the AI.") | ||
| if video_device: | ||
| print("Camera is enabled for video input.") | ||
| print("Press Ctrl+C to stop.\n") | ||
|
|
||
| Runner(AgentLauncher(create_agent=create_agent, join_call=join_call)).cli() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [project] | ||
| name = "local-transport-example" | ||
| version = "0.0.0" | ||
| requires-python = ">=3.10" | ||
|
|
||
| # Dependencies for local audio transport | ||
| dependencies = [ | ||
| "python-dotenv>=1.0", | ||
| "vision-agents-plugins-deepgram", | ||
| "vision-agents-plugins-gemini", | ||
| "vision-agents-plugins-local", | ||
| ] | ||
|
|
||
| [tool.uv.sources] | ||
| "vision-agents-plugins-deepgram" = { path = "../../plugins/deepgram", editable = true } | ||
| "vision-agents-plugins-gemini" = { path = "../../plugins/gemini", editable = true } | ||
| "vision-agents-plugins-local" = { path = "../../plugins/local", editable = true } | ||
| "vision-agents" = { path = "../../agents-core", editable = true } |
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
Empty file.
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| [build-system] | ||
| requires = ["hatchling", "hatch-vcs"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [project] | ||
| name = "vision-agents-plugins-local" | ||
| dynamic = ["version"] | ||
| description = "Local audio & video integration for Vision Agents" | ||
| readme = "README.md" | ||
| keywords = ["local", "AI", "voice agents", "agents"] | ||
| requires-python = ">=3.10" | ||
| license = "MIT" | ||
| dependencies = [ | ||
| "vision-agents", | ||
| "sounddevice>=0.5.0", | ||
| "aiortc>=1.14.0, <1.15.0", | ||
| "av>=14.2.0, <17", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Documentation = "https://visionagents.ai/" | ||
| Website = "https://visionagents.ai/" | ||
| Source = "https://github.com/GetStream/Vision-Agents" | ||
|
|
||
| [tool.hatch.version] | ||
| source = "vcs" | ||
| raw-options = { root = "..", search_parent_directories = true, fallback_version = "0.0.0" } | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["."] | ||
|
|
||
| [tool.hatch.build.targets.sdist] | ||
| include = ["/vision_agents"] | ||
|
|
||
| [tool.uv.sources] | ||
| vision-agents = { workspace = true } | ||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "pytest>=8.4.1", | ||
| "pytest-asyncio>=1.0.0", | ||
| ] |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.