Ana içeriğe geç

Çevrimdışı Sesli Asistan Modunu Okuma ve Ayarlama

Etkin çevrimdışı sesli asistan modunu okuyun ve aygıt yeteneğinin desteklediği bir modu isteyin.

Ön Koşullar

  • Aygıt bağlıdır ve OnDeviceVoiceAssistantAPI protokolüne uyar.
  • onDeviceVoiceAssistantCapability, .none değildir.
  • Hedef mod bildirilen yetenekle uyumludur ve .unknown değildir.

API Reference

Framework

AIBuds.xcframework

Declaration

Swift
/// The protocol for the on-device voice assistant API.
protocol OnDeviceVoiceAssistantAPI: DeviceAPI {
    /// The current mode of the on-device voice assistant.
    var onDeviceVoiceAssistantMode: OnDeviceVoiceAssistantMode { get }

    /// Sets the mode of the on-device voice assistant.
    /// - Parameters:
    ///   - mode: The desired mode to set.
    ///   - completion: Called when the operation completes.
    ///     - success: `true` when the operation succeeds.
    ///     - error: Error details on failure; otherwise `nil`.
    func setOnDeviceVoiceAssistantMode(_ mode: OnDeviceVoiceAssistantMode,
                                   completion: AIBudsCompletionHandler?)
}

onDeviceVoiceAssistantMode, setOnDeviceVoiceAssistantMode ve OnDeviceVoiceAssistantMode başvurularına bakın.

Uyumlu Modlar

YetenekGösterilecek modlar
.noneMod denetimi yok
.keywordWakeup.disabled, .basic
.common.disabled, .basic, .advanced

Kullanım Örnekleri

Swift
guard let voiceAssistant = device as? OnDeviceVoiceAssistantAPI else {
    print("On-device voice assistant is not supported")
    return
}

print("Current mode: \(voiceAssistant.onDeviceVoiceAssistantMode)")

guard voiceAssistant.onDeviceVoiceAssistantCapability == .common else {
    print("Advanced mode is not supported")
    return
}

voiceAssistant.setOnDeviceVoiceAssistantMode(.advanced) { success, error in
    guard success else {
        print(error?.localizedDescription ?? "Unable to change mode")
        return
    }
    print("Mode changed to advanced")
}

Notlar

  • .unknown, kullanılamayan durumu temsil eder ve hedef mod olarak gönderilmemelidir.
  • Başarılı geri çağrı isteği doğrular. Arayüzü aygıt özelliğinden veya mod değişikliği delegesi geri çağrısından yenileyin.
  • .advanced, arama durumu sesli denetimini içerir ve yalnızca .common yeteneğinde sunulmalıdır.