Skip to content

Commit acd5823

Browse files
committed
Fixed capitalization in docstrings
1 parent a976c9c commit acd5823

2 files changed

Lines changed: 47 additions & 46 deletions

File tree

Sources/FluidAudio/Diarizer/Clustering/SpeakerManager.swift

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public class SpeakerManager {
3737

3838
/// Add known speakers to the database
3939
/// - Parameters:
40-
/// - speakers: list of `Speaker`s to add
41-
/// - mode: mode for handling overlapping ID conflicts. `.reset` will reset the speaker database before initializing new speakers. `.overwrite` will overwrite the old speakers and replace them with the new ones. `.merge` will merge the new speakers with the old ones, keeping the new name. `.skip` will skip new speakers if their ID matches an existing one. (Default: `.skip`)
42-
/// - preservePermanent: whether to avoid overwriting/merging pre-existing permanent speakers
40+
/// - speakers: Array of `Speaker`s to add
41+
/// - mode: Mode for handling overlapping ID conflicts. `.reset` will reset the speaker database before initializing new speakers. `.overwrite` will overwrite the old speakers and replace them with the new ones. `.merge` Will merge the new speakers with the old ones, keeping the new name. `.skip` will skip new speakers if their ID matches an existing one. (Default: `.skip`)
42+
/// - preservePermanent: Whether to avoid overwriting/merging pre-existing permanent speakers
4343
public func initializeKnownSpeakers(_ speakers: [Speaker], mode: SpeakerInitializationMode = .skip, preserveIfPermanent: Bool = true) {
4444
if mode == .reset {
4545
self.reset(keepIfPermanent: preserveIfPermanent)
@@ -62,7 +62,7 @@ public class SpeakerManager {
6262
case .reset:
6363
fallthrough
6464
case .overwrite:
65-
if !(oldSpeaker.isPermanent && preservePermanent) {
65+
if !(oldSpeaker.isPermanent && preserveIfPermanent) {
6666
logger.warning("Speaker \(speaker.id) is already initialized. Overwriting old speaker.")
6767
speakerDatabase[speaker.id] = speaker
6868
} else {
@@ -101,11 +101,11 @@ public class SpeakerManager {
101101
/// Match the embedding to the closest existing speaker if sufficiently similar or create a new one if not.
102102
/// - Parameters:
103103
/// - embedding: 256D speaker embedding vector
104-
/// - speechDuration: duration of the speech segment during which this speaker was active
105-
/// - confidence: confidence in the embedding vector being correct
106-
/// - speakerThreshold: the maximum cosine distance to an existing speaker to create a new one (uses the default threshold for this `SpeakerManager` object if none is provided)
107-
/// - newName: name to assign the speaker if a new one is created (default: `Speaker $id`)
108-
/// - Returns: a `Speaker` object if a match was found or a new one was created. Returns `nil` if an error occured.
104+
/// - speechDuration: Duration of the speech segment during which this speaker was active
105+
/// - confidence: Confidence in the embedding vector being correct
106+
/// - speakerThreshold: The maximum cosine distance to an existing speaker to create a new one (uses the default threshold for this `SpeakerManager` object if none is provided)
107+
/// - newName: Name to assign the speaker if a new one is created (default: `Speaker $id`)
108+
/// - Returns: A `Speaker` object if a match was found or a new one was created. Returns `nil` if an error occured.
109109
public func assignSpeaker(
110110
_ embedding: [Float],
111111
speechDuration: Float,
@@ -162,8 +162,8 @@ public class SpeakerManager {
162162
/// Find the closest existing speaker to an embedding, up to a maximum cosine distance of `speakerThreshold`.
163163
/// - Parameters:
164164
/// - embedding: 256D speaker embedding vector
165-
/// - speakerThreshold: the maximum cosine distance to an existing speaker to create a new one (uses the default threshold for this `SpeakerManager` object if none is provided)
166-
/// - Returns: the ID of the match (if found) and the distance to that match.
165+
/// - speakerThreshold: Maximum cosine distance to an existing speaker to create a new one (uses the default threshold for this `SpeakerManager` object if none is provided)
166+
/// - Returns: ID of the match (if found) and the distance to that match.
167167
public func findSpeaker(with embedding: [Float], speakerThreshold: Float? = nil) -> (id: String?, distance: Float) {
168168
queue.sync {
169169
let (closestSpeakerId, minDistance) = findClosestSpeaker(to: embedding)
@@ -178,8 +178,8 @@ public class SpeakerManager {
178178
/// Find the closest existing speaker to an embedding, up to a maximum cosine distance of `speakerThreshold`.
179179
/// - Parameters:
180180
/// - embedding: 256D speaker embedding vector
181-
/// - speakerThreshold: the maximum cosine distance between `embedding` and another speaker for them to be a match (default: `self.speakerThreshold`)
182-
/// - Returns: a list of the `maxCount` nearest speakers and the distances to them from `embedding`, sorted by descending cosine distances.
181+
/// - speakerThreshold: Maximum cosine distance between `embedding` and another speaker for them to be a match (default: `self.speakerThreshold`)
182+
/// - Returns: Array of the `maxCount` nearest speakers and the distances to them from `embedding`, sorted by descending cosine distances.
183183
public func findMatchingSpeakers(with embedding: [Float], speakerThreshold: Float? = nil) -> [(id: String, distance: Float)] {
184184
queue.sync {
185185
var matches: [(id: String, distance: Float)] = []
@@ -196,17 +196,17 @@ public class SpeakerManager {
196196
}
197197
}
198198

199-
/// find all speakers that meet a certain predicate
200-
/// - Parameter predicate: the condition that the speakers must meet to be returned
201-
/// - Returns: a list of all Speaker IDs corresponding to Speakers that meet the predicate
199+
/// Find all speakers that meet a certain predicate
200+
/// - Parameter predicate: Condition the speakers must meet to be returned
201+
/// - Returns: A list of all Speaker IDs corresponding to Speakers that meet the predicate
202202
public func findSpeakers(where predicate: (Speaker) -> Bool) -> [String] {
203203
queue.sync {
204204
return speakerDatabase.filter { predicate($0.value) }.map(\.key)
205205
}
206206
}
207207

208208
/// Mark a speaker as permanent
209-
/// - Parameter speakerId: the ID of the speaker to mark as permanent
209+
/// - Parameter speakerId: ID of the speaker to mark as permanent
210210
public func makeSpeakerPermanent(_ speakerId: String) {
211211
queue.sync(flags: .barrier) {
212212
guard let speaker = speakerDatabase[speakerId] else {
@@ -219,7 +219,7 @@ public class SpeakerManager {
219219
}
220220

221221
/// Remove a speaker's permanent marker
222-
/// - Parameter speakerId: the ID of the speaker to mark as permanent
222+
/// - Parameter speakerId: ID of the speaker to mark as permanent
223223
public func revokePermanence(from speakerId: String) {
224224
queue.sync(flags: .barrier) {
225225
guard let speaker = speakerDatabase[speakerId] else {
@@ -236,9 +236,9 @@ public class SpeakerManager {
236236
/// - Parameters:
237237
/// - sourceId: ID of the `Speaker` being merged
238238
/// - destinationId: ID of the `Speaker` that absorbs the other one
239-
/// - mergedName: new name for the merged speaker (uses `destination`'s name if not provided)
240-
/// - stopIfPermanent: whether to stop merging if the source speaker is permanent
241-
/// - Returns: `true` if merge was successful, `false` if not.
239+
/// - mergedName: New name for the merged speaker (uses `destination`'s name if not provided)
240+
/// - stopIfPermanent: Whether to stop merging if the source speaker is permanent
241+
/// - Returns: `true` If merge was successful, `false` if not.
242242
public func mergeSpeaker(_ sourceId: String, into destinationId: String, mergedName: String? = nil, stopIfPermanent: Bool = true) -> Void {
243243
// don't merge a speaker into itself
244244
guard sourceId != destinationId else {
@@ -267,9 +267,9 @@ public class SpeakerManager {
267267

268268
/// Find all pairs of speakers that can be merged
269269
/// - Parameters:
270-
/// - speakerThreshold: the max cosine distance between speakers to let them be considered mergeable
271-
/// - excludeIfBothPermanent: whether to exclude speaker pairs where both speakers are permanent
272-
/// - Returns: a list of speaker ID pairs that belong to speakers that are similar enough to be merged
270+
/// - speakerThreshold: Max cosine distance between speakers to let them be considered mergeable
271+
/// - excludeIfBothPermanent: Whether to exclude speaker pairs where both speakers are permanent
272+
/// - Returns: Array of speaker ID pairs that belong to speakers that are similar enough to be merged
273273
public func findMergeablePairs(speakerThreshold: Float? = nil, excludeIfBothPermanent: Bool = true) -> [(speakerToMerge: String, destination: String)] {
274274
queue.sync {
275275
let speakerThreshold = speakerThreshold ?? self.speakerThreshold
@@ -317,7 +317,7 @@ public class SpeakerManager {
317317
/// Remove a speaker from the database
318318
/// - Parameters:
319319
/// - speakerID: ID of the speaker being removed
320-
/// - keepIfPermanent: whether to stop the removal if the speaker is marked as permanent
320+
/// - keepIfPermanent: Whether to stop the removal if the speaker is marked as permanent
321321
public func removeSpeaker(_ speakerID: String, keepIfPermanent: Bool = true) {
322322
queue.sync(flags: .barrier) {
323323
// determine if we should skip the removal due to permanence
@@ -338,7 +338,7 @@ public class SpeakerManager {
338338
/// Remove all speakers that were inactive since a given `date`
339339
/// - Parameters:
340340
/// - data: Speakers who have not been active after this date will be removed.
341-
/// - keepIfPermanent: whether to stop the removal if the speaker is marked as permanent
341+
/// - keepIfPermanent: Whether to stop the removal if the speaker is marked as permanent
342342
public func removeSpeakersInactive(since date: Date, keepIfPermanent: Bool = true) {
343343
queue.sync(flags: .barrier) {
344344
if keepIfPermanent {
@@ -357,19 +357,19 @@ public class SpeakerManager {
357357
}
358358
}
359359

360-
/// remove speakers that have been inactive for a given duration
360+
/// Remove speakers that have been inactive for a given duration
361361
/// - Parameters:
362362
/// - durationInactive: Minimum duration for which a speaker needs to be inactive to be removed
363-
/// - keepIfPermanent: whether to stop the removal if the speaker is marked as permanent
363+
/// - keepIfPermanent: Whether to stop the removal if the speaker is marked as permanent
364364
public func removeSpeakersInactive(for durationInactive: TimeInterval, keepIfPermanent: Bool = true) {
365365
let date = Date().addingTimeInterval(-durationInactive)
366366
self.removeSpeakersInactive(since: date, keepIfPermanent: keepIfPermanent)
367367
}
368368

369-
/// remove speakers that meet a certain predicate
369+
/// Remove speakers that meet a certain predicate
370370
/// - Parameters:
371-
/// - predicate: the predicate to determine whether the speaker should be removed
372-
/// - keepIfPermanent: whether to stop the removal if the speaker is marked as permanent
371+
/// - predicate: The predicate to determine whether the speaker should be removed
372+
/// - keepIfPermanent: Whether to stop the removal if the speaker is marked as permanent
373373
public func removeSpeakers(where predicate: (Speaker) -> Bool, keepIfPermanent: Bool = true) {
374374
queue.sync(flags: .barrier) {
375375
if keepIfPermanent {
@@ -387,15 +387,15 @@ public class SpeakerManager {
387387
}
388388
}
389389

390-
/// remove non-permanent speakers that meet a certain predicate
390+
/// Remove non-permanent speakers that meet a certain predicate
391391
/// - Parameters:
392-
/// - predicate: the predicate to determine whether the speaker should be removed
392+
/// - predicate: Predicate to determine whether the speaker should be removed
393393
public func removeSpeakers(where predicate: (Speaker) -> Bool) {
394394
removeSpeakers(where: predicate, keepIfPermanent: true)
395395
}
396396

397397
/// Check if the speaker database has a speaker with a given ID.
398-
/// - Parameter speakerId: the ID to check
398+
/// - Parameter speakerId: ID to check
399399
/// - Returns: `true` if a speaker is found, `false` if not
400400
public func hasSpeaker(_ speakerId: String) -> Bool {
401401
queue.sync {
@@ -548,7 +548,7 @@ public class SpeakerManager {
548548
/// - updateCount: Number of updates to this speaker
549549
/// - createdAt: Creation timestamp
550550
/// - updatedAt: Last update timestamp
551-
/// - isPermanent: whether the speaker should be protected from merges and removals by default
551+
/// - isPermanent: Whether the speaker should be protected from merges and removals by default
552552
public func upsertSpeaker(
553553
id: String,
554554
currentEmbedding: [Float],
@@ -603,7 +603,7 @@ public class SpeakerManager {
603603
}
604604

605605
/// Reset the speaker database
606-
/// - Parameter keepIfPermanent: whether to keep permanent speakers
606+
/// - Parameter keepIfPermanent: Whether to keep permanent speakers
607607
public func reset(keepIfPermanent: Bool = false) {
608608
queue.sync(flags: .barrier) {
609609
if !keepIfPermanent {

Sources/FluidAudio/Diarizer/Clustering/SpeakerTypes.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ public final class Speaker: Identifiable, Codable, Equatable, Hashable {
5959
return SendableSpeaker(from: self)
6060
}
6161

62-
/// Update main embedding with new segment data using exponential moving average
62+
/// Update main embedding with new segment data using exponential moving average (EMA)
6363
/// - Parameters:
64-
/// - duration: segment duration
65-
/// -
64+
/// - duration: Segment duration
65+
/// - embedding: 256D speaker embedding vector
66+
/// - segmentId: The ID of the segment
67+
/// - alpha: EMA blending parameter
6668
public func updateMainEmbedding(
6769
duration: Float,
6870
embedding: [Float],
6971
segmentId: UUID,
7072
alpha: Float = 0.9
7173
) {
72-
7374
// Validate embedding quality
7475
var sumSquares: Float = 0
7576
vDSP_svesq(embedding, 1, &sumSquares, vDSP_Length(embedding.count))
@@ -162,8 +163,8 @@ public final class Speaker: Identifiable, Codable, Equatable, Hashable {
162163

163164
/// Merge another speaker into this one
164165
/// - Parameters:
165-
/// - other: other Speaker to merge
166-
/// - keepName: the resulting name after the merge
166+
/// - other: Other Speaker to merge
167+
/// - keepName: The resulting name after the merge
167168
public func mergeWith(_ other: Speaker, keepName: String? = nil) {
168169
// Merge raw embeddings
169170
var allEmbeddings = rawEmbeddings + other.rawEmbeddings
@@ -269,13 +270,13 @@ public struct SendableSpeaker: Sendable, Identifiable, Hashable {
269270
}
270271

271272
public enum SpeakerInitializationMode {
272-
/// reset the speaker database and add the new speakers
273+
/// Reset the speaker database and add the new speakers
273274
case reset
274-
/// merge new speakers whose IDs match with existing ones
275+
/// Merge new speakers whose IDs match with existing ones
275276
case merge
276-
/// overwrite existing speakers with the same IDs as the new ones
277+
/// Overwrite existing speakers with the same IDs as the new ones
277278
case overwrite
278-
/// skip speakers whose IDs match existing ones
279+
/// Skip speakers whose IDs match existing ones
279280
case skip
280281
}
281282

0 commit comments

Comments
 (0)