-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_custom_usage.py
More file actions
167 lines (131 loc) · 4.45 KB
/
Copy pathexample_custom_usage.py
File metadata and controls
167 lines (131 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
"""
Example of how to use the voice chat library programmatically
with custom configurations
"""
import asyncio
from config import create_config
from voice_chat import VoiceChat
async def example_basic_conversation():
"""
Basic example: Simple conversation with default settings
"""
print("\n" + "="*60)
print("Example 1: Basic Conversation")
print("="*60)
# Create configuration
config = create_config(
jetson_ip="192.168.1.100", # Replace with your Jetson IP
ollama_model="llama3.2:3b"
)
# Create voice chat instance
chat = VoiceChat(config)
# Run the conversation
await chat.run()
async def example_custom_personality():
"""
Example: Chatbot with custom personality
"""
print("\n" + "="*60)
print("Example 2: Custom Personality")
print("="*60)
# Create configuration with custom system prompt
config = create_config(
jetson_ip="192.168.1.100", # Replace with your Jetson IP
system_prompt=(
"You are a friendly tech support assistant who loves to help people "
"with their computer problems. You explain things in simple terms and "
"always ask if the user needs clarification. Keep responses brief."
),
ollama_model="llama3.2:3b"
)
chat = VoiceChat(config)
await chat.run()
async def example_sensitive_detection():
"""
Example: Adjusted for sensitive microphone (picks up background noise)
"""
print("\n" + "="*60)
print("Example 3: Sensitive Microphone Settings")
print("="*60)
# Increase thresholds for noisy environment
config = create_config(
jetson_ip="192.168.1.100", # Replace with your Jetson IP
silence_threshold=800.0, # Higher threshold
silence_duration=2.0, # Longer wait time
ollama_model="llama3.2:3b"
)
chat = VoiceChat(config)
await chat.run()
async def example_streaming_mode():
"""
Example: Streaming mode to see LLM thinking in real-time
"""
print("\n" + "="*60)
print("Example 4: Streaming Mode")
print("="*60)
config = create_config(
jetson_ip="192.168.1.100", # Replace with your Jetson IP
ollama_model="llama3.2:3b"
)
chat = VoiceChat(config)
await chat.run_with_streaming()
async def example_manual_control():
"""
Example: Manual control over conversation flow
(e.g., for integration with other systems)
"""
print("\n" + "="*60)
print("Example 5: Manual Control")
print("="*60)
config = create_config(
jetson_ip="192.168.1.100", # Replace with your Jetson IP
ollama_model="llama3.2:3b"
)
chat = VoiceChat(config)
try:
# Connect to services
await chat.connect()
# Have 3 conversation turns
for turn in range(3):
print(f"\n--- Turn {turn + 1} ---")
should_continue = await chat.process_turn()
if not should_continue:
break
print("\n--- Conversation complete ---")
finally:
# Always disconnect
await chat.disconnect()
async def example_different_model():
"""
Example: Using a different (smaller/faster) model
"""
print("\n" + "="*60)
print("Example 6: Using Smaller Model for Speed")
print("="*60)
# Use smaller 1B model for faster responses
config = create_config(
jetson_ip="192.168.1.100", # Replace with your Jetson IP
ollama_model="llama3.2:1b" # Smaller, faster model
)
chat = VoiceChat(config)
await chat.run()
def main():
"""
Main function - uncomment the example you want to run
"""
print("\n🎯 Voice Chat Library - Usage Examples\n")
print("Edit example_custom_usage.py to run different examples")
print("Make sure to replace '192.168.1.100' with your Jetson IP!\n")
# Uncomment ONE of the following lines to run that example:
# asyncio.run(example_basic_conversation())
# asyncio.run(example_custom_personality())
# asyncio.run(example_sensitive_detection())
# asyncio.run(example_streaming_mode())
# asyncio.run(example_manual_control())
# asyncio.run(example_different_model())
print("\n💡 Tip: Uncomment one of the example functions in main() to run it")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\nExiting...")