Skip to content

Commit 796aa2d

Browse files
committed
Update realtime agent guide document page
1 parent e291b10 commit 796aa2d

File tree

3 files changed

+222
-116
lines changed

3 files changed

+222
-116
lines changed

docs/ja/realtime/quickstart.md

Lines changed: 125 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ search:
44
---
55
# クイックスタート
66

7-
Realtime エージェントは、 OpenAI の Realtime API を使用して AI 音声会話を実現します。このガイドでは、最初の Realtime 音声エージェントの作成手順を説明します
7+
Realtime エージェントは、OpenAI の Realtime API を使って AI エージェントとの音声対話を可能にします。このガイドでは、最初のリアルタイム音声エージェントの作成手順を説明します
88

99
!!! warning "ベータ機能"
10-
Realtime エージェントはベータ版です。実装の改良に伴い、互換性のない変更が入る可能性があります
10+
Realtime エージェントはベータ版です。実装の改善に伴い、非互換の変更が入る可能性があります
1111

1212
## 前提条件
1313

14-
- Python 3.9 以上
15-
- OpenAI API キー
16-
- OpenAI Agents SDK の基本的な知識
14+
- Python 3.9 以上
15+
- OpenAI API キー
16+
- OpenAI Agents SDK の基本的な知識
1717

1818
## インストール
1919

20-
まだの場合は、 OpenAI Agents SDK をインストールします:
20+
まだの場合は、OpenAI Agents SDK をインストールします:
2121

2222
```bash
2323
pip install openai-agents
2424
```
2525

26-
## はじめての Realtime エージェントの作成
26+
## 最初の Realtime エージェントの作成
2727

2828
### 1. 必要なコンポーネントのインポート
2929

@@ -41,47 +41,77 @@ agent = RealtimeAgent(
4141
)
4242
```
4343

44-
### 3. Runner のセットアップ
44+
### 3. Runner をセットアップ
4545

4646
```python
4747
runner = RealtimeRunner(
4848
starting_agent=agent,
4949
config={
5050
"model_settings": {
51-
"model_name": "gpt-4o-realtime-preview",
52-
"voice": "alloy",
53-
"modalities": ["text", "audio"],
51+
"model_name": "gpt-realtime",
52+
"voice": "ash",
53+
"modalities": ["audio"],
54+
"input_audio_format": "pcm16",
55+
"output_audio_format": "pcm16",
56+
"input_audio_transcription": {"model": "gpt-4o-mini-transcribe"},
57+
"turn_detection": {"type": "semantic_vad", "interrupt_response": True},
5458
}
5559
}
5660
)
5761
```
5862

59-
### 4. セッションの開始
63+
### 4. セッションを開始
6064

6165
```python
62-
async def main():
63-
# Start the realtime session
64-
session = await runner.run()
65-
66-
async with session:
67-
# Send a text message to start the conversation
68-
await session.send_message("Hello! How are you today?")
69-
70-
# The agent will stream back audio in real-time (not shown in this example)
71-
# Listen for events from the session
72-
async for event in session:
73-
if event.type == "response.audio_transcript.done":
74-
print(f"Assistant: {event.transcript}")
75-
elif event.type == "conversation.item.input_audio_transcription.completed":
76-
print(f"User: {event.transcript}")
77-
78-
# Run the session
79-
asyncio.run(main())
66+
# Start the session
67+
session = await runner.run()
68+
69+
async with session:
70+
print("Session started! The agent will stream audio responses in real-time.")
71+
# Process events
72+
async for event in session:
73+
try:
74+
if event.type == "agent_start":
75+
print(f"Agent started: {event.agent.name}")
76+
elif event.type == "agent_end":
77+
print(f"Agent ended: {event.agent.name}")
78+
elif event.type == "handoff":
79+
print(f"Handoff from {event.from_agent.name} to {event.to_agent.name}")
80+
elif event.type == "tool_start":
81+
print(f"Tool started: {event.tool.name}")
82+
elif event.type == "tool_end":
83+
print(f"Tool ended: {event.tool.name}; output: {event.output}")
84+
elif event.type == "audio_end":
85+
print("Audio ended")
86+
elif event.type == "audio":
87+
# Enqueue audio for callback-based playback with metadata
88+
# Non-blocking put; queue is unbounded, so drops won’t occur.
89+
pass
90+
elif event.type == "audio_interrupted":
91+
print("Audio interrupted")
92+
# Begin graceful fade + flush in the audio callback and rebuild jitter buffer.
93+
elif event.type == "error":
94+
print(f"Error: {event.error}")
95+
elif event.type == "history_updated":
96+
pass # Skip these frequent events
97+
elif event.type == "history_added":
98+
pass # Skip these frequent events
99+
elif event.type == "raw_model_event":
100+
print(f"Raw model event: {_truncate_str(str(event.data), 200)}")
101+
else:
102+
print(f"Unknown event type: {event.type}")
103+
except Exception as e:
104+
print(f"Error processing event: {_truncate_str(str(e), 200)}")
105+
106+
def _truncate_str(s: str, max_length: int) -> str:
107+
if len(s) > max_length:
108+
return s[:max_length] + "..."
109+
return s
80110
```
81111

82-
## 完全なコード例
112+
## 完全な例
83113

84-
動作する完全なコード例は次のとおりです:
114+
以下は動作する完全な例です:
85115

86116
```python
87117
import asyncio
@@ -93,86 +123,109 @@ async def main():
93123
name="Assistant",
94124
instructions="You are a helpful voice assistant. Keep responses brief and conversational.",
95125
)
96-
97126
# Set up the runner with configuration
98127
runner = RealtimeRunner(
99128
starting_agent=agent,
100129
config={
101130
"model_settings": {
102-
"model_name": "gpt-4o-realtime-preview",
103-
"voice": "alloy",
104-
"modalities": ["text", "audio"],
105-
"input_audio_transcription": {
106-
"model": "whisper-1"
107-
},
108-
"turn_detection": {
109-
"type": "server_vad",
110-
"threshold": 0.5,
111-
"prefix_padding_ms": 300,
112-
"silence_duration_ms": 200
113-
}
131+
"model_name": "gpt-realtime",
132+
"voice": "ash",
133+
"modalities": ["audio"],
134+
"input_audio_format": "pcm16",
135+
"output_audio_format": "pcm16",
136+
"input_audio_transcription": {"model": "gpt-4o-mini-transcribe"},
137+
"turn_detection": {"type": "semantic_vad", "interrupt_response": True},
114138
}
115-
}
139+
},
116140
)
117-
118141
# Start the session
119142
session = await runner.run()
120143

121144
async with session:
122145
print("Session started! The agent will stream audio responses in real-time.")
123-
124146
# Process events
125147
async for event in session:
126-
if event.type == "response.audio_transcript.done":
127-
print(f"Assistant: {event.transcript}")
128-
elif event.type == "conversation.item.input_audio_transcription.completed":
129-
print(f"User: {event.transcript}")
130-
elif event.type == "error":
131-
print(f"Error: {event.error}")
132-
break
148+
try:
149+
if event.type == "agent_start":
150+
print(f"Agent started: {event.agent.name}")
151+
elif event.type == "agent_end":
152+
print(f"Agent ended: {event.agent.name}")
153+
elif event.type == "handoff":
154+
print(f"Handoff from {event.from_agent.name} to {event.to_agent.name}")
155+
elif event.type == "tool_start":
156+
print(f"Tool started: {event.tool.name}")
157+
elif event.type == "tool_end":
158+
print(f"Tool ended: {event.tool.name}; output: {event.output}")
159+
elif event.type == "audio_end":
160+
print("Audio ended")
161+
elif event.type == "audio":
162+
# Enqueue audio for callback-based playback with metadata
163+
# Non-blocking put; queue is unbounded, so drops won’t occur.
164+
pass
165+
elif event.type == "audio_interrupted":
166+
print("Audio interrupted")
167+
# Begin graceful fade + flush in the audio callback and rebuild jitter buffer.
168+
elif event.type == "error":
169+
print(f"Error: {event.error}")
170+
elif event.type == "history_updated":
171+
pass # Skip these frequent events
172+
elif event.type == "history_added":
173+
pass # Skip these frequent events
174+
elif event.type == "raw_model_event":
175+
print(f"Raw model event: {_truncate_str(str(event.data), 200)}")
176+
else:
177+
print(f"Unknown event type: {event.type}")
178+
except Exception as e:
179+
print(f"Error processing event: {_truncate_str(str(e), 200)}")
180+
181+
def _truncate_str(s: str, max_length: int) -> str:
182+
if len(s) > max_length:
183+
return s[:max_length] + "..."
184+
return s
133185

134186
if __name__ == "__main__":
187+
# Run the session
135188
asyncio.run(main())
136189
```
137190

138191
## 設定オプション
139192

140193
### モデル設定
141194

142-
- `model_name`: 利用可能な Realtime モデルから選択 (例: `gpt-4o-realtime-preview`)
143-
- `voice`: 音声の選択 (`alloy`, `echo`, `fable`, `onyx`, `nova`, `shimmer`)
144-
- `modalities`: テキストや音声の有効化 (`["text", "audio"]`)
195+
- `model_name`: 利用可能なリアルタイムモデルから選択 (例: `gpt-realtime`)
196+
- `voice`: 音声を選択 (`alloy`, `echo`, `fable`, `onyx`, `nova`, `shimmer`)
197+
- `modalities`: テキストまたは音声を有効化 (`["text"]` または `["audio"]`)
145198

146199
### オーディオ設定
147200

148-
- `input_audio_format`: 入力音声の形式 (`pcm16`, `g711_ulaw`, `g711_alaw`)
149-
- `output_audio_format`: 出力音声の形式
150-
- `input_audio_transcription`: 書き起こしの設定
201+
- `input_audio_format`: 入力音声の形式 (`pcm16`, `g711_ulaw`, `g711_alaw`)
202+
- `output_audio_format`: 出力音声の形式
203+
- `input_audio_transcription`: 文字起こしの設定
151204

152205
### ターン検出
153206

154-
- `type`: 検出方法 (`server_vad`, `semantic_vad`)
155-
- `threshold`: 音声活動の閾値 (0.0–1.0)
156-
- `silence_duration_ms`: ターン終了を検出する無音時間
157-
- `prefix_padding_ms`: 発話前の音声パディング
207+
- `type`: 検出方法 (`server_vad`, `semantic_vad`)
208+
- `threshold`: 音声アクティビティのしきい値 (0.0–1.0)
209+
- `silence_duration_ms`: ターン終了を検出する無音時間
210+
- `prefix_padding_ms`: 発話前の音声パディング
158211

159212
## 次のステップ
160213

161-
- [Realtime エージェントについて詳しく学ぶ](guide.md)
162-
- [examples/realtime](https://github.com/openai/openai-agents-python/tree/main/examples/realtime) フォルダの動作するコード例を参照
163-
- エージェントにツールを追加
164-
- エージェント間のハンドオフを実装
165-
- 安全性のためのガードレールを設定
214+
- [Realtime エージェントの詳細](guide.md)
215+
- 実行可能なサンプルは [examples/realtime](https://github.com/openai/openai-agents-python/tree/main/examples/realtime) フォルダを参照してください
216+
- エージェントにツールを追加する
217+
- エージェント間のハンドオフを実装する
218+
- 安全性のためのガードレールを設定する
166219

167220
## 認証
168221

169-
環境に OpenAI API キーが設定されていることを確認してください:
222+
OpenAI API キーが環境に設定されていることを確認してください:
170223

171224
```bash
172225
export OPENAI_API_KEY="your-api-key-here"
173226
```
174227

175-
また、セッション作成時に直接渡すこともできます:
228+
または、セッション作成時に直接渡します:
176229

177230
```python
178231
session = await runner.run(model_config={"api_key": "your-api-key"})

0 commit comments

Comments
 (0)