メインコンテンツまでスキップ

同時通訳

長時間実行する音声同時通訳セッションを開始し、原文、訳文、任意の TTS 音声、イベント、最終レポートを逐次受け取ります。

SimultaneousInterpretationEventType のライフサイクルと onEvent での扱いは、AI セッションイベントを参照してください。

Animated workflow

同時通訳セッションのライフサイクル

プロバイダーの開始、使用中の音声入力、逐次結果の並び順、中断処理、最終停止を一連の流れとして管理します。

ホストアプリ

言語を設定

対応する元言語と対象言語に加え、TTS と再生オプションを設定します。

AI サービス

セッションを開始

プロバイダーを利用する同時通訳サービスを開始します。

ホストアプリ

セッションを保持

返されたセッションを保持し、AIBuds AI SDK の内部録音を使用するか確認します。

ホストアプリ + デバイス

音声を入力

SDK 内部録音を無効にした場合は、外部 PCM をセッションへ渡します。デバイス録音も入力元の一つです。

AI サービス → アプリ

結果を逐次受信

確定した原文と訳文を順序どおりに並べ、任意の TTS 音声を処理します。

逐次結果
ホストアプリ

実行時イベントを処理

イベント、回復可能な例外、中断による停止を処理します。

デバイス

外部音声を停止

デバイス録音中の場合は、同時通訳より先に停止します。

AI サービス

同時通訳を停止

現在の同時通訳セッションへ停止を要求します。

終了コールバック

セッションを終了

任意のレポートを処理し、保持していたセッションを破棄します。

回復可能な onException が呼ばれても、セッションが自動的に停止したとは限りません。

前提条件

  • AIBudsAISDK が初期化済みで、登録済みプロバイダーの選択と認証が完了していること。
  • プロバイダーが SimultaneousInterpretationServiceAPI に対応していること。
  • 元言語と対象言語には異なる値を指定し、ハイフン区切りの言語 ID を使用すること。
  • AIBuds AI SDK の内部録音を無効にする場合は、ホストアプリから外部 PCM を入力すること。接続中のデバイスを入力元にする場合、そのデバイスが DeviceAudioRecordingAPI に準拠していること。

AI を活用して実装

AI で実装

AI でこのワークフローを実装

公式の「AIBuds 同時通訳の実装」スキルを使い、アプリに合わせて実装します。

https://docs-aibuds.github.io/ja/skills/implement-aibuds-simultaneous-interpretation を読み、その指示に従ってください。このスキルで「AIBuds 同時通訳の実装」をこの iOS プロジェクトに実装し、検証してください。
公式スキルを見る

API リファレンス

フレームワーク

AIBudsAI.xcframework

インポート

Swift
import AIBuds
import AIBudsAI
import AIBudsAIFoundation

宣言

Swift
/// Starts a simultaneous interpretation session.
/// - Parameters:
///   - config: The session configuration.
///   - onStartSuccess: Called with the started session.
///   - onStartFailure: Called when the session cannot start.
///   - onStopByInterruption: Called when an interruption stops the session.
///   - onException: Called for a recoverable session exception. The app decides
///     whether the session should stop.
///   - streamResultHandler: Called with incremental interpretation results.
///   - onEvent: Called for session-level events.
///   - onFinish: Called with the optional final report.
public static func startSimultaneousInterpretation(_ config: SimultaneousInterpretationConfig = .default,
                                             onStartSuccess: ((_ session: SimultaneousInterpretationSessionConvertible) -> Void)? = nil,
                                             onStartFailure: ((_ error: NSError) -> Void)? = nil,
                                       onStopByInterruption: ((_ error: NSError?) -> Void)? = nil,
                                                onException: ((_ error: NSError) -> Void)? = nil,
                                        streamResultHandler: ((
                                            _ isFinal: Bool,
                                            _ response: SimultaneousInterpretationDataModel?,
                                            _ error: Error?
                                        ) -> Void)? = nil,
                                                    onEvent: ((_ event: SimultaneousInterpretationEventModel) -> Void)? = nil,
                                                   onFinish: ((_ report: SimultaneousInterpretationReportModel?) -> Void)? = nil)

/// Stops the current simultaneous interpretation session.
public static func stopSimultaneousInterpretation()

startSimultaneousInterpretationstopSimultaneousInterpretation を参照してください。

設定

SimultaneousInterpretationConfig では次の項目を設定できます。

プロパティ既定値説明
sourceLanguageアプリの表示言語任意の元言語。空文字列にすると自動判定が有効になります。
targetLanguageen-US必須の対象言語。
enableTTStrue訳文の音声を合成するかどうか。
enableVoicePlaybacktrue合成音声を再生するかどうか。
usesInternalAudioRecordingtrueAIBuds AI SDK の内部録音を使用するかどうか。
preferSpeakerOutputfalseスピーカー出力を優先するかどうか。

usesInternalAudioRecordingfalse の場合、AIBuds AI SDK はセッションの音声を録音しません。ホストアプリで返されたセッションを保持し、appendInt16PCM(_:isFinal:) または appendAudioPCMBuffer(_:isFinal:) を使って外部 PCM を入力してください。

使用例

Swift
let config = SimultaneousInterpretationConfig.default
config.sourceLanguage = "zh-CN"
config.targetLanguage = "en-US"
config.usesInternalAudioRecording = true
config.preferSpeakerOutput = false

AIBudsAISDK.startSimultaneousInterpretation(
    config,
    onStartSuccess: { session in
        currentSession = session
    },
    onStartFailure: { error in
        print("Unable to start: \(error.localizedDescription)")
    },
    onStopByInterruption: { error in
        print(error?.localizedDescription ?? "Session interrupted")
        currentSession = nil
    },
    onException: { error in
        print("Session exception: \(error.localizedDescription)")
    },
    streamResultHandler: { isFinal, response, error in
        if let error {
            print(error.localizedDescription)
            return
        }
        guard let response else { return }

        if response.isSourceTextDefinite {
            print("Source: \(response.sourceText ?? "")")
        }
        if response.isTargetTextDefinite {
            print("Target: \(response.targetText ?? "")")
        }
        if isFinal { print("Final result") }
    },
    onEvent: { event in
        print(event)
    },
    onFinish: { report in
        currentSession = nil
        print(report ?? "No report")
    }
)

session.isRecordingInternallyfalse の場合、外部音声の経路はホストアプリが管理します。Demo では onStartSuccess の後にデバイス側の AI 録音を開始し、デコードした PCM を順次 session.appendInt16PCM(_:isFinal:) へ渡します。停止時は先にデバイス録音を止め、その後で AIBudsAISDK.stopSimultaneousInterpretation() を呼び出します。

注意事項

  • 開始時に返される SimultaneousInterpretationSessionConvertible を保持し、実行中のセッションと録音方式を管理してください。
  • onException が呼ばれても、セッションが停止するとは限りません。継続するか stopSimultaneousInterpretation() を呼ぶかをアプリで判断してください。
  • 逐次コールバックをそのまま追加せず、sourceTextSequencetargetTextSequence を使って確定区間を並べてください。
  • TTS 音声は SimultaneousInterpretationDataModel 上で、相対ファイル名、フルパス、または Base64 PCM データとして提供される場合があります。