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

AI 録音

指定した RecordingScene に対応する AI 録音を開始・停止します。

前提条件

  • デバイスが接続済みで、操作可能な状態であること。
  • デバイスが DeviceAudioRecordingAPI に準拠していること。
  • 録音停止時には、開始時と同じシーンを指定すること。

API リファレンス

フレームワーク

AIBuds.xcframework

インポート

Swift
import AIBuds
import AIBudsFoundation

プロトコル

Swift
/// The protocol for device API that supports audio recording.
protocol DeviceAudioRecordingAPI: DeviceAPI {
    /// Starts an AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func startAIAudioRecording(
        _ scene: RecordingScene,
        completion: AIBudsCompletionHandler?
    )

    /// Stops the AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func stopAIAudioRecording(
        _ scene: RecordingScene,
        completion: AIBudsCompletionHandler?
    )
}

インスタンスメソッド

メソッド用途
startAIAudioRecording指定シーンの AI 録音を開始します。
stopAIAudioRecording指定シーンの AI 録音を停止します。

録音シーン

SwiftObjective-C説明
.onSiteAIBudsRecordingSceneOnSite周囲音や現場の録音。
.callAIBudsRecordingSceneCall通話中の録音。

完了ハンドラーは success と任意の NSError を返します。これらのメソッドは文字起こし結果や録音ファイルのパスを返しません。

使用例

Swift
import AIBuds

guard let device = device as? DeviceAudioRecordingAPI else {
    print("Device does not support audio recording")
    return
}

let scene: RecordingScene = .onSite
device.startAIAudioRecording(scene) { success, error in
    guard success else {
        print("AI recording failed to start: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("AI recording started")
}

// Stop using the same scene.
device.stopAIAudioRecording(scene) { success, error in
    if !success {
        print(error?.localizedDescription ?? "AI recording failed to stop")
    }
}

エラー処理

停止要求に同じシーンを渡せるよう、アプリで録音中のシーンを保持します。コールバックが失敗した場合は、デバイスから次の録音状態が通知されるまで、UI を未確定状態として扱ってください。