다음을 통해 공유


Teams 상호 운용성에 대한 선택 자막 사용

사용자가 Azure Communication Services 사용자와 Teams 클라이언트 사용자 간의 모임에 참석하거나 사용자가 Microsoft 365 ID로 Azure Communication Services 통화 SDK를 사용하는 Teams 상호 운용성 시나리오에서 사용자가 선택 자막을 사용하도록 설정하는 방법을 알아봅니다.

필수 조건

참고 항목

이 가이드에 설명된 선택 자막 기능에 액세스하려면 Azure Communication Services 통화 SDK를 사용하는 음성 통화 앱이 있어야 합니다.

모델

이름 설명
CaptionsCallFeature 캡션 통화 기능 API
TeamsCaptions Teams 캡션용 API
StartCaptionOptions 음성 언어와 같은 선택 자막 옵션
TeamsCaptionsReceivedEventArgs Teams 캡션으로 받은 이벤트 각각에 대한 데이터 개체

선택 자막 기능 가져오기

외부 ID 사용자 및 Microsoft 365 사용자

Azure Communication Services 사용자가 Teams 모임에 참가할 수 있도록 하는 애플리케이션을 빌드하는 경우

CaptionsCallFeature captionsCallFeature = call.Features.Captions;
CallCaptions callCaptions = await captionsCallFeature.GetCaptionsAsync();
if (callCaptions.CaptionsKind == CaptionsKind.TeamsCaptions)
{
    TeamsCaptions teamsCaptions = callCaptions as TeamsCaptions;
} 

수신기 구독

수신기를 추가하여 캡션 사용 여부 상태 받기

teamsCaptions.CaptionsEnabledChanged += OnIsCaptionsEnabledChanged;

private void OnIsCaptionsEnabledChanged(object sender, PropertyChangedEventArgs args)
{
    if (teamsCaptions.IsEnabled)
    {
    }
}

수신된 캡션 데이터에 대한 수신기 추가

teamsCaptions.CaptionsReceived += OnCaptionsReceived;

private void OnCaptionsReceived(object sender, TeamsCaptionsReceivedEventArgs eventArgs)
{
    // Information about the speaker.
    // eventArgs.Speaker
    // The original text with no transcribed.
    // eventArgs.SpokenText
    // language identifier for the captions text.
    // eventArgs.CaptionLanguage
    // language identifier for the speaker.
    // eventArgs.SpokenLanguage
    // The transcribed text.
    // eventArgs.CaptionText
    // Timestamp denoting the time when the corresponding speech was made.
    // eventArgs.Timestamp
    // CaptionsResultKind is Partial if text contains partially spoken sentence.
    // It is set to Final once the sentence has been completely transcribed.
    // eventArgs.ResultKind
}

활성 음성 언어 변경 상태를 수신하는 수신기 추가

teamsCaptions.ActiveSpokenLanguageChanged += OnIsActiveSpokenLanguageChanged;

private void OnIsActiveSpokenLanguageChanged(object sender, PropertyChangedEventArgs args)
{
    // teamsCaptions.ActiveSpokenLanguage
}

활성 캡션 언어 변경 상태를 수신하는 수신기 추가

teamsCaptions.ActiveCaptionLanguageChanged += OnIsActiveCaptionLanguageChanged;

private void OnIsActiveCaptionLanguageChanged(object sender, PropertyChangedEventArgs args)
{
    // teamsCaptions.ActiveCaptionLanguage
}

캡션 시작

모든 수신기를 설정했으면 캡션 추가를 시작할 수 있습니다.


private async void StartCaptions()
{
    var options = new StartCaptionsOptions
    {
        SpokenLanguage = "en-us"
    };
    try
    {
        await teamsCaptions.StartCaptionsAsync(options);
    }
    catch (Exception ex)
    {
    }
}

캡션 중지

private async void StopCaptions()
{
    try
    {
        await teamsCaptions.StopCaptionsAsync();
    }
    catch (Exception ex)
    {
    }
}

캡션 수신 수신기 제거

teamsCaptions.CaptionsReceived -= OnCaptionsReceived;

음성 언어 지원

지원되는 음성 언어 목록 가져오기

선택 자막을 사용하도록 설정할 때 사용자가 선택할 수 있는, 지원되는 음성 언어 목록을 가져옵니다.

// bcp 47 formatted language code
IReadOnlyList<string> sLanguages = teamsCaptions.SupportedSpokenLanguages;```

### Set spoken language 
When the user selects the spoken language, your app can set the spoken language that it expects captions to be generated from. 

``` cs 
public async void SetSpokenLanguage()
{
    try
    {
        await teamsCaptions.SetSpokenLanguageAsync("en-us");
    }
    catch (Exception ex)
    {
    }
}

캡션 언어 지원

지원되는 캡션 언어 가져오기

조직에 활성 Teams 프리미엄 라이선스가 있는 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 있는 동안에는 Azure Communication Services 사용자가 번역된 캡션을 사용하도록 설정할 수 있습니다. Microsoft 365 ID가 있는 사용자의 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 없을 때 자신의 사용자 계정에 대해 이 사항이 확인됩니다.

// ISO 639-1 formatted language code
IReadOnlyList<string> cLanguages = teamsCaptions.SupportedCaptionLanguages;

자막 언어 설정

public async void SetCaptionLanguage()
{
    try
    {
        await teamsCaptions.SetCaptionLanguageAsync("en");
    }
    catch (Exception ex)
    {
    }
}

필수 조건

참고 항목

이 가이드에 설명된 선택 자막 기능에 액세스하려면 Azure Communication Services 통화 SDK를 사용하는 음성 통화 앱이 있어야 합니다.

모델

이름 설명
CaptionsCallFeature 캡션용 API
CaptionsCommon 캡션 기본 클래스
StartCaptionOptions 음성 언어와 같은 선택 자막 옵션
TeamsCaptionHandler CaptionsReceivedEventType 이벤트를 처리하기 위한 콜백 정의
TeamsCaptionsInfo 각 CaptionsReceivedEventType 이벤트에 대해 받은 데이터 구조

선택 자막 기능 가져오기

외부 ID 사용자

Azure Communication Services 사용자가 Teams 모임에 참가할 수 있도록 하는 애플리케이션을 빌드하는 경우

let captionsCallFeature: SDK.CaptionsCallFeature = call.feature(SDK.Features.Captions);

Microsoft 365 사용자

let captionsCallFeature: SDK.CaptionsCallFeature = teamsCall.feature(SDK.Features.Captions);

Teams 캡션 개체 가져오기

Teams 캡션 특정 기능을 활용하려면 Teams 캡션 개체를 가져와서 캐스팅해야 합니다.

let teamsCaptions: SDK.TeamsCaptions;
if (captionsCallFeature.captions.kind === 'TeamsCaptions') {
    teamsCaptions = captionsCallFeature.captions as SDK.TeamsCaptions;
}

수신기 구독

활성 상태 여부 캡션을 수신하는 수신기 추가

const captionsActiveChangedHandler = () => {
    if (teamsCaptions.isCaptionsFeatureActive) {
        /* USER CODE HERE - E.G. RENDER TO DOM */
    }
}
teamsCaptions.on('CaptionsActiveChanged', captionsActiveChangedHandler);

수신된 캡션 데이터에 대한 수신기 추가

반환된 TeamsCaptionsInfo 데이터 개체를 처리합니다.

참고: 개체에는 데이터가 부분 캡션인지 또는 캡션의 최종 버전인지를 나타내는 resultType prop이 포함되어 있습니다. ResultType 중 partial은 편집하지 않은 라이브 캡션을 의미하며 final은 문장이 최종적으로 해석된 버전, 즉, 문장 부호 및 대문자 표시가 들어간 버전을 나타냅니다.

let currentCaptionLanguage : string;
const captionsReceivedHandler : TeamsCaptionsHandler = (data: TeamsCaptionsInfo) => { 
    /** USER CODE HERE - E.G. RENDER TO DOM 
     * data.captionLanguage
     * data.captionText
     * data.resultType
     * data.speaker
     * data.spokenText
     * data.timeStamp
    */
   // Example code:
   // Create a dom element, i.e. div, with id "captionArea" before proceeding with the sample code
    if (!this._currentCaptionLanguage || this._currentCaptionLanguage === data.captionLanguage) {
        let mri: string;
        switch (data.speaker.identifier.kind) {
            case 'communicationUser': { mri = data.speaker.identifier.communicationUserId; break; }
            case 'microsoftTeamsUser': { mri = data.speaker.identifier.microsoftTeamsUserId; break; }
            case 'phoneNumber': { mri = data.speaker.identifier.phoneNumber; break; }
        }
        const outgoingCaption = `prefix${mri.replace(/:/g, '').replace(/-/g, '')}`;

        let captionArea = document.getElementById("captionArea");
        const captionText = `${data.timestamp.toUTCString()}
            ${data.speaker.displayName}: ${data.captionText ?? data.spokenText}`;

        let foundCaptionContainer = captionArea.querySelector(`.${outgoingCaption}[isNotFinal='true']`);
        if (!foundCaptionContainer) {
            let captionContainer = document.createElement('div');
            captionContainer.setAttribute('isNotFinal', 'true');
            captionContainer.style['borderBottom'] = '1px solid';
            captionContainer.style['whiteSpace'] = 'pre-line';
            captionContainer.textContent = captionText;
            captionContainer.classList.add(newClassName);

            captionArea.appendChild(captionContainer);
        } else {
            foundCaptionContainer.textContent = captionText;

            if (captionData.resultType === 'Final') {
                foundCaptionContainer.setAttribute('isNotFinal', 'false');
            }
        }
    }
}; 
teamsCaptions.on('CaptionsReceived', captionsReceivedHandler); 

음성 언어 변경 상태를 수신하는 수신기 추가

const spokenLanguageChangedHandler = () => {
    if (teamsCaptions.activeSpokenLanguage !== currentSpokenLanguage) {
        /* USER CODE HERE - E.G. RENDER TO DOM */
    }
}
teamsCaptions.on('SpokenLanguageChanged', spokenLanguageChangedHandler)

캡션 언어 변경 상태를 수신하는 수신기 추가

const captionLanguageChangedHandler = () => {
    if (teamsCaptions.activeCaptionLanguage !== currentCaptionLanguage) {
        /* USER CODE HERE - E.G. RENDER TO DOM */
    }
}
teamsCaptions.on('CaptionLanguageChanged', captionLanguageChangedHandler)

캡션 시작

모든 수신기를 설정했으면 캡션 추가를 시작할 수 있습니다.

try {
    await teamsCaptions.startCaptions({ spokenLanguage: 'en-us' });
} catch (e) {
    /* USER ERROR HANDLING CODE HERE */
}

캡션 중지

try {
    teamsCaptions.stopCaptions(); 
} catch (e) {
    /* USER ERROR HANDLING CODE HERE */
}

수신기 구독 취소

teamsCaptions.off('CaptionsActiveChanged', captionsActiveChangedHandler);
teamsCaptions.off('CaptionsReceived', captionsReceivedHandler); 

음성 언어 지원

지원되는 음성 언어 목록 가져오기

선택 자막을 사용하도록 설정할 때 사용자가 선택할 수 있는, 지원되는 음성 언어 목록을 가져옵니다. 이 속성은 bcp 47 형식의 언어 배열을 반환합니다.

const spokenLanguages = teamsCaptions.supportedSpokenLanguages; 

음성 언어 설정

지원하는 음성 언어 배열에서 값을 전달하여 요청된 언어를 지원하는지 확인합니다. 기본적으로는 contoso에서 언어를 전혀 제공하지 않거나 지원되지 않는 언어를 제공하지 않는 경우 음성 언어는 기본값인 'en-us'로 설정됩니다.

// bcp 47 formatted language code
const language = 'en-us'; 

// Altneratively, pass a value from the supported spoken languages array
const language = spokenLanguages[0]; 

try {
    teamsCaptions.setSpokenLanguage(language);
} catch (e) {
    /* USER ERROR HANDLING CODE HERE */
}

캡션 언어 지원

지원하는 캡션 언어 목록 가져오기

조직에 활성 Teams 프리미엄 라이선스가 있는 경우 사용자가 Teams 캡션에서 제공하는 번역된 캡션을 사용하도록 허용할 수 있습니다. Microsoft 365 ID가 있는 사용자의 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 없을 때 Microsoft 365 사용자 계정에 대해 캡션 언어 검사가 수행됩니다.

이 속성은 두 글자 언어 코드의 배열을 ISO 639-1 표준으로 반환합니다.

const captionLanguages = teamsCaptions.supportedCaptionLanguages;

자막 언어 설정

// ISO 639-1 formatted language code
const language = 'en'; 

// Altneratively, pass a value from the supported caption languages array
const language = captionLanguages[0];
try {
    teamsCaptions.setCaptionLanguage(language);
} catch (e) {
    /* USER ERROR HANDLING CODE HERE */
}

필수 조건

참고 항목

이 가이드에 설명된 선택 자막 기능에 액세스하려면 Azure Communication Services 통화 SDK를 사용하는 음성 통화 앱이 있어야 합니다.

모델

이름 설명
CaptionsCallFeature 캡션 통화 기능 API
TeamsCaptions Teams 캡션용 API
StartCaptionOptions 음성 언어와 같은 선택 자막 옵션
TeamsCaptionsListener TeamsCaptions addOnCaptionsReceivedListener에 대한 수신기
TeamsCaptionsReceivedEvent TeamsCaptionsListener 이벤트 각각에 대해 받은 데이터 개체

선택 자막 기능 가져오기

외부 ID 사용자 및 Microsoft 365 사용자

사용자가 Teams 모임에 참가할 수 있도록 하는 애플리케이션을 빌드하는 경우

CaptionsCallFeature captionsCallFeature = call.feature(Features.CAPTIONS);
captionsCallFeature.getCaptions().whenComplete(
    ((captions, throwable) -> {
        if (throwable == null) {
            CallCaptions callCaptions = captions;
            if (captions.getCaptionsType() == CaptionsType.TEAMS_CAPTIONS) {
            // teams captions
            TeamsCaptions teamsCaptions = (TeamsCaptions) captions;
            }
        } else {
        // get captions failed
        // throwable is the exception/cause
        }
    }));

수신기 구독

수신기를 추가하여 캡션 사용 여부 상태 받기

public void addOnIsCaptionsEnabledChangedListener() {
    teamsCaptions.addOnCaptionsEnabledChangedListener( (PropertyChangedEvent args) -> {
        if(teamsCaptions.isEnabled()) {
            // captions enabled
        }
    });
}

수신된 캡션 데이터에 대한 수신기 추가

TeamsCaptionsListener captionsListener = (TeamsCaptionsReceivedEvent args) -> {
  // Information about the speaker.
  // CallerInfo participantInfo = args.getSpeaker();
  // The original text with no transcribed.
  // args.getSpokenText();
  // language identifier for the captions text.
  // args.getCaptionLanguage();
  // language identifier for the speaker.
  // args.getSpokenLanguage();
  // The transcribed text.
  // args.getCaptionText();
  // Timestamp denoting the time when the corresponding speech was made.
  // args.getTimestamp();
  // CaptionsResultType is Partial if text contains partially spoken sentence.
  // It is set to Final once the sentence has been completely transcribed.
  // args.getResultType() == CaptionsResultType.FINAL;
}; 
public void addOnCaptionsReceivedListener() {
  teamsCaptions.addOnCaptionsReceivedListener(captionsListener); 
}

활성 음성 언어 변경 상태를 수신하는 수신기 추가

public void addOnActiveSpokenLanguageChangedListener() {
    teamsCaptions.addOnActiveSpokenLanguageChangedListener( (PropertyChangedEvent args) -> {
       // teamsCaptions.getActiveSpokenLanguage()
    });
}

활성 캡션 언어 변경 상태를 수신하는 수신기 추가

public void addOnActiveCaptionLanguageChangedListener() {
    teamsCaptions.addOnActiveCaptionLanguageChangedListener( (PropertyChangedEvent args) -> {
       // teamsCaptions.getActiveCaptionLanguage()
    });
}

캡션 시작

모든 수신기를 설정했으면 캡션 추가를 시작할 수 있습니다.

public void startCaptions() {
    StartCaptionsOptions startCaptionsOptions = new StartCaptionsOptions();
    startCaptionsOptions.setSpokenLanguage("en-us");
    teamsCaptions.startCaptions(startCaptionsOptions).whenComplete((result, error) -> {
        if (error != null) {
        }
    });
}

캡션 중지

public void stopCaptions() {
    teamsCaptions.stopCaptions().whenComplete((result, error) -> {
        if (error != null) {
        }
    });
}

캡션 수신 수신기 제거

public void removeOnCaptionsReceivedListener() {
    teamsCaptions.removeOnCaptionsReceivedListener(captionsListener);
}

음성 언어 지원

지원되는 음성 언어 목록 가져오기

선택 자막을 사용하도록 설정할 때 사용자가 선택할 수 있는, 지원되는 음성 언어 목록을 가져옵니다.

// bcp 47 formatted language code
teamsCaptions.getSupportedSpokenLanguages();

음성 언어 설정

사용자가 음성 언어를 선택하면 앱에서 캡션이 생성될 것으로 예상되는 음성 언어를 설정할 수 있습니다.

public void setSpokenLanguage() {
    teamsCaptions.setSpokenLanguage("en-us").whenComplete((result, error) -> {
        if (error != null) {
        }
    });
}

캡션 언어 지원

지원되는 캡션 언어 가져오기

조직에 활성 Teams 프리미엄 라이선스가 있는 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 있는 동안에는 Azure Communication Services 사용자가 번역된 캡션을 사용하도록 설정할 수 있습니다. Microsoft 365 ID가 있는 사용자의 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 없을 때 자신의 사용자 계정에 대해 이 사항이 확인됩니다.

// ISO 639-1 formatted language code
teamsCaptions.getSupportedCaptionLanguages();

자막 언어 설정

public void setCaptionLanguage() {
    teamsCaptions.setCaptionLanguage("en").whenComplete((result, error) -> {
        if (error != null) {
        }
    });
}

필수 조건

참고 항목

이 가이드에 설명된 선택 자막 기능에 액세스하려면 Azure Communication Services 통화 SDK를 사용하는 음성 통화 앱이 있어야 합니다.

모델

이름 설명
CaptionsCallFeature 캡션 통화 기능 API
TeamsCaptions Teams 캡션용 API
StartCaptionOptions 음성 언어와 같은 선택 자막 옵션
TeamsCaptionsDelegate Teams 캡션 대리자
TeamsCaptionsReceivedEventArgs Teams 캡션으로 받은 이벤트 각각에 대한 데이터 개체

선택 자막 기능 가져오기

외부 ID 사용자 및 Microsoft 365 사용자

Azure Communication Services 사용자가 Teams 모임에 참가할 수 있도록 하는 애플리케이션을 빌드하는 경우

if let call = self.call {
    @State var captionsCallFeature = call.feature(Features.captions)
    captionsCallFeature.getCaptions{(value, error) in
        if let error = error {
            // failed to get captions
        } else {
            if (value?.type == CaptionsType.teamsCaptions) {
                // teams captions
                @State var teamsCaptions = value as? TeamsCaptions
            }
        }
    }
}

수신기 구독

사용 여부, 음성 언어, 캡션 언어 상태 변경 사항, 수신된 데이터를 수신하는 수신기 추가

extension CallObserver: TeamsCaptionsDelegate {
    // listener for receive captions enabled/disabled status
    public func teamsCaptions(_ teamsCaptions: TeamsCaptions, didChangeCaptionsEnabledState args: PropertyChangedEventArgs) {
        // teamsCaptions.isEnabled
    }
    
    // listener for active spoken language state change
    public func teamsCaptions(_ teamsCaptions: TeamsCaptions, didChangeActiveSpokenLanguageState args: PropertyChangedEventArgs) {
        // teamsCaptions.activeSpokenLanguage
    }
    
    // listener for active caption language state change
    public func teamsCaptions(_ teamsCaptions: TeamsCaptions, didChangeActiveCaptionLanguageState args: PropertyChangedEventArgs) {
        // teamsCaptions.activeCaptionLanguage
    }
    
    // listener for captions data received
    public func teamsCaptions(_ teamsCaptions: TeamsCaptions, didReceiveCaptions:TeamsCaptionsReceivedEventArgs) {
            // Information about the speaker.
            // didReceiveCaptions.speaker
            // The original text with no transcribed.
            // didReceiveCaptions.spokenText
            // language identifier for the captions text.
            // didReceiveCaptions.captionLanguage
            // language identifier for the speaker.
            // didReceiveCaptions.spokenLanguage
            // The transcribed text.
            // didReceiveCaptions.captionText
            // Timestamp denoting the time when the corresponding speech was made.
            // didReceiveCaptions.timestamp
            // CaptionsResultType is Partial if text contains partially spoken sentence.
            // It is set to Final once the sentence has been completely transcribed.
            // didReceiveCaptions.resultType
    }
}

teamsCaptions.delegate = self.callObserver

캡션 시작

모든 수신기를 설정했으면 캡션 추가를 시작할 수 있습니다.

func startCaptions() {
    guard let teamsCaptions = teamsCaptions else {
        return
    }
    let startCaptionsOptions = StartCaptionsOptions()
    startCaptionsOptions.spokenLanguage = "en-us"
    teamsCaptions.startCaptions(startCaptionsOptions: startCaptionsOptions, completionHandler: { (error) in
        if error != nil {
            
        }
    })
}

캡션 중지

func stopCaptions() {
    teamsCaptions.stopCaptions(completionHandler: { (error) in
        if error != nil {
            
        }
    })
}

캡션 수신 수신기 제거

teamsCaptions?.delegate = nil

음성 언어 지원

지원되는 음성 언어 목록 가져오기

선택 자막을 사용하도록 설정할 때 사용자가 선택할 수 있는, 지원되는 음성 언어 목록을 가져옵니다.

// bcp 47 formatted language code
let spokenLanguage : String = "en-us"
for language in teamsCaptions?.supportedSpokenLanguages ?? [] {
    // choose required language
    spokenLanguage = language
}

음성 언어 설정

사용자가 음성 언어를 선택하면 앱에서 캡션이 생성될 것으로 예상되는 음성 언어를 설정할 수 있습니다.

func setSpokenLanguage() {
    guard let teamsCaptions = self.teamsCaptions else {
        return
    }

    teamsCaptions.set(spokenLanguage: spokenLanguage, completionHandler: { (error) in
        if let error = error {
        }
    })
}

캡션 언어 지원

지원되는 캡션 언어 가져오기

조직에 활성 Teams 프리미엄 라이선스가 있는 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 있는 동안에는 Azure Communication Services 사용자가 번역된 캡션을 사용하도록 설정할 수 있습니다. Microsoft 365 ID가 있는 사용자의 경우 모임 이끌이에게 Teams 프리미엄 라이선스가 없을 때 자신의 사용자 계정에 대해 이 사항이 확인됩니다.

// ISO 639-1 formatted language code
let captionLanguage : String = "en"
for language in teamsCaptions?.supportedCaptionLanguages ?? [] {
    // choose required language
    captionLanguage = language
}

자막 언어 설정

func setCaptionLanguage() {
    guard let teamsCaptions = self.teamsCaptions else {
        return
    }

    teamsCaptions.set(captionLanguage: captionLanguage, completionHandler: { (error) in
        if let error = error {
        }
    })
}

리소스 정리

Communication Services 구독을 정리하고 제거하려면 리소스 또는 리소스 그룹을 삭제하면 됩니다. 리소스 그룹을 삭제하면 해당 리소스 그룹에 연결된 다른 모든 리소스가 함께 삭제됩니다. 여기에서 리소스 정리에 대해 자세히 알아보세요.

다음 단계

자세한 내용은 다음 문서를 참조하세요.