key缺少,添加权限多语言

This commit is contained in:
2026-03-07 13:29:29 +08:00
parent e03287605c
commit cbcf8c4197
47 changed files with 986 additions and 225 deletions

View File

@@ -940,7 +940,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
case KBChatMessageActionTypeCopy: {
if (message.text.length > 0) {
[UIPasteboard generalPasteboard].string = message.text;
[KBHUD showSuccess:KBLocalized(@"复制成功")];
[KBHUD showSuccess:KBLocalized(@"Copied")];
}
} break;
case KBChatMessageActionTypeDelete: {
@@ -973,7 +973,7 @@ static NSString * const KBChatSessionDidResetNotification = @"KBChatSessionDidRe
dispatch_async(dispatch_get_main_queue(), ^{
[KBHUD dismiss];
if (!success || error) {
NSString *msg = error.localizedDescription ?: KBLocalized(@"删除失败,请重试");
NSString *msg = error.localizedDescription ?: KBLocalized(@"Delete failed, please try again");
[KBHUD showError:msg];
return;
}

View File

@@ -349,7 +349,7 @@
_goChatButton.layer.cornerRadius = 25;
}
[_goChatButton setTitle:KBLocalized(@"Go Chatting") forState:UIControlStateNormal];
[_goChatButton setTitle:KBLocalized(@"Chatting") forState:UIControlStateNormal];
[_goChatButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
_goChatButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
[_goChatButton addTarget:self action:@selector(goChatButtonTapped) forControlEvents:UIControlEventTouchUpInside];

View File

@@ -548,7 +548,7 @@
- (UILabel *)contentTitleLabel {
if (!_contentTitleLabel) {
_contentTitleLabel = [[UILabel alloc] init];
_contentTitleLabel.text = KBLocalized(@"selection content");
_contentTitleLabel.text = KBLocalized(@"Selection Content");
_contentTitleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_contentTitleLabel.textColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.0];
}

View File

@@ -1272,9 +1272,9 @@ static void KBChatUpdatedDarwinCallback(CFNotificationCenterRef center,
}
NSLog(@"[KBAIHomeVC] 语音转文字失败:%@", error.localizedDescription);
[KBHUD showError:KBLocalized(@"语音转文字失败,请重试")];
[KBHUD showError:KBLocalized(@"Voice-to-text failed, please try again")];
if (cell) {
[cell updateLastUserMessage:KBLocalized(@"语音识别失败")];
[cell updateLastUserMessage:KBLocalized(@"Voice recognition failed")];
}
strongSelf.isVoiceProcessing = NO;
[strongSelf updateCollectionViewScrollState];
@@ -1284,7 +1284,7 @@ static void KBChatUpdatedDarwinCallback(CFNotificationCenterRef center,
NSString *transcript = response.data.transcript ?: @"";
if (transcript.length == 0) {
NSLog(@"[KBAIHomeVC] 语音转文字结果为空");
[KBHUD showError:KBLocalized(@"未识别到语音内容")];
[KBHUD showError:KBLocalized(@"No speech content recognized")];
if (cell) {
[cell removeLoadingUserMessage];
}
@@ -1305,7 +1305,7 @@ static void KBChatUpdatedDarwinCallback(CFNotificationCenterRef center,
- (void)voiceRecordManagerDidRecordTooShort:(KBVoiceRecordManager *)manager {
NSLog(@"[KBAIHomeVC] 录音过短,已忽略");
[KBHUD showError:KBLocalized(@"录音时间过短,请重新录音")];
[KBHUD showError:KBLocalized(@"Recording too short, please try again")];
}
- (void)voiceRecordManager:(KBVoiceRecordManager *)manager

View File

@@ -8,6 +8,7 @@
#import "KBVoiceToTextManager.h"
#import "DeepgramStreamingManager.h"
#import "KBVoiceInputBar.h"
#import "KBLocalizationManager.h"
@interface KBVoiceToTextManager () <KBVoiceInputBarDelegate,
DeepgramStreamingManagerDelegate>
@@ -55,6 +56,7 @@
if (!self.deepgramEnabled) {
return;
}
[self kb_refreshDeepgramLanguage];
[self.deepgramManager prepareConnection];
}
@@ -72,7 +74,7 @@
self.deepgramManager.delegate = self;
self.deepgramManager.serverURL = @"wss://api.deepgram.com/v1/listen";
self.deepgramManager.apiKey = @"9c792eb63a65d644cbc95785155754cd1e84f8cf";
self.deepgramManager.language = @"en";
[self kb_refreshDeepgramLanguage];
self.deepgramManager.model = @"nova-3";
self.deepgramManager.punctuate = YES;
self.deepgramManager.smartFormat = YES;
@@ -86,15 +88,35 @@
[self.fullText setString:@""];
}
- (void)kb_refreshDeepgramLanguage {
self.deepgramManager.language = [self kb_currentDeepgramLanguageCode];
}
- (NSString *)kb_currentDeepgramLanguageCode {
NSString *languageCode = [KBLocalizationManager shared].currentLanguageCode ?: @"en";
NSString *lc = languageCode.lowercaseString;
if ([lc hasPrefix:@"es"]) { return @"es"; }
if ([lc hasPrefix:@"id"]) { return @"id"; }
if ([lc hasPrefix:@"pt"]) { return @"pt"; }
if ([lc hasPrefix:@"zh-hant"] || [lc hasPrefix:@"zh_tw"] || [lc hasPrefix:@"zh-tw"] || [lc hasPrefix:@"zh-hk"]) {
return @"zh-TW";
}
if ([lc hasPrefix:@"zh-hans"] || [lc hasPrefix:@"zh_cn"] || [lc hasPrefix:@"zh-cn"]) {
return @"zh-CN";
}
return @"en";
}
#pragma mark - KBVoiceInputBarDelegate
- (void)voiceInputBarDidBeginRecording:(KBVoiceInputBar *)inputBar {
[self resetTranscript];
if (self.deepgramEnabled) {
inputBar.statusText = @"正在连接...";
[self kb_refreshDeepgramLanguage];
inputBar.statusText = KBLocalized(@"Voice Connecting...");
[self.deepgramManager start];
} else {
inputBar.statusText = @"正在录音...";
inputBar.statusText = KBLocalized(@"Voice Recording...");
}
if ([self.delegate respondsToSelector:@selector
@@ -105,10 +127,10 @@
- (void)voiceInputBarDidEndRecording:(KBVoiceInputBar *)inputBar {
if (self.deepgramEnabled) {
inputBar.statusText = @"正在识别...";
inputBar.statusText = KBLocalized(@"Voice Recognizing...");
[self.deepgramManager stopAndFinalize];
} else {
inputBar.statusText = @"录音结束";
inputBar.statusText = KBLocalized(@"Voice Recording Ended");
}
if ([self.delegate respondsToSelector:@selector
@@ -118,7 +140,7 @@
}
- (void)voiceInputBarDidCancelRecording:(KBVoiceInputBar *)inputBar {
inputBar.statusText = @"已取消";
inputBar.statusText = KBLocalized(@"Voice Cancelled");
[self resetTranscript];
if (self.deepgramEnabled) {
[self.deepgramManager cancel];
@@ -136,7 +158,7 @@
if (!self.deepgramEnabled) {
return;
}
self.inputBar.statusText = @"正在聆听...";
self.inputBar.statusText = KBLocalized(@"Voice Listening...");
}
- (void)deepgramStreamingManagerDidDisconnect:(NSError *_Nullable)error {
@@ -147,7 +169,7 @@
return;
}
self.inputBar.statusText = @"识别失败";
self.inputBar.statusText = KBLocalized(@"Voice Recognition Failed");
if ([self.delegate respondsToSelector:@selector
(voiceToTextManager:didFailWithError:)]) {
[self.delegate voiceToTextManager:self didFailWithError:error];
@@ -174,7 +196,7 @@
}
self.inputBar.statusText =
displayText.length > 0 ? displayText : @"正在识别...";
displayText.length > 0 ? displayText : KBLocalized(@"Voice Recognizing...");
if ([self.delegate respondsToSelector:@selector
(voiceToTextManager:didUpdateInterimText:)]) {
@@ -195,7 +217,7 @@
NSString *finalText = [self.fullText copy];
self.inputBar.statusText =
finalText.length > 0 ? finalText : @"识别完成";
finalText.length > 0 ? finalText : KBLocalized(@"Voice Recognition Completed");
if (finalText.length > 0 &&
[self.delegate respondsToSelector:@selector
@@ -208,7 +230,7 @@
if (!self.deepgramEnabled) {
return;
}
self.inputBar.statusText = @"识别失败";
self.inputBar.statusText = KBLocalized(@"Voice Recognition Failed");
if ([self.delegate respondsToSelector:@selector
(voiceToTextManager:didFailWithError:)]) {
[self.delegate voiceToTextManager:self didFailWithError:error];