다음을 통해 공유


XSpeechSynthesizerEnumerateInstalledVoices

설치된 음성을 열거하고 각 음성에 대해 콜백으로 지정된 메서드를 호출합니다.

구문

HRESULT XSpeechSynthesizerEnumerateInstalledVoices(  
         void* context,  
         XSpeechSynthesizerInstalledVoicesCallback* callback  
)  

매개 변수

context _In_opt_
형식: void*

호출자가 호출자 특정 데이터를 복구할 수 있도록 콜백 함수에 전달되는 사용자 지정 변수입니다.

callback _In_
형식: XSpeechSynthesizerInstalledVoicesCallback*

설치된 음성별로 한 번씩 호출되는 메서드에 대한 포인터입니다.

반환 값

형식: HRESULT

성공한 경우 S_OK를 반환하고, 그렇지 않으면 오류 코드를 반환합니다. 오류 코드 목록은 오류 코드를 참조하세요.

설명

참고 항목

이 함수는 시간에 민감한 스레드에서 호출하는 것이 안전하지 않습니다. 자세한 내용은 시간에 민감한 스레드를 참조하세요.

이 함수는 장치에 설치된 음성 합성 엔진 또는 음성을 열거합니다. 이 함수는 설치된 각 음성에 대해 콜백에 지정된 XSpeechSynthesizerInstalledVoicesCallback 콜백 함수를 한 번 호출하고, 해당 음성 정보를 포함하는XSpeechSynthesizerVoiceInformation 구조체를 전달합니다.

다음 예제에서는 XSpeechSynthesizerEnumerateInstalledVoices 함수를 호출하여 장치에 설치된 음성을 열거하는 방법을 보여줍니다. 이 예제에서는 XSpeechSynthesizerInstalledVoicesCallback 콜백 함수를 호출하여 (1) 장치에 설치된 음성 수를 계산하고 (2) XSpeechSynthesizerVoiceInformation 구조체에서 디버거로 설치된 각 음성에 대한 정보를 출력합니다.

int Game::CountInstalledVoices()
{
    HRESULT hr = S_OK;
    int* voiceCount = new int();
    // Call XSpeechSynthesizerEnumerateInstalledVoices with a callback function
    // defined as a lambda expression that increments the count of installed voices 
    // each time it's invoked, and outputs information about each voice to the 
    // debugger for display.
    hr = XSpeechSynthesizerEnumerateInstalledVoices(voiceCount,
        [](
            _In_ const XSpeechSynthesizerVoiceInformation* information,
            _In_ void* context
            ) -> bool 
        {
        // Increment and update the count of installed voices.
        int* voiceCount = (int*)context;
        *voiceCount = *voiceCount + 1;
        CopyMemory(context, voiceCount, sizeof(int));

        // Output information about the current installed voice
        // to the debugger for display.
        char buffer[1000];
        int bufferLen;
        bufferLen = sprintf(buffer, "(%s) %s - %s, %s\n",
            information->VoiceId,
            information->Description,
            information->Gender == XSpeechSynthesizerVoiceGender::Male ? "Male" : "Female",
            information->Language);
        OutputDebugStringA(buffer);
      
        // Continue iterating through installed voices.
        // If this was set to false, the calling function would stop
        // enumerating installed voices.
        return true;
        }
    );

    // Return the count of installed voices.
    return *voiceCount;
}

요구 사항

헤더: XSpeechSynthesizer.h

라이브러리: xgameruntime.lib

지원되는 플랫폼: Windows, Xbox One 패밀리 콘솔 및 Xbox Series 콘솔

참고 항목

XAccessibility
XSpeechSynthesizerSetCustomVoice
XSpeechSynthesizer