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
370
0
Share
Realtime API 入門
Kanagawa.swift #1 で発表した Realtime APIに関する入門スライドです。
RioFujimon
November 03, 2024
More Decks by RioFujimon
See All by RioFujimon
Foundation Models を 活用するための Tips
riofujimon
1
350
2025.01.17_Sansan × DMM.swift
riofujimon
3
1.1k
実践 Realtime API 〜入力として音声データを扱う〜
riofujimon
1
100
Let's learn code review
riofujimon
3
1.3k
Other Decks in Programming
See All in Programming
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
170
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
1.3k
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
280
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
280
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
450
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
230
🦞OpenClaw works with AWS
licux
1
230
AIを導入する前にやるべきこと
negima
2
230
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
250
事業会社でのセキュリティ長期インターンについて
masachikaura
0
270
NakouPAY説明用
annouim0
0
260
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
130
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
GraphQLとの向き合い方2022年版
quramy
50
15k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
How GitHub (no longer) Works
holman
316
150k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Building Adaptive Systems
keathley
44
3k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
300
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
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 参考リンク
ご清聴ありがとうございました!