Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src-tauri/crates/berd-call/native/siri_tts_bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -1026,10 +1026,28 @@ static void BerdDownloadedVoices(
return @[];
}

// The name a voice's natural premium UAF asset carries as its CFBundleName.
static NSString *BerdUAFVoiceAssetName(NSString *language, NSString *voiceName) {
return [[NSString stringWithFormat:@"com.apple.siri.tts.voice.%@.%@.natural.premium",
[language stringByReplacingOccurrencesOfString:@"-" withString:@"_"], voiceName]
// The catalog identifier prefix of a Siri voice family.
static NSString *BerdSiriVoicePrefix(NSString *family) {
return [family isEqualToString:@"natural"]
? @"com.apple.siri.natural."
: @"com.apple.ttsbundle.gryphon-neural_";
}

// macOS 27 lists natural Siri voices, and Berd uses only those where they exist.
// macOS 26 has only neural ones.
static NSString *BerdSiriVoiceFamily(NSArray *resources) {
for (id resource in resources ?: @[]) {
if ([[resource valueForKey:@"identifier"] hasPrefix:BerdSiriVoicePrefix(@"natural")]) {
return @"natural";
}
}
return @"neural";
}

// The name a voice's premium UAF asset in a family carries as its CFBundleName.
static NSString *BerdUAFVoiceAssetName(NSString *language, NSString *voiceName, NSString *family) {
return [[NSString stringWithFormat:@"com.apple.siri.tts.voice.%@.%@.%@.premium",
[language stringByReplacingOccurrencesOfString:@"-" withString:@"_"], voiceName, family]
lowercaseString];
}

Expand Down Expand Up @@ -1079,6 +1097,8 @@ static void BerdDownloadedVoices(
return nil;
}
NSArray *resources = ((SendObject)objc_msgSend)(manager, voicesSelector, nil);
NSString *family = BerdSiriVoiceFamily(resources);
NSString *prefix = BerdSiriVoicePrefix(family);
NSString *normalizedFilter =
[[languageFilter stringByReplacingOccurrencesOfString:@"_" withString:@"-"] lowercaseString];
NSDictionary<NSString *, NSString *> *diskAssets = BerdUAFVoiceAssets(
Expand All @@ -1087,7 +1107,7 @@ static void BerdDownloadedVoices(
[NSMutableDictionary dictionary];
for (id resource in resources ?: @[]) {
NSString *identifier = [resource valueForKey:@"identifier"];
if (![identifier hasPrefix:@"com.apple.siri.natural."]) continue;
if (![identifier hasPrefix:prefix]) continue;
NSString *language = [resource valueForKey:@"language"] ?: @"";
NSString *normalizedLanguage =
[[language stringByReplacingOccurrencesOfString:@"_" withString:@"-"] lowercaseString];
Expand All @@ -1101,7 +1121,7 @@ static void BerdDownloadedVoices(
// on disk.
NSString *content = [resource valueForKey:@"contentPath"];
if (!content.length || ![NSFileManager.defaultManager fileExistsAtPath:content]) {
content = diskAssets[BerdUAFVoiceAssetName(language, name)];
content = diskAssets[BerdUAFVoiceAssetName(language, name, family)];
}
// Newer voices have a code as their name (en-US-F); macOS shows its localized name.
NSString *localizedName = [resource respondsToSelector:@selector(localizedName)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,31 @@ static BOOL BerdTestVoiceDownloadIdentity(NSError **error) {
}
NSDictionary *assets = BerdUAFVoiceAssets(root);
[files removeItemAtPath:root error:nil];
if (![assets[BerdUAFVoiceAssetName(@"en-US", @"Damon")] hasSuffix:@"/a/AssetData"] ||
![assets[BerdUAFVoiceAssetName(@"en-US", @"en-US-F")] hasSuffix:@"/b/AssetData"] ||
assets[BerdUAFVoiceAssetName(@"en-US", @"Quinn")] ||
assets[BerdUAFVoiceAssetName(@"en-US", @"Simone")] ||
assets[BerdUAFVoiceAssetName(@"en-GB", @"Damon")]) {
if (![assets[BerdUAFVoiceAssetName(@"en-US", @"Damon", @"natural")] hasSuffix:@"/a/AssetData"] ||
![assets[BerdUAFVoiceAssetName(@"en-US", @"en-US-F", @"natural")] hasSuffix:@"/b/AssetData"] ||
assets[BerdUAFVoiceAssetName(@"en-US", @"Quinn", @"natural")] ||
![assets[BerdUAFVoiceAssetName(@"en-US", @"Quinn", @"neural")] hasSuffix:@"/c/AssetData"] ||
assets[BerdUAFVoiceAssetName(@"en-US", @"Simone", @"natural")] ||
assets[BerdUAFVoiceAssetName(@"en-GB", @"Damon", @"natural")]) {
if (error) *error = BerdError(108, @"Siri voice assets on disk were matched wrongly.");
return NO;
}
return YES;
}

static BOOL BerdTestSiriVoiceFamily(NSError **error) {
NSDictionary *neural = @{ @"identifier" : @"com.apple.ttsbundle.gryphon-neural_Nora_en-US_premium" };
NSDictionary *natural = @{ @"identifier" : @"com.apple.siri.natural.en-US.Nora" };
if (![BerdSiriVoiceFamily(@[ neural, natural ]) isEqualToString:@"natural"] ||
![BerdSiriVoiceFamily(@[ neural ]) isEqualToString:@"neural"] ||
![neural[@"identifier"] hasPrefix:BerdSiriVoicePrefix(@"neural")] ||
[@"com.apple.ttsbundle.gryphon-neuralAX_Nora_en-US_premium" hasPrefix:BerdSiriVoicePrefix(@"neural")]) {
if (error) *error = BerdError(109, @"Siri voices were listed from the wrong family.");
return NO;
}
return YES;
}

int main(void) {
@autoreleasepool {
NSError *error = nil;
Expand All @@ -280,6 +294,10 @@ int main(void) {
fprintf(stderr, "voice download identity: %s\n", error.localizedDescription.UTF8String);
return 1;
}
if (!BerdTestSiriVoiceFamily(&error)) {
fprintf(stderr, "Siri voice family: %s\n", error.localizedDescription.UTF8String);
return 1;
}
if (!BerdTestPCMNormalization(&error)) {
fprintf(stderr, "normalize PCM: %s\n", error.localizedDescription.UTF8String);
return 1;
Expand Down
Loading