Ana içeriğe geç

Standart Ses Kaydı

Bağlı aygıttan standart ses kaydı oturumunu başlatmasını veya durdurmasını isteyin.

Ön Koşullar

  • Aygıt bağlı ve hazırdır.
  • Aygıt DeviceAudioRecordingAPI protokolüne uyar.
  • Aygıtta kayıt için yeterli depolama alanı vardır.

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

Protokol

İstekler DeviceAudioRecordingAPI tarafından tanımlanır.

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?)
}

Örnek Yöntemleri

YöntemAmaç
requestStartAudioRecordingAygıttan kaydı başlatmasını ister.
requestStopAudioRecordingAygıttan kaydı durdurmasını ister.

Tamamlanma Değerleri

AdTürAçıklama
successBool / BOOLİsteğin başarılı olup olmadığı.
statusCodeNSNumber?Aygıtın döndürdüğü durum kodu; işlem başarısızsa nil.
errorNSError?Hata ayrıntıları; başarılıysa nil.

Yöntemler kayıt dosyası yolu döndürmez. Sonuç, aygıt komutunun durumudur.

Kullanım Örnekleri

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")")
}

Hata Yönetimi

Birincil sonuç olarak success kullanın. Aygıta özgü işleme için dönen statusCode değerini koruyun ve varsa error öğesini gösterin; genel protokol tek tek durum kodlarının anlamını belgelemez.