मुख्य कंटेंट तक स्किप करें

सामान्य रिकॉर्डिंग

Connected device से standard audio recording session शुरू या बंद करने का अनुरोध करें।

आवश्यक शर्तें

  • डिवाइस connected और ready है।
  • डिवाइस DeviceAudioRecordingAPI को conform करता है।
  • डिवाइस में recording के लिए पर्याप्त storage है।

API संदर्भ

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

प्रोटोकॉल

Requests DeviceAudioRecordingAPI में defined हैं।

Swift
/// The protocol for device API that supports audio recording.
protocol DeviceAudioRecordingAPI: DeviceAPI {
    /// Requests the device to start an audio recording session.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestStartAudioRecording(_ completion: AIBudsStatusCodeCompletionHandler?)

    /// Requests the device to stop the current audio recording session.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestStopAudioRecording(_ completion: AIBudsStatusCodeCompletionHandler?)
}

इंस्टेंस मेथड

Methodउपयोग
requestStartAudioRecordingडिवाइस से recording शुरू करने का अनुरोध करें।
requestStopAudioRecordingडिवाइस से recording बंद करने का अनुरोध करें।

पूर्णता मान

NameTypeविवरण
successBool / BOOLRequest सफल हुआ या नहीं।
statusCodeNSNumber?Device status code; operation fail होने पर nil
errorNSError?Failure details; success पर nil

Methods recording file path नहीं लौटाते। Result device command status है।

उपयोग के उदाहरण

Swift
import AIBuds

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

device.requestStartAudioRecording { success, statusCode, error in
    guard success else {
        print("Start failed: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Recording started, status: \(statusCode?.stringValue ?? "Unavailable")")
}

// Call this from the UI action that stops the active recording.
device.requestStopAudioRecording { success, statusCode, error in
    guard success else {
        print("Stop failed: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Recording stopped, status: \(statusCode?.stringValue ?? "Unavailable")")
}

त्रुटि प्रबंधन

Primary result के रूप में success उपयोग करें। Device-specific handling के लिए returned statusCode सुरक्षित रखें और available होने पर error दिखाएँ; public protocol individual status-code values का अर्थ नहीं बताता।