-
Notifications
You must be signed in to change notification settings - Fork 0
/
realtime_chat_demo.py
44 lines (39 loc) · 1.36 KB
/
realtime_chat_demo.py
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
from time import perf_counter
from koemotion import Koemotion
from openai import OpenAI
openai_client = OpenAI()
koemotion_client = Koemotion()
messages = [
{
"role": "system",
"content": "以降のユーザ発話に対して気の効いたリアクションや質問を一言で作成してください.絵文字や記号は含めてはいけません",
}
]
koemotion_params = {
"speaker_x": 2.0,
"speaker_y": 3.0,
"output_format": "wav",
"streaming": True,
}
while True:
messages.append({"role": "user", "content": input("User: ")})
start_time_openai = perf_counter()
response = openai_client.chat.completions.create(
model="gpt-4o",
messages=messages,
max_tokens=32,
)
end_time_openai = perf_counter()
content = response.choices[0].message.content
print("System:", content)
print(f"OpenAI API response time: {end_time_openai - start_time_openai:.3f} sec")
messages.append({"role": "system", "content": content})
koemotion_params["text"] = content
start_time_koemotion = perf_counter()
response = koemotion_client.request(koemotion_params)
end_time_koemotion = perf_counter()
print(
f"Koemotion API response time: {end_time_koemotion - start_time_koemotion:.3f} sec"
)
response.stream_audio()
response.save_audio(f"wav/{content}.wav", quiet=True)