Skip to content

Commit 9226cac

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: voice consent signature types across all SDK languages.
PiperOrigin-RevId: 885814555
1 parent c1fbc87 commit 9226cac

2 files changed

Lines changed: 140 additions & 2 deletions

File tree

GeneratedFirebaseAI/Sources/Converters.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,24 @@ public enum Converters {
18001800
public static func replicatedVoiceConfigToVertex(
18011801
apiClient: APIClient, fromObject: ReplicatedVoiceConfig
18021802
) throws -> [String: Any] {
1803+
1804+
if fromObject.consentAudio != nil {
1805+
throw NSError(
1806+
domain: "Vertex AI", code: -1,
1807+
userInfo: [
1808+
NSLocalizedDescriptionKey: "consentAudio parameter is not supported in Vertex AI."
1809+
])
1810+
}
1811+
1812+
if fromObject.voiceConsentSignature != nil {
1813+
throw NSError(
1814+
domain: "Vertex AI", code: -1,
1815+
userInfo: [
1816+
NSLocalizedDescriptionKey:
1817+
"voiceConsentSignature parameter is not supported in Vertex AI."
1818+
])
1819+
}
1820+
18031821
let encoder = JSONEncoder()
18041822
encoder.userInfo[.configuration] = apiClient
18051823
encoder.keyEncodingStrategy = .convertToSnakeCase

GeneratedFirebaseAI/Sources/Types.swift

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7682,6 +7682,53 @@ extension ToolConfig: Codable {
76827682
}
76837683
}
76847684

7685+
/// The signature of the voice consent check.
7686+
@available(iOS 15.0, macOS 13.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
7687+
public struct VoiceConsentSignature: Sendable {
7688+
/// The signature string.
7689+
public let signature: String?
7690+
7691+
/// Default initializer.
7692+
public init(
7693+
signature: String? = nil
7694+
) {
7695+
self.signature = signature
7696+
}
7697+
}
7698+
7699+
@available(iOS 15.0, macOS 13.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
7700+
extension VoiceConsentSignature: Codable {
7701+
7702+
// MARK: - Codable
7703+
public enum MLDevKeys: String, CodingKey {
7704+
case signature = "signature"
7705+
}
7706+
7707+
public init(from decoder: any Decoder) throws {
7708+
let configuration: APIClient = try decoder.userInfoOrThrow(.configuration)
7709+
7710+
let MLDevKeysContainer = try decoder.container(keyedBy: MLDevKeys.self)
7711+
signature = try MLDevKeysContainer.decodeIfPresent(
7712+
String.self,
7713+
forKey: .signature
7714+
)
7715+
}
7716+
7717+
public func encode(to encoder: any Encoder) throws {
7718+
let configuration: APIClient = try encoder.userInfoOrThrow(.configuration)
7719+
7720+
if configuration.isMlDeveloper() {
7721+
7722+
var MLDevKeysContainer = encoder.container(keyedBy: MLDevKeys.self)
7723+
try MLDevKeysContainer.encodeIfPresent(
7724+
signature,
7725+
forKey: .signature
7726+
)
7727+
7728+
}
7729+
}
7730+
}
7731+
76857732
/// The configuration for the replicated voice to use.
76867733
@available(iOS 15.0, macOS 13.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
76877734
public struct ReplicatedVoiceConfig: Sendable {
@@ -7693,13 +7740,29 @@ public struct ReplicatedVoiceConfig: Sendable {
76937740
/// The sample of the custom voice.
76947741
public let voiceSampleAudio: Data?
76957742

7743+
/// Recorded consent verifying ownership of the voice. This
7744+
/// represents 16-bit signed little-endian wav data, with a 24kHz sampling
7745+
/// rate.
7746+
public let consentAudio: Data?
7747+
7748+
/// Signature of a previously verified consent audio. This should be
7749+
/// populated with a signature generated by the server for a previous
7750+
/// request containing the consent_audio field. When provided, the
7751+
/// signature is verified instead of the consent_audio field to reduce
7752+
/// latency. Requests will fail if the signature is invalid or expired.
7753+
public let voiceConsentSignature: VoiceConsentSignature?
7754+
76967755
/// Default initializer.
76977756
public init(
76987757
mimeType: String? = nil,
7699-
voiceSampleAudio: Data? = nil
7758+
voiceSampleAudio: Data? = nil,
7759+
consentAudio: Data? = nil,
7760+
voiceConsentSignature: VoiceConsentSignature? = nil
77007761
) {
77017762
self.mimeType = mimeType
77027763
self.voiceSampleAudio = voiceSampleAudio
7764+
self.consentAudio = consentAudio
7765+
self.voiceConsentSignature = voiceConsentSignature
77037766
}
77047767
}
77057768

@@ -7712,6 +7775,10 @@ extension ReplicatedVoiceConfig: Codable {
77127775
case mimeType = "mimeType"
77137776
case voiceSampleAudio = "voiceSampleAudio"
77147777
}
7778+
public enum MLDevKeys: String, CodingKey {
7779+
case consentAudio = "consentAudio"
7780+
case voiceConsentSignature = "voiceConsentSignature"
7781+
}
77157782

77167783
public init(from decoder: any Decoder) throws {
77177784
let configuration: APIClient = try decoder.userInfoOrThrow(.configuration)
@@ -7726,6 +7793,17 @@ extension ReplicatedVoiceConfig: Codable {
77267793
Data.self,
77277794
forKey: .voiceSampleAudio
77287795
)
7796+
7797+
let MLDevKeysContainer = try decoder.container(keyedBy: MLDevKeys.self)
7798+
consentAudio = try MLDevKeysContainer.decodeIfPresent(
7799+
Data.self,
7800+
forKey: .consentAudio
7801+
)
7802+
7803+
voiceConsentSignature = try MLDevKeysContainer.decodeIfPresent(
7804+
VoiceConsentSignature.self,
7805+
forKey: .voiceConsentSignature
7806+
)
77297807
}
77307808

77317809
public func encode(to encoder: any Encoder) throws {
@@ -7741,6 +7819,21 @@ extension ReplicatedVoiceConfig: Codable {
77417819
voiceSampleAudio,
77427820
forKey: .voiceSampleAudio
77437821
)
7822+
7823+
if configuration.isMlDeveloper() {
7824+
7825+
var MLDevKeysContainer = encoder.container(keyedBy: MLDevKeys.self)
7826+
try MLDevKeysContainer.encodeIfPresent(
7827+
consentAudio,
7828+
forKey: .consentAudio
7829+
)
7830+
7831+
try MLDevKeysContainer.encodeIfPresent(
7832+
voiceConsentSignature,
7833+
forKey: .voiceConsentSignature
7834+
)
7835+
7836+
}
77447837
}
77457838
}
77467839

@@ -33967,25 +34060,42 @@ public struct LiveServerSetupComplete: Sendable {
3396734060
/// The session id of the live session.
3396834061
public let sessionId: String?
3396934062

34063+
/// Signature of the verified consent audio. This is populated when the
34064+
/// request has a ReplicatedVoiceConfig with consent_audio set, if the consent
34065+
/// verification was successful. This may be used in a subsequent request
34066+
/// instead of the consent_audio to verify the same consent.
34067+
public let voiceConsentSignature: VoiceConsentSignature?
34068+
3397034069
/// Default initializer.
3397134070
public init(
33972-
sessionId: String? = nil
34071+
sessionId: String? = nil,
34072+
voiceConsentSignature: VoiceConsentSignature? = nil
3397334073
) {
3397434074
self.sessionId = sessionId
34075+
self.voiceConsentSignature = voiceConsentSignature
3397534076
}
3397634077
}
3397734078

3397834079
@available(iOS 15.0, macOS 13.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
3397934080
extension LiveServerSetupComplete: Codable {
3398034081

3398134082
// MARK: - Codable
34083+
public enum MLDevKeys: String, CodingKey {
34084+
case voiceConsentSignature = "voiceConsentSignature"
34085+
}
3398234086
public enum VertexKeys: String, CodingKey {
3398334087
case sessionId = "sessionId"
3398434088
}
3398534089

3398634090
public init(from decoder: any Decoder) throws {
3398734091
let configuration: APIClient = try decoder.userInfoOrThrow(.configuration)
3398834092

34093+
let MLDevKeysContainer = try decoder.container(keyedBy: MLDevKeys.self)
34094+
voiceConsentSignature = try MLDevKeysContainer.decodeIfPresent(
34095+
VoiceConsentSignature.self,
34096+
forKey: .voiceConsentSignature
34097+
)
34098+
3398934099
let VertexKeysContainer = try decoder.container(keyedBy: VertexKeys.self)
3399034100
sessionId = try VertexKeysContainer.decodeIfPresent(
3399134101
String.self,
@@ -33996,6 +34106,16 @@ extension LiveServerSetupComplete: Codable {
3399634106
public func encode(to encoder: any Encoder) throws {
3399734107
let configuration: APIClient = try encoder.userInfoOrThrow(.configuration)
3399834108

34109+
if configuration.isMlDeveloper() {
34110+
34111+
var MLDevKeysContainer = encoder.container(keyedBy: MLDevKeys.self)
34112+
try MLDevKeysContainer.encodeIfPresent(
34113+
voiceConsentSignature,
34114+
forKey: .voiceConsentSignature
34115+
)
34116+
34117+
}
34118+
3399934119
if configuration.isVertexAI() {
3400034120

3400134121
var VertexKeysContainer = encoder.container(keyedBy: VertexKeys.self)

0 commit comments

Comments
 (0)