key缺少,添加权限多语言
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user