Diyalog Çevirisi
Etkin konuşmacı için kısa bir eşzamanlı çeviri oturumu başlatıp diğer katılımcıda kaynak ve hedef dilleri ters çevirerek iki kişilik, sırayla konuşulan bir çeviri deneyimi oluşturun.
Bu, ConversationTranslationDemoController ile gösterilen bir ürün iş akışıdır; ayrı bir ConversationTranslationAPI sunmaz.
One conversation turn
Each speaker turn owns one interpretation session. Reverse the language direction for the partner's turn and never run both turns concurrently.
Ön Koşullar
- Eşzamanlı Çeviri sayfasındaki tüm ön koşulları karşılayın.
- Birbirinden farklı, tireli kaynak ve hedef dil tanımlayıcıları kullanın.
- Etkin konuşmacıyı, geçerli oturumu, başlatma/durdurma durumunu ve gösterilen tur iletilerini ana uygulamada izleyin.
- İki konuşmacının aynı anda oturum başlatmasını engelleyin.
AI desteğiyle uygulayın
Bu iş akışını AI ile uygulayın
Resmî “AIBuds Konuşma Çevirisini Uygulama” becerisini kullanarak iş akışını uygulamanıza uyarlayın.
https://docs-aibuds.github.io/tr/skills/implement-aibuds-conversation-translation adresini okuyup yönergeleri izleyin. Bu beceriyle “AIBuds Konuşma Çevirisini Uygulama” iş akışını iOS projesinde uygulayıp doğrulayın.API Reference
Diyalog Çevirisi; startSimultaneousInterpretation, stopSimultaneousInterpretation ve SimultaneousInterpretationConfig kullanır.
Genel bildirimlerin ve geri çağrı sözleşmesinin tamamı için Eşzamanlı Çeviri sayfasına bakın.
Kullanım Örnekleri
Konuşmacı Turunu Başlatma
Demo, “Ben” için myLanguage → partnerLanguage, “Karşı taraf” için ters yönü kullanır. Aşağıdaki yardımcılar çözümlenen yönü kabul ederek ürün durumunu açık hale getirir.
- Swift
- Objective-C
func startConversationTurn(source: String, target: String) {
guard currentSession == nil, source != target else { return }
let config = SimultaneousInterpretationConfig.default
config.sourceLanguage = source
config.targetLanguage = target
config.usesInternalAudioRecording = true
config.preferSpeakerOutput = true
config.enableVoicePlayback = true
AIBudsAISDK.startSimultaneousInterpretation(
config,
onStartSuccess: { session in
currentSession = session
setTurnActive(true)
},
onStartFailure: { error in
currentSession = nil
setTurnActive(false)
show(error)
},
onStopByInterruption: { error in
currentSession = nil
setTurnActive(false)
if let error { show(error) }
},
onException: { error in
showRecoverable(error)
},
streamResultHandler: { _, response, error in
if let error {
show(error)
return
}
guard let response else { return }
if response.isSourceTextDefinite { renderSource(response) }
if response.isTargetTextDefinite { renderTarget(response) }
},
onEvent: { event in
handle(event)
},
onFinish: { report in
currentSession = nil
setTurnActive(false)
save(report)
}
)
}- (void)startConversationTurnFrom:(NSString *)source to:(NSString *)target {
if (self.currentSession != nil || [source isEqualToString:target])
return;
AIBudsSimultaneousInterpretationConfig *config =
[AIBudsSimultaneousInterpretationConfig defaultConfig];
config.sourceLanguage = source;
config.targetLanguage = target;
config.usesInternalAudioRecording = YES;
config.preferSpeakerOutput = YES;
config.enableVoicePlayback = YES;
[AIBudsAISDK startSimultaneousInterpretationWithConfig:config
onStartSuccess:^(id<AIBudsSimultaneousInterpretationSessionConvertible> session) {
self.currentSession = session;
[self setTurnActive:YES];
}
onStartFailure:^(NSError *error) {
self.currentSession = nil;
[self setTurnActive:NO];
[self showError:error];
}
onStopByInterruption:^(NSError *error) {
self.currentSession = nil;
[self setTurnActive:NO];
if (error != nil)
[self showError:error];
}
onException:^(NSError *error) {
[self showRecoverableError:error];
}
streamResultHandler:^(
BOOL isFinal, AIBudsSimultaneousInterpretationDataModel *response, NSError *error) {
if (error != nil) {
[self showError:error];
return;
}
if (response.isSourceTextDefinite)
[self renderSource:response];
if (response.isTargetTextDefinite)
[self renderTarget:response];
}
onEvent:^(AIBudsSimultaneousInterpretationEventModel *event) {
[self handleEvent:event];
}
onFinish:^(AIBudsSimultaneousInterpretationReportModel *report) {
self.currentSession = nil;
[self setTurnActive:NO];
[self saveReport:report];
}];
}Etkin Turu Durdurma
currentSession.isRecordingInternally false olduğunda son sesin doğru sırayla iletilmesi için hizmetten önce aygıt tarafındaki AI kaydını durdurun.
- Swift
- Objective-C
func stopConversationTurn() {
guard let session = currentSession else { return }
if !session.isRecordingInternally,
let recordingDevice = device as? DeviceAudioRecordingAPI
{
recordingDevice.stopAIAudioRecording(.onSite) { _, _ in
AIBudsAISDK.stopSimultaneousInterpretation()
}
} else {
AIBudsAISDK.stopSimultaneousInterpretation()
}
}- (void)stopConversationTurn {
if (self.currentSession == nil)
return;
if (!self.currentSession.isRecordingInternally) {
id<AIBudsDeviceAudioRecordingAPI> recordingDevice =
(id<AIBudsDeviceAudioRecordingAPI>)self.device;
if ([recordingDevice conformsToProtocol:@protocol(AIBudsDeviceAudioRecordingAPI)]) {
[recordingDevice
stopAIAudioRecordingWithScene:AIBudsRecordingSceneOnSite
completion:^(__unused BOOL success, __unused NSError *error) {
[AIBudsAISDK stopSimultaneousInterpretation];
}];
return;
}
}
[AIBudsAISDK stopSimultaneousInterpretation];
}Hata Yönetimi
Başlatma hatasını, kesintiyi, kurtarılabilir istisnayı, akış hatasını, aygıt kayıt hatasını ve nihai tamamlanmayı ayrı yönetin. Aygıt kaydı hâlâ başlarken durdurma istenirse hizmeti durdurmayı aygıt başlatma geri çağrısı tamamlanana kadar erteleyin; Demo bu yarış durumunu açıkça izler.
Notlar
- Bir diyalog birçok tur içerebilir ancak aynı anda yalnızca bir çeviri oturumu etkin olmalıdır.
- Dilleri yalnızca etkin tur yokken değiştirin.
- Her geri çağrıyı doğrudan eklemek yerine kesin parçaları kaynak ve hedef sıra alanlarıyla sıralayın.
- Harici aygıt kaydı kullanıldığında ilk paketin kaybolmaması için aygıt sesini başlatmadan önce saklanan çeviri oturumunu uygulamanın PCM yönlendirme yoluna kaydedin.