Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Realtime API 入門
Search
RioFujimon
November 03, 2024
Programming
0
310
Realtime API 入門
Kanagawa.swift #1 で発表した Realtime APIに関する入門スライドです。
RioFujimon
November 03, 2024
Tweet
Share
More Decks by RioFujimon
See All by RioFujimon
2025.01.17_Sansan × DMM.swift
riofujimon
3
800
実践 Realtime API 〜入力として音声データを扱う〜
riofujimon
1
80
Let's learn code review
riofujimon
3
1.1k
Other Decks in Programming
See All in Programming
データベースコネクションプール(DBCP)の変遷と理解
fujikawa8
1
250
2度もゼロから書き直して、やっとブラウザでぬるぬる動くAIに辿り着いた話
tomoino
0
160
UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ
shimomura
1
540
Practical Tips and Tricks for Working with Compose Multiplatform Previews (mDevCamp 2025)
stewemetal
0
120
社内での開発コミュニティ活動とモジュラーモノリス標準化事例のご紹介/xPalette and Introduction of Modular monolith standardization
m4maruyama
1
120
生成AIで日々のエラー調査を進めたい
yuyaabo
0
560
技術懸念に立ち向かい 法改正を穏便に乗り切った話
pop_cashew
0
1.4k
CSC307 Lecture 17
javiergs
PRO
0
110
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
1.9k
C++20 射影変換
faithandbrave
0
450
イベントストーミングから始めるドメイン駆動設計
jgeem
4
830
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
250
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
480
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
The Language of Interfaces
destraynor
158
25k
4 Signs Your Business is Dying
shpigford
184
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
910
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
43
2.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Transcript
Realtime API 入門 藤門 莉生(Rio Fujimon)
自己紹介 藤門 莉生(Rio Fujimon) - Sansan株式会社 - 23卒(新卒2年目) - Eight
の iOSアプリを開発 - X(旧 Twitter):@RioFujimon - iOS開発で主に興味がある領域 - UIKit, SwiftUI - Bluetooth, NFC, Audio, etc
None
Realtime API 紹介文 開発者はアプリケーションに 高速な音声合成体験 を組み込めるようになった
Realtime API 登場以前の手法 Whisper 音声を テキストに 書き起こす テキスト 解析モデル 目的の
応答を生成
Realtime API 登場以前の問題 Whisper 音声を テキストに 書き起こす テキスト 解析モデル 目的の
応答を生成 プロセス全体で感情やアクセントが失われたり、遅延が発生
Realtime API を利用した場合 Whisper 音声を テキストに 書き起こす テキスト 解析モデル 目的の
応答を生成 Realtime API
実装を見ていく
まずはRealtime API のチュートリアル 🔰
公式のドキュメントは JavaScript の例しか載ってない 😭 https://platform.openai.com/docs/ guides/realtime#overview 自力で読み解いて Swift で書き直す or
AIツールを利用して Swiftで書き直す
💡 要点 ・URLSessionWebSocketDelegate を利用 ・urlSession(_, webSocketTask:, didOpenWithProtocol:) で以下を記述 ・URLSessionWebSocketTask.Messageを作成 ・URLSessionWebSocketTask
の send()で送信 ・receiveMessage() でWebSocketを利用したデータ受信
💡 要点 ・URLSessionWebSocketTask の receive() で受信 ・URLSessionWebSocketTask.Message として取得 ・.string(String) と
.data(Data) で取得可能
None
実行してみる ▶
None
None
None
😵 様々な形式の JSONデータが返却されてよく分からん
🖐 JSONの重要な部分を見てみる
JSONデータを1行取り出してみる 👀 - type: response.text.delta - delta: 【差分のテキスト文】
別なJSONデータを1行取り出してみる 👀 - type: response.text.done - text: 【テキストの完全文】
💡 要点 ・JSON から type を取得 ・type で場合分けを実施 ・response.text.delta の場合、
delta を取得して表示 ・response.text.done の text を取得して表示
None
🗣 会話の内容を変更する
💡 要点 ・type を指定することで Client からのイベントが変更可能 ・type の種類 ・conversation.item.create の場合、会話内容を追加
・response.create の場合、レスポンスの生成 を指示
会話・質問の内容を変えることに成功 🎉
テキストは、無事に扱えるようになった 🎉
音声データはどう取得するの? 🧐
💡 要点 ・modalities に audio を指定
JSONデータを1行取り出してみる 👀 - type: response.audio.delta - delta: 【base64エンコードされた逐次の音声データ】
別なJSONデータを1行取り出してみる 👀 - type: response.audio_transcript.delta - delta: 【トランスクリプトの差分】
別なJSONデータを1行取り出してみる 👀 - type: response.audio_transcript.done - transcript: 【トランスクリプトの完全文】
💡 要点 ・JSON から type を取得 ・type で場合分けを実施 ・response.audio.delta の場合、
delta を表示 ・response.audio_transcript.delta の delta を表示 ・response.audio_transcript.done の transcript を表示
音声データの取得が行えるようになった 🎉
本日話した内容 目的の 応答を生成 Realtime API
残っている内容 目的の 応答を生成 Realtime API AVFoundation(AVAudioEngine, AVAudioSession)で扱う
AVFoundationの 部分をお話する予定 ご参加 お待ちしてます 🙏 connpassのリンクは こちら
【参考】 Realtime API のライブラリも 開発されているみたい https://github.com/m1guelp f/swift-realtime-openai
- https://openai.com/index/introducing-the-realtime-api/ - https://platform.openai.com/docs/guides/realtime?text-generation-quickstart-e xample=stream - https://platform.openai.com/docs/api-reference/realtime-client-events - https://platform.openai.com/docs/api-reference/realtime-server-events -
https://openai.com/brand/ - https://developer.apple.com/documentation/foundation/urlsessionwebsocketd elegate - https://developer.apple.com/documentation/foundation/urlsessionwebsocketta sk - https://github.com/m1guelpf/swift-realtime-openai 参考リンク
ご清聴ありがとうございました!