-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemini.py
More file actions
77 lines (58 loc) · 1.97 KB
/
gemini.py
File metadata and controls
77 lines (58 loc) · 1.97 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
from __future__ import annotations
from logging import StreamHandler, getLogger
from dotenv import load_dotenv
from google import genai
from google.genai import types
from stackchan_server.app import StackChanApp
from stackchan_server.ws_proxy import (
EmptyTranscriptError,
ServoMoveType,
ServoWaitType,
WsProxy,
)
logger = getLogger(__name__)
logger.addHandler(StreamHandler())
logger.setLevel("DEBUG")
load_dotenv()
app = StackChanApp()
client = genai.Client(vertexai=True).aio
@app.setup
async def setup(proxy: WsProxy):
logger.info("WebSocket connected")
@app.talk_session
async def talk_session(proxy: WsProxy):
chat = client.chats.create(
model="gemini-3-flash-preview",
config=types.GenerateContentConfig(
system_instruction="あなたは親切な音声アシスタントです。音声で返答するため、マークダウンは記述せず、簡潔に答えてください。だいたい3文程度で答えてください。",
),
)
while True:
# listening pose
await proxy.move_servo([(ServoMoveType.MOVE_Y, 80, 100)])
try:
# voice recognition
text = await proxy.listen()
except EmptyTranscriptError:
# off pose
await proxy.move_servo([(ServoMoveType.MOVE_Y, 90, 100)])
return
# nod pose
await proxy.move_servo(
[
(ServoMoveType.MOVE_Y, 100, 100),
(ServoWaitType.SLEEP, 200),
(ServoMoveType.MOVE_Y, 90, 100),
(ServoWaitType.SLEEP, 200),
(ServoMoveType.MOVE_Y, 100, 100),
(ServoWaitType.SLEEP, 200),
(ServoMoveType.MOVE_Y, 90, 100),
]
)
logger.info("Human: %s", text)
# generate response
resp = await chat.send_message(text)
# speaking
logger.info("AI: %s", resp.text)
if resp.text:
await proxy.speak(resp.text)